“This is the 30th day of my participation in the First Challenge 2022. For details: First Challenge 2022.”

One, flower recognition

1. Introduction to the data set

The Oxford 102 Flowers Dataset is a flower collection Dataset, mainly used for image classification, which is divided into 102 types of Flowers in total, and each type contains 40 to 258 images.

This dataset was published in 2008 by the Department of Engineering Science at the University of Oxford with a paper called Automated Flower Classification over a Large Number of classes.

TXT (training set, 1020 images), valid. TXT (validation set, 1020 images), and test.txt(6149) have been generated in the folder. Format of each line in the file: label_id of the image relative to the path image (note: space in between).

2. PaddleClas profile

PaddleClas is currently release2.3, so it’s a bit different than before, so you need to get used to it again.

Address: gitee.com/paddlepaddl…

Configs has been moved to the PPCLS directory to deploy as a separate deploy directory

Unzip the dataset! tar -xvf data/data19852/flowers102.tar -C ./data/Copy the code

PaddleClas

# Download the latest version! git clone https://gitee.com/paddlepaddle/PaddleClas/ --depth=1
Copy the code
Cloning into 'PaddleClas'... remote: Enumerating objects: 1420, done.[K remote: Counting objects: 100% (1420/1420), done.[K remote: Compressing objects: 100% (1256/1256), done.[K remote: Total 1420 (delta 326), reused 967 (delta 138), pack-reused 0[K Receiving objects: 100% (1420/1420) and 92.84 MiB | 2.32 MiB/s, done. Resolving deltas: 100% (326/326), done. Checking connectivity... done.Copy the code
%cd PaddleClas/
Copy the code
/home/aistudio/PaddleClas
Copy the code

3. Model training

1. Modify imagenet_dataset. Py

Directory: \ PPCLS \ data \ dataloader \ imagenet_dataset py

There is a bug in the directory section.

  • assert os.path.exists(self._cls_path)
  • assert os.path.exists(self._img_root)

add

  • self._cls_path=os.path.join(self._img_root,self._cls_path)

Otherwise, relative paths cannot be used

class ImageNetDataset(CommonDataset): def _load_anno(self, seed=None): If cls_path uses a relative directory, an error will be reported. Join (self._img_root,self._cls_path) # assert os.path.exists(self._cls_path) # assert os.path.exists(self._img_root) self._cls_path=os.path.join(self._img_root,self._cls_path) print('self._cls_path',self._cls_path) self.images = [] self.labels = [] with open(self._cls_path) as fd: lines = fd.readlines() if seed is not None: np.random.RandomState(seed).shuffle(lines) for l in lines: l = l.strip().split(" ") self.images.append(os.path.join(self._img_root, l[0])) self.labels.append(int(l[1])) assert os.path.exists(self.images[-1])Copy the code

2. Modify the configuration file

# global configs Global: checkpoints: null Pretrained_model: null output_dir:./output/ # CPU configuration # eval_during_train: True # eval_interval: Print_batch_step: 10 # Use visualDL use_visualDL: False # used for static mode and model export image_shape: [3, 224, 224] # save address save_inference_dir: ./inference # model architecture Arch: name: ResNet50_vd # loss function config for traing/eval process Loss: Train: -celoss: weight: 1.0 Eval: -celoss: weight: 1.0 Optimizer: name: Momentum Momentum: 0.9 LR: name: Cosup_epoch: 5 Regularizer: name: 'L2' Coeff: 0.00001 # data loader for train and eval DataLoader: train: dataset: name: ImageNetDataset image_root: /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/ cls_label_path: train.txt transform_ops: - DecodeImage: to_rgb: True channel_first: False - RandCropImage: size: 224 - RandFlipImage: flip_code: 1 - NormalizeImage: scale: 1.0/255.0 mean: [0.485, 0.456, 0.406] STD: [0.229, 0.224, 0.225] Order: 'sampler: name' DistributedBatchSampler batch_size: 256 drop_last: False shuffle: True loader: num_workers: 4 use_shared_memory: True Eval: dataset: name: ImageNetDataset image_root: /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/ cls_label_path: valid.txt transform_ops: - DecodeImage: to_rgb: True channel_first: False - ResizeImage: resize_short: 256 - CropImage: size: 224 - NormalizeImage: scale: 1.0/255.0 mean: [0.485, 0.456, 0.406] STD: [0.229, 0.224, 0.225] Order: 'sampler: name' DistributedBatchSampler batch_size: 256 drop_last: False shuffle: False loader: num_workers: 4 use_shared_memory: True Infer: infer_imgs: /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/ batch_size: 10 transforms: - DecodeImage: to_rgb: True channel_first: False - ResizeImage: resize_short: 256 - CropImage: size: 224-NormalizeImage: scale: 1.0/255.0 mean: [0.485, 0.456, 0.406] STD: [0.229, 0.224, 0.225] order: "-tochwImage: PostProcess: name: Topk topk: 5 class_id_map_file: /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/jpg/image_00030.jpg Metric: Train: - TopkAcc: topk: [1, 5] Eval: - TopkAcc: topk: [1, 5]Copy the code
  • The -c parameter specifies the path of the training configuration file. For details about the hyperparameters, see the YAML file
  • Yaml global. device parameter is set to CPU, that is, CPU is used for training (if not set, this parameter defaults to True).
  • If epochs is set to 20 in the YAML file, it indicates that 20 epoch iterations are performed on the entire data set. The training time is expected to be about 20 minutes (the training time varies with cpus). In this case, the training model is not sufficient. If the training model accuracy is improved, please set this parameter as large as 40, and the training time will be extended accordingly

3. Configuration description

3.1 Global Configuration (Global)

Parameter name Specific meaning The default value An optional value
checkpoints Breakpoint model path for recovery training null str
pretrained_model Pretrain model path null str
output_dir Save model path “./output/” str
save_interval How many epochs do you save the model at 1 int
eval_during_train Whether to evaluate during training True bool
eval_interval How many epochs were used to evaluate the model 1 int
epochs Train the total epoch number int
print_batch_step How many mini-batches are printed every 10 int
use_visualdl Whether to use VisualDL to visualize the training process False bool
image_shape Image size [3,224,224] list, shape: (3,)
save_inference_dir Preservation path of the Inference model “./inference” str
eval_mode The pattern of eval “classification” “retrieval”

3.2 structure (Arch)

Parameter name Specific meaning The default value An optional value
name Model structure name ResNet50 PaddleClas provides the model structure
class_num Class number 1000 int
pretrained Pretraining model False Bool, STR

3.3 Loss Function (Loss)

Parameter name Specific meaning The default value An optional value
CELoss Cross entropy loss function
CELoss.weight The weight of CELoss in the whole Loss 1.0 float
CELoss.epsilon Epsilon value of label_smooth in CELoss 0.1 Float between 0 and 1

3.4 Optimizer

Parameter name Specific meaning The default value An optional value
name Optimizer method name “Momentum” “RmsProp” and other optimizers
momentum Momentum values 0.9 float
lr.name Ways of learning rate decline “Cosine” “Linear”, “Piecewise” and other descent methods
lr.learning_rate Initial value of learning rate 0.1 float
lr.warmup_epoch Warmup round number 0 Int, such as 5
regularizer.name Regularize method name “L2” [“L1”, “L2”]
regularizer.coeff Regularization coefficient 0.00007 float

4. Training

# GPU set! export CUDA_VISIBLE_DEVICES=0

# -o Arch. Pretrained =True # -o Arch. Pretrained =True! python tools/train.py -c ./ppcls/configs/quick_start/ResNet50_vd.yaml -o Arch.pretrained=True
Copy the code

The training log is as follows

[2021/10/31 01:53:47] root INFO: [Train][Epoch 16/20][Iter: 0/4] LR: 0.00285, TOP1:0.93750, Top5:0.96484, CELoss: 0.36489, loss: 0.36489, batch_cost: 1.48066s, reader_cost: 0.68550, IPS: 172.89543 images/ SEC, eta: 0:00:29 [2021/10/31 01:53:49] root INFO: [Train][Epoch 16/20][Avg] TOP1:0.95098, TOP5:0.97745, CELoss: 0.31581, loss: 0.31581 [2021/10/31 01:53:53] root INFO: [Train][Epoch 17/20][Iter: 0/4] LR: 0.00183, Top1:0.94531, top5: 0.97656, CELoss: 0.32916, loss: 0.32916, batCH_cost: 1.47958s, reader_cost: 0.68473, IPS: 173.02266 images/ SEC, eta: 0:00:23 [2021/10/31 01:53:55] root INFO: [Train][Epoch 17/20][Avg] Top1:0.95686, Top5:0.98137, CELoss: 0.29560, loss: 0.29560 [2021/10/31 01:53:58] root INFO: [Train][Epoch 18/20][Iter: 0/4] lR: 0.00101, Top1:0.93750, top5: 0.98047, CELoss: 0.31542, loss: 0.31542, BATCH_cost: 1.47524s, reader_cost: 0.68058, IPS: 173.53117 images/ SEC, eta: 0:00:17 [2021/10/31 01:54:01] root INFO: [Train][Epoch 18/20][Avg] TOP1:0.94608, TOP5:0.98627, CELoss: 0.29086, loss: 0.29086 [2021/10/31 01:54:04] root INFO: [Train][Epoch 19/20][Iter: 0/4] lR: 0.00042, Top1:0.97266, top5: 0.98438, CELoss: 0.24642, loss: 0.24642, batCH_cost: 1.47376s, reader_cost: 0.67916, IPS: 173.70590 images/ SEC, eta: 0:00:11 [2021/10/31 01:54:07] root INFO: [Train][Epoch 19/20][Avg] Top1:0.94608, TOP5:0.97941, CELoss: 0.30998, loss: 0.30998 [2021/10/31 01:54:10] root INFO: [Train][Epoch 20/20][Iter: 0/4] LR: 0.00008, Top1:0.98047, top5: 0.98438, CELoss: 0.20209, loss: 0.20209, batCH_cost: 1.47083s, reader_cost: 0.67647, IPS: 174.05180 images/ SEC, eta: 0:00:05 [2021/10/31 01:54:13] root INFO: [Train][Epoch 20/20][Avg] Top1:0.95784, Top5:0.98922, CELoss: 0.25974, loss: 0.25974 [2021/10/31 01:54:16] root INFO: [Eval][Epoch 20][Iter: 0/4]CELoss: 0.47912, loss: 0.47912, top1: 0.91797, TOP5:0.96094, BATCH_cost: 3.26175s, reader_cost: 3.02034, ips: 78.48538 images/ SEC [2021/10/31 01:54:17] root INFO: [Eval][Epoch 20][Avg]CELoss: 0.54982, Loss: 0.54982, TOP1: 0.88922, top5: 0.96667 [2021/10/31 01:54:18] root INFO: Already save model in ./output/ResNet50_vd/best_model [2021/10/31 01:54:18] root INFO: [Eval][Epoch 20][best metric: 0.8892156844045601] [2021/10/31 01:54:18] root INFO: Already save model in ./output/ResNet50_vd/epoch_20 [2021/10/31 01:54:18] root INFO: Already save model in ./output/ResNet50_vd/latestCopy the code

The visible log output is messy and not as clear as before, it is best to use VisualDL to see the training

Four, forecasting

1. The prediction

from PIL import Image
img=Image.open('/home/aistudio/data/oxford-102-flowers/oxford-102-flowers/jpg/image_00033.jpg')
img
Copy the code

# prediction! python3 tools/infer.py -c ./ppcls/configs/quick_start/ResNet50_vd.yaml -o Infer.infer_imgs=/home/aistudio/data/oxford-102-flowers/oxford-102-flowers/jpg/image_00033.jpg  -o Global.pretrained_model=output/ResNet50_vd/best_model
Copy the code
/home/aistudio/PaddleClas/ppcls/arch/backbone/model_zoo/vision_transformer.py:15: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Callable
[2021/10/31 02:02:53] root INFO: 
===========================================================
==        PaddleClas is powered by PaddlePaddle !        ==
===========================================================
==                                                       ==
==   For more info please go to the following website.   ==
==                                                       ==
==       https://github.com/PaddlePaddle/PaddleClas      ==
===========================================================

[2021/10/31 02:02:53] root INFO: Arch : 
[2021/10/31 02:02:53] root INFO:     name : ResNet50_vd
[2021/10/31 02:02:53] root INFO: DataLoader : 
[2021/10/31 02:02:53] root INFO:     Eval : 
[2021/10/31 02:02:53] root INFO:         dataset : 
[2021/10/31 02:02:53] root INFO:             cls_label_path : valid.txt
[2021/10/31 02:02:53] root INFO:             image_root : /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/
[2021/10/31 02:02:53] root INFO:             name : ImageNetDataset
[2021/10/31 02:02:53] root INFO:             transform_ops : 
[2021/10/31 02:02:53] root INFO:                 DecodeImage : 
[2021/10/31 02:02:53] root INFO:                     channel_first : False
[2021/10/31 02:02:53] root INFO:                     to_rgb : True
[2021/10/31 02:02:53] root INFO:                 ResizeImage : 
[2021/10/31 02:02:53] root INFO:                     resize_short : 256
[2021/10/31 02:02:53] root INFO:                 CropImage : 
[2021/10/31 02:02:53] root INFO:                     size : 224
[2021/10/31 02:02:53] root INFO:                 NormalizeImage : 
[2021/10/31 02:02:53] root INFO:                     mean : [0.485, 0.456, 0.406]
[2021/10/31 02:02:53] root INFO:                     order : 
[2021/10/31 02:02:53] root INFO:                     scale : 1.0/255.0
[2021/10/31 02:02:53] root INFO:                     std : [0.229, 0.224, 0.225]
[2021/10/31 02:02:53] root INFO:         loader : 
[2021/10/31 02:02:53] root INFO:             num_workers : 4
[2021/10/31 02:02:53] root INFO:             use_shared_memory : True
[2021/10/31 02:02:53] root INFO:         sampler : 
[2021/10/31 02:02:53] root INFO:             batch_size : 256
[2021/10/31 02:02:53] root INFO:             drop_last : False
[2021/10/31 02:02:53] root INFO:             name : DistributedBatchSampler
[2021/10/31 02:02:53] root INFO:             shuffle : False
[2021/10/31 02:02:53] root INFO:     Train : 
[2021/10/31 02:02:53] root INFO:         dataset : 
[2021/10/31 02:02:53] root INFO:             cls_label_path : train.txt
[2021/10/31 02:02:53] root INFO:             image_root : /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/
[2021/10/31 02:02:53] root INFO:             name : ImageNetDataset
[2021/10/31 02:02:53] root INFO:             transform_ops : 
[2021/10/31 02:02:53] root INFO:                 DecodeImage : 
[2021/10/31 02:02:53] root INFO:                     channel_first : False
[2021/10/31 02:02:53] root INFO:                     to_rgb : True
[2021/10/31 02:02:53] root INFO:                 RandCropImage : 
[2021/10/31 02:02:53] root INFO:                     size : 224
[2021/10/31 02:02:53] root INFO:                 RandFlipImage : 
[2021/10/31 02:02:53] root INFO:                     flip_code : 1
[2021/10/31 02:02:53] root INFO:                 NormalizeImage : 
[2021/10/31 02:02:53] root INFO:                     mean : [0.485, 0.456, 0.406]
[2021/10/31 02:02:53] root INFO:                     order : 
[2021/10/31 02:02:53] root INFO:                     scale : 1.0/255.0
[2021/10/31 02:02:53] root INFO:                     std : [0.229, 0.224, 0.225]
[2021/10/31 02:02:53] root INFO:         loader : 
[2021/10/31 02:02:53] root INFO:             num_workers : 4
[2021/10/31 02:02:53] root INFO:             use_shared_memory : True
[2021/10/31 02:02:53] root INFO:         sampler : 
[2021/10/31 02:02:53] root INFO:             batch_size : 256
[2021/10/31 02:02:53] root INFO:             drop_last : False
[2021/10/31 02:02:53] root INFO:             name : DistributedBatchSampler
[2021/10/31 02:02:53] root INFO:             shuffle : True
[2021/10/31 02:02:53] root INFO: Global : 
[2021/10/31 02:02:53] root INFO:     checkpoints : None
[2021/10/31 02:02:53] root INFO:     class_num : 102
[2021/10/31 02:02:53] root INFO:     device : gpu
[2021/10/31 02:02:53] root INFO:     epochs : 20
[2021/10/31 02:02:53] root INFO:     eval_during_train : True
[2021/10/31 02:02:53] root INFO:     eval_interval : 5
[2021/10/31 02:02:53] root INFO:     image_shape : [3, 224, 224]
[2021/10/31 02:02:53] root INFO:     output_dir : ./output/
[2021/10/31 02:02:53] root INFO:     pretrained_model : output/ResNet50_vd/best_model
[2021/10/31 02:02:53] root INFO:     print_batch_step : 10
[2021/10/31 02:02:53] root INFO:     save_inference_dir : ./inference
[2021/10/31 02:02:53] root INFO:     save_interval : 5
[2021/10/31 02:02:53] root INFO:     use_visualdl : False
[2021/10/31 02:02:53] root INFO: Infer : 
[2021/10/31 02:02:53] root INFO:     PostProcess : 
[2021/10/31 02:02:53] root INFO:         class_id_map_file : /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/jpg/image_00030.jpg
[2021/10/31 02:02:53] root INFO:         name : Topk
[2021/10/31 02:02:53] root INFO:         topk : 5
[2021/10/31 02:02:53] root INFO:     batch_size : 10
[2021/10/31 02:02:53] root INFO:     infer_imgs : /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/jpg/image_00033.jpg
[2021/10/31 02:02:53] root INFO:     transforms : 
[2021/10/31 02:02:53] root INFO:         DecodeImage : 
[2021/10/31 02:02:53] root INFO:             channel_first : False
[2021/10/31 02:02:53] root INFO:             to_rgb : True
[2021/10/31 02:02:53] root INFO:         ResizeImage : 
[2021/10/31 02:02:53] root INFO:             resize_short : 256
[2021/10/31 02:02:53] root INFO:         CropImage : 
[2021/10/31 02:02:53] root INFO:             size : 224
[2021/10/31 02:02:53] root INFO:         NormalizeImage : 
[2021/10/31 02:02:53] root INFO:             mean : [0.485, 0.456, 0.406]
[2021/10/31 02:02:53] root INFO:             order : 
[2021/10/31 02:02:53] root INFO:             scale : 1.0/255.0
[2021/10/31 02:02:53] root INFO:             std : [0.229, 0.224, 0.225]
[2021/10/31 02:02:53] root INFO:         ToCHWImage : None
[2021/10/31 02:02:53] root INFO: Loss : 
[2021/10/31 02:02:53] root INFO:     Eval : 
[2021/10/31 02:02:53] root INFO:         CELoss : 
[2021/10/31 02:02:53] root INFO:             weight : 1.0
[2021/10/31 02:02:53] root INFO:     Train : 
[2021/10/31 02:02:53] root INFO:         CELoss : 
[2021/10/31 02:02:53] root INFO:             weight : 1.0
[2021/10/31 02:02:53] root INFO: Metric : 
[2021/10/31 02:02:53] root INFO:     Eval : 
[2021/10/31 02:02:53] root INFO:         TopkAcc : 
[2021/10/31 02:02:53] root INFO:             topk : [1, 5]
[2021/10/31 02:02:53] root INFO:     Train : 
[2021/10/31 02:02:53] root INFO:         TopkAcc : 
[2021/10/31 02:02:53] root INFO:             topk : [1, 5]
[2021/10/31 02:02:53] root INFO: Optimizer : 
[2021/10/31 02:02:53] root INFO:     lr : 
[2021/10/31 02:02:53] root INFO:         learning_rate : 0.0125
[2021/10/31 02:02:53] root INFO:         name : Cosine
[2021/10/31 02:02:53] root INFO:         warmup_epoch : 5
[2021/10/31 02:02:53] root INFO:     momentum : 0.9
[2021/10/31 02:02:53] root INFO:     name : Momentum
[2021/10/31 02:02:53] root INFO:     regularizer : 
[2021/10/31 02:02:53] root INFO:         coeff : 1e-05
[2021/10/31 02:02:53] root INFO:         name : L2
[2021/10/31 02:02:53] root INFO: train with paddle 2.1.2 and device CUDAPlace(0)
W1031 02:02:53.626825  7656 device_context.cc:404] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W1031 02:02:53.631515  7656 device_context.cc:422] device: 0, cuDNN Version: 7.6.
'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  if data.dtype == np.object:
[{'class_ids': [37, 35, 76, 28, 50], 'scores': [0.45998, 0.13054, 0.03585, 0.03207, 0.02833], 'file_name': '/home/aistudio/data/oxford-102-flowers/oxford-102-flowers/jpg/image_00033.jpg', 'label_names': []}]
Copy the code

You can see that the log output of the updated version is chaotic.

The final output

[{'class_ids': [37, 35, 76, 28, 50], 'scores': [0.45998, 0.13054, 0.03585, 0.03207, 0.02833], 'file_name': '/home/aistudio/data/oxford-102-flowers/oxford-102-flowers/jpg/image_00033.jpg', 'label_names': []}]
Copy the code

It shows the probability of top5, so it can be seen that there are 37 categories. This is empty because label_names is not set.

2. Use inference model to carry out model inference

2.1 Inference format conversion

By deriving the inference model, PaddlePaddle supports the inference using the prediction engine.

! python3 tools/export_model.py \ -c ./ppcls/configs/quick_start/ResNet50_vd.yaml \ -o Global.pretrained_model=output/ResNet50_vd/best_modelCopy the code
/home/aistudio/PaddleClas/ppcls/arch/backbone/model_zoo/vision_transformer.py:15: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Callable
[2021/10/31 02:30:38] root INFO: 
===========================================================
==        PaddleClas is powered by PaddlePaddle !        ==
===========================================================
==                                                       ==
==   For more info please go to the following website.   ==
==                                                       ==
==       https://github.com/PaddlePaddle/PaddleClas      ==
===========================================================

[2021/10/31 02:30:38] root INFO: Arch : 
[2021/10/31 02:30:38] root INFO:     name : ResNet50_vd
[2021/10/31 02:30:38] root INFO: DataLoader : 
[2021/10/31 02:30:38] root INFO:     Eval : 
[2021/10/31 02:30:38] root INFO:         dataset : 
[2021/10/31 02:30:38] root INFO:             cls_label_path : valid.txt
[2021/10/31 02:30:38] root INFO:             image_root : /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/
[2021/10/31 02:30:38] root INFO:             name : ImageNetDataset
[2021/10/31 02:30:38] root INFO:             transform_ops : 
[2021/10/31 02:30:38] root INFO:                 DecodeImage : 
[2021/10/31 02:30:38] root INFO:                     channel_first : False
[2021/10/31 02:30:38] root INFO:                     to_rgb : True
[2021/10/31 02:30:38] root INFO:                 ResizeImage : 
[2021/10/31 02:30:38] root INFO:                     resize_short : 256
[2021/10/31 02:30:38] root INFO:                 CropImage : 
[2021/10/31 02:30:38] root INFO:                     size : 224
[2021/10/31 02:30:38] root INFO:                 NormalizeImage : 
[2021/10/31 02:30:38] root INFO:                     mean : [0.485, 0.456, 0.406]
[2021/10/31 02:30:38] root INFO:                     order : 
[2021/10/31 02:30:38] root INFO:                     scale : 1.0/255.0
[2021/10/31 02:30:38] root INFO:                     std : [0.229, 0.224, 0.225]
[2021/10/31 02:30:38] root INFO:         loader : 
[2021/10/31 02:30:38] root INFO:             num_workers : 4
[2021/10/31 02:30:38] root INFO:             use_shared_memory : True
[2021/10/31 02:30:38] root INFO:         sampler : 
[2021/10/31 02:30:38] root INFO:             batch_size : 256
[2021/10/31 02:30:38] root INFO:             drop_last : False
[2021/10/31 02:30:38] root INFO:             name : DistributedBatchSampler
[2021/10/31 02:30:38] root INFO:             shuffle : False
[2021/10/31 02:30:38] root INFO:     Train : 
[2021/10/31 02:30:38] root INFO:         dataset : 
[2021/10/31 02:30:38] root INFO:             cls_label_path : train.txt
[2021/10/31 02:30:38] root INFO:             image_root : /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/
[2021/10/31 02:30:38] root INFO:             name : ImageNetDataset
[2021/10/31 02:30:38] root INFO:             transform_ops : 
[2021/10/31 02:30:38] root INFO:                 DecodeImage : 
[2021/10/31 02:30:38] root INFO:                     channel_first : False
[2021/10/31 02:30:38] root INFO:                     to_rgb : True
[2021/10/31 02:30:38] root INFO:                 RandCropImage : 
[2021/10/31 02:30:38] root INFO:                     size : 224
[2021/10/31 02:30:38] root INFO:                 RandFlipImage : 
[2021/10/31 02:30:38] root INFO:                     flip_code : 1
[2021/10/31 02:30:38] root INFO:                 NormalizeImage : 
[2021/10/31 02:30:38] root INFO:                     mean : [0.485, 0.456, 0.406]
[2021/10/31 02:30:38] root INFO:                     order : 
[2021/10/31 02:30:38] root INFO:                     scale : 1.0/255.0
[2021/10/31 02:30:38] root INFO:                     std : [0.229, 0.224, 0.225]
[2021/10/31 02:30:38] root INFO:         loader : 
[2021/10/31 02:30:38] root INFO:             num_workers : 4
[2021/10/31 02:30:38] root INFO:             use_shared_memory : True
[2021/10/31 02:30:38] root INFO:         sampler : 
[2021/10/31 02:30:38] root INFO:             batch_size : 256
[2021/10/31 02:30:38] root INFO:             drop_last : False
[2021/10/31 02:30:38] root INFO:             name : DistributedBatchSampler
[2021/10/31 02:30:38] root INFO:             shuffle : True
[2021/10/31 02:30:38] root INFO: Global : 
[2021/10/31 02:30:38] root INFO:     checkpoints : None
[2021/10/31 02:30:38] root INFO:     class_num : 102
[2021/10/31 02:30:38] root INFO:     device : gpu
[2021/10/31 02:30:38] root INFO:     epochs : 20
[2021/10/31 02:30:38] root INFO:     eval_during_train : True
[2021/10/31 02:30:38] root INFO:     eval_interval : 5
[2021/10/31 02:30:38] root INFO:     image_shape : [3, 224, 224]
[2021/10/31 02:30:38] root INFO:     output_dir : ./output/
[2021/10/31 02:30:38] root INFO:     pretrained_model : output/ResNet50_vd/best_model
[2021/10/31 02:30:38] root INFO:     print_batch_step : 10
[2021/10/31 02:30:38] root INFO:     save_inference_dir : ./inference
[2021/10/31 02:30:38] root INFO:     save_interval : 5
[2021/10/31 02:30:38] root INFO:     use_visualdl : False
[2021/10/31 02:30:38] root INFO: Infer : 
[2021/10/31 02:30:38] root INFO:     PostProcess : 
[2021/10/31 02:30:38] root INFO:         class_id_map_file : /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/jpg/image_00030.jpg
[2021/10/31 02:30:38] root INFO:         name : Topk
[2021/10/31 02:30:38] root INFO:         topk : 5
[2021/10/31 02:30:38] root INFO:     batch_size : 10
[2021/10/31 02:30:38] root INFO:     infer_imgs : /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/
[2021/10/31 02:30:38] root INFO:     transforms : 
[2021/10/31 02:30:38] root INFO:         DecodeImage : 
[2021/10/31 02:30:38] root INFO:             channel_first : False
[2021/10/31 02:30:38] root INFO:             to_rgb : True
[2021/10/31 02:30:38] root INFO:         ResizeImage : 
[2021/10/31 02:30:38] root INFO:             resize_short : 256
[2021/10/31 02:30:38] root INFO:         CropImage : 
[2021/10/31 02:30:38] root INFO:             size : 224
[2021/10/31 02:30:38] root INFO:         NormalizeImage : 
[2021/10/31 02:30:38] root INFO:             mean : [0.485, 0.456, 0.406]
[2021/10/31 02:30:38] root INFO:             order : 
[2021/10/31 02:30:38] root INFO:             scale : 1.0/255.0
[2021/10/31 02:30:38] root INFO:             std : [0.229, 0.224, 0.225]
[2021/10/31 02:30:38] root INFO:         ToCHWImage : None
[2021/10/31 02:30:38] root INFO: Loss : 
[2021/10/31 02:30:38] root INFO:     Eval : 
[2021/10/31 02:30:38] root INFO:         CELoss : 
[2021/10/31 02:30:38] root INFO:             weight : 1.0
[2021/10/31 02:30:38] root INFO:     Train : 
[2021/10/31 02:30:38] root INFO:         CELoss : 
[2021/10/31 02:30:38] root INFO:             weight : 1.0
[2021/10/31 02:30:38] root INFO: Metric : 
[2021/10/31 02:30:38] root INFO:     Eval : 
[2021/10/31 02:30:38] root INFO:         TopkAcc : 
[2021/10/31 02:30:38] root INFO:             topk : [1, 5]
[2021/10/31 02:30:38] root INFO:     Train : 
[2021/10/31 02:30:38] root INFO:         TopkAcc : 
[2021/10/31 02:30:38] root INFO:             topk : [1, 5]
[2021/10/31 02:30:38] root INFO: Optimizer : 
[2021/10/31 02:30:38] root INFO:     lr : 
[2021/10/31 02:30:38] root INFO:         learning_rate : 0.0125
[2021/10/31 02:30:38] root INFO:         name : Cosine
[2021/10/31 02:30:38] root INFO:         warmup_epoch : 5
[2021/10/31 02:30:38] root INFO:     momentum : 0.9
[2021/10/31 02:30:38] root INFO:     name : Momentum
[2021/10/31 02:30:38] root INFO:     regularizer : 
[2021/10/31 02:30:38] root INFO:         coeff : 1e-05
[2021/10/31 02:30:38] root INFO:         name : L2
[2021/10/31 02:30:38] root INFO: train with paddle 2.1.2 and device CUDAPlace(0)
W1031 02:30:38.361168 11634 device_context.cc:404] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W1031 02:30:38.365787 11634 device_context.cc:422] device: 0, cuDNN Version: 7.6.
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:77: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  return (isinstance(seq, collections.Sequence) and
Copy the code

The file was saved to PaddleClas/inference/

inference.pdiparams  
inference.pdiparams.info  
inference.pdmodel
Copy the code

2.2 Inference was used for prediction

%cd deploy ! python3 python/predict_cls.py \ -c configs/inference_cls.yaml \ -o Global.infer_imgs=/home/aistudio/data/oxford-102-flowers/oxford-102-flowers/jpg/image_00033.jpg \ -o Global.inference_model_dir=.. /inference/ \ -o PostProcess.Topk.class_id_map_file=None
Copy the code
/home/aistudio/PaddleClas/deploy 2021-10-31 02:34:50 INFO: =========================================================== == PaddleClas is powered by PaddlePaddle ! == =========================================================== == == == For more info please go to the following website. == == == == https://github.com/PaddlePaddle/PaddleClas == =========================================================== 2021-10-31 02:34:50 INFO: Global : 2021-10-31 02:34:50 INFO: batch_size : 1 2021-10-31 02:34:50 INFO: cpu_num_threads : 10 2021-10-31 02:34:50 INFO: enable_benchmark : True 2021-10-31 02:34:50 INFO: enable_mkldnn : True 2021-10-31 02:34:50 INFO: enable_profile : False 2021-10-31 02:34:50 INFO: gpu_mem : 8000 2021-10-31 02:34:50 INFO: infer_imgs : /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/jpg/image_00033.jpg 2021-10-31 02:34:50 INFO: inference_model_dir : .. /inference/ 2021-10-31 02:34:50 INFO: ir_optim : True 2021-10-31 02:34:50 INFO: use_fp16 : False 2021-10-31 02:34:50 INFO: use_gpu : True 2021-10-31 02:34:50 INFO: use_tensorrt : False 2021-10-31 02:34:50 INFO: PostProcess : 2021-10-31 02:34:50 INFO: SavePreLabel : 2021-10-31 02:34:50 INFO: save_dir : ./pre_label/ 2021-10-31 02:34:50 INFO: Topk : 2021-10-31 02:34:50 INFO: class_id_map_file : None 2021-10-31 02:34:50 INFO: topk : 5 2021-10-31 02:34:50 INFO: main_indicator : Topk 2021-10-31 02:34:50 INFO: PreProcess : 2021-10-31 02:34:50 INFO: transform_ops : 2021-10-31 02:34:50 INFO: ResizeImage : 2021-10-31 02:34:50 INFO: resize_short : 256 2021-10-31 02:34:50 INFO: CropImage : 2021-10-31 02:34:50 INFO: size : 224 2021-10-31 02:34:50 INFO: NormalizeImage : 2021-10-31 02:34:50 INFO: channel_num : 3 2021-10-31 02:34:50 INFO: Mean: [0.485, 0.456, 0.406] 2021-10-31 02:34:50 INFO: Order: 2021-10-31 02:34:50 INFO: scale: 0.00392157 2021-10-31 02:34:50 INFO: STD: [0.229, 0.224, 0.225] 2021-10-31 02:34:50 INFO: ToCHWImage: None image_00033.jpg: class ID (s): [37, 35, 76, 28, 50], Score (s): [0.46, 0.13, 0.04, 0.03, 0.03], label_name(s): []Copy the code
Copy the code

5. Model evaluation

! python tools/eval.py \
        -c ./ppcls/configs/quick_start/ResNet50_vd.yaml \
        -o Global.pretrained_model=output/ResNet50_vd/best_model
Copy the code
/home/aistudio/PaddleClas/ppcls/arch/backbone/model_zoo/vision_transformer.py:15: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Callable
[2021/10/31 02:28:12] root INFO: 
===========================================================
==        PaddleClas is powered by PaddlePaddle !        ==
===========================================================
==                                                       ==
==   For more info please go to the following website.   ==
==                                                       ==
==       https://github.com/PaddlePaddle/PaddleClas      ==
===========================================================

[2021/10/31 02:28:12] root INFO: Arch : 
[2021/10/31 02:28:12] root INFO:     name : ResNet50_vd
[2021/10/31 02:28:12] root INFO: DataLoader : 
[2021/10/31 02:28:12] root INFO:     Eval : 
[2021/10/31 02:28:12] root INFO:         dataset : 
[2021/10/31 02:28:12] root INFO:             cls_label_path : valid.txt
[2021/10/31 02:28:12] root INFO:             image_root : /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/
[2021/10/31 02:28:12] root INFO:             name : ImageNetDataset
[2021/10/31 02:28:12] root INFO:             transform_ops : 
[2021/10/31 02:28:12] root INFO:                 DecodeImage : 
[2021/10/31 02:28:12] root INFO:                     channel_first : False
[2021/10/31 02:28:12] root INFO:                     to_rgb : True
[2021/10/31 02:28:12] root INFO:                 ResizeImage : 
[2021/10/31 02:28:12] root INFO:                     resize_short : 256
[2021/10/31 02:28:12] root INFO:                 CropImage : 
[2021/10/31 02:28:12] root INFO:                     size : 224
[2021/10/31 02:28:12] root INFO:                 NormalizeImage : 
[2021/10/31 02:28:12] root INFO:                     mean : [0.485, 0.456, 0.406]
[2021/10/31 02:28:12] root INFO:                     order : 
[2021/10/31 02:28:12] root INFO:                     scale : 1.0/255.0
[2021/10/31 02:28:12] root INFO:                     std : [0.229, 0.224, 0.225]
[2021/10/31 02:28:12] root INFO:         loader : 
[2021/10/31 02:28:12] root INFO:             num_workers : 4
[2021/10/31 02:28:12] root INFO:             use_shared_memory : True
[2021/10/31 02:28:12] root INFO:         sampler : 
[2021/10/31 02:28:12] root INFO:             batch_size : 256
[2021/10/31 02:28:12] root INFO:             drop_last : False
[2021/10/31 02:28:12] root INFO:             name : DistributedBatchSampler
[2021/10/31 02:28:12] root INFO:             shuffle : False
[2021/10/31 02:28:12] root INFO:     Train : 
[2021/10/31 02:28:12] root INFO:         dataset : 
[2021/10/31 02:28:12] root INFO:             cls_label_path : train.txt
[2021/10/31 02:28:12] root INFO:             image_root : /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/
[2021/10/31 02:28:12] root INFO:             name : ImageNetDataset
[2021/10/31 02:28:12] root INFO:             transform_ops : 
[2021/10/31 02:28:12] root INFO:                 DecodeImage : 
[2021/10/31 02:28:12] root INFO:                     channel_first : False
[2021/10/31 02:28:12] root INFO:                     to_rgb : True
[2021/10/31 02:28:12] root INFO:                 RandCropImage : 
[2021/10/31 02:28:12] root INFO:                     size : 224
[2021/10/31 02:28:12] root INFO:                 RandFlipImage : 
[2021/10/31 02:28:12] root INFO:                     flip_code : 1
[2021/10/31 02:28:12] root INFO:                 NormalizeImage : 
[2021/10/31 02:28:12] root INFO:                     mean : [0.485, 0.456, 0.406]
[2021/10/31 02:28:12] root INFO:                     order : 
[2021/10/31 02:28:12] root INFO:                     scale : 1.0/255.0
[2021/10/31 02:28:12] root INFO:                     std : [0.229, 0.224, 0.225]
[2021/10/31 02:28:12] root INFO:         loader : 
[2021/10/31 02:28:12] root INFO:             num_workers : 4
[2021/10/31 02:28:12] root INFO:             use_shared_memory : True
[2021/10/31 02:28:12] root INFO:         sampler : 
[2021/10/31 02:28:12] root INFO:             batch_size : 256
[2021/10/31 02:28:12] root INFO:             drop_last : False
[2021/10/31 02:28:12] root INFO:             name : DistributedBatchSampler
[2021/10/31 02:28:12] root INFO:             shuffle : True
[2021/10/31 02:28:12] root INFO: Global : 
[2021/10/31 02:28:12] root INFO:     checkpoints : None
[2021/10/31 02:28:12] root INFO:     class_num : 102
[2021/10/31 02:28:12] root INFO:     device : gpu
[2021/10/31 02:28:12] root INFO:     epochs : 20
[2021/10/31 02:28:12] root INFO:     eval_during_train : True
[2021/10/31 02:28:12] root INFO:     eval_interval : 5
[2021/10/31 02:28:12] root INFO:     image_shape : [3, 224, 224]
[2021/10/31 02:28:12] root INFO:     output_dir : ./output/
[2021/10/31 02:28:12] root INFO:     pretrained_model : output/ResNet50_vd/best_model
[2021/10/31 02:28:12] root INFO:     print_batch_step : 10
[2021/10/31 02:28:12] root INFO:     save_inference_dir : ./inference
[2021/10/31 02:28:12] root INFO:     save_interval : 5
[2021/10/31 02:28:12] root INFO:     use_visualdl : False
[2021/10/31 02:28:12] root INFO: Infer : 
[2021/10/31 02:28:12] root INFO:     PostProcess : 
[2021/10/31 02:28:12] root INFO:         class_id_map_file : /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/jpg/image_00030.jpg
[2021/10/31 02:28:12] root INFO:         name : Topk
[2021/10/31 02:28:12] root INFO:         topk : 5
[2021/10/31 02:28:12] root INFO:     batch_size : 10
[2021/10/31 02:28:12] root INFO:     infer_imgs : /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/
[2021/10/31 02:28:12] root INFO:     transforms : 
[2021/10/31 02:28:12] root INFO:         DecodeImage : 
[2021/10/31 02:28:12] root INFO:             channel_first : False
[2021/10/31 02:28:12] root INFO:             to_rgb : True
[2021/10/31 02:28:12] root INFO:         ResizeImage : 
[2021/10/31 02:28:12] root INFO:             resize_short : 256
[2021/10/31 02:28:12] root INFO:         CropImage : 
[2021/10/31 02:28:12] root INFO:             size : 224
[2021/10/31 02:28:12] root INFO:         NormalizeImage : 
[2021/10/31 02:28:12] root INFO:             mean : [0.485, 0.456, 0.406]
[2021/10/31 02:28:12] root INFO:             order : 
[2021/10/31 02:28:12] root INFO:             scale : 1.0/255.0
[2021/10/31 02:28:12] root INFO:             std : [0.229, 0.224, 0.225]
[2021/10/31 02:28:12] root INFO:         ToCHWImage : None
[2021/10/31 02:28:12] root INFO: Loss : 
[2021/10/31 02:28:12] root INFO:     Eval : 
[2021/10/31 02:28:12] root INFO:         CELoss : 
[2021/10/31 02:28:12] root INFO:             weight : 1.0
[2021/10/31 02:28:12] root INFO:     Train : 
[2021/10/31 02:28:12] root INFO:         CELoss : 
[2021/10/31 02:28:12] root INFO:             weight : 1.0
[2021/10/31 02:28:12] root INFO: Metric : 
[2021/10/31 02:28:12] root INFO:     Eval : 
[2021/10/31 02:28:12] root INFO:         TopkAcc : 
[2021/10/31 02:28:12] root INFO:             topk : [1, 5]
[2021/10/31 02:28:12] root INFO:     Train : 
[2021/10/31 02:28:12] root INFO:         TopkAcc : 
[2021/10/31 02:28:12] root INFO:             topk : [1, 5]
[2021/10/31 02:28:12] root INFO: Optimizer : 
[2021/10/31 02:28:12] root INFO:     lr : 
[2021/10/31 02:28:12] root INFO:         learning_rate : 0.0125
[2021/10/31 02:28:12] root INFO:         name : Cosine
[2021/10/31 02:28:12] root INFO:         warmup_epoch : 5
[2021/10/31 02:28:12] root INFO:     momentum : 0.9
[2021/10/31 02:28:12] root INFO:     name : Momentum
[2021/10/31 02:28:12] root INFO:     regularizer : 
[2021/10/31 02:28:12] root INFO:         coeff : 1e-05
[2021/10/31 02:28:12] root INFO:         name : L2
[2021/10/31 02:28:12] root INFO: train with paddle 2.1.2 and device CUDAPlace(0)
self._cls_path /home/aistudio/data/oxford-102-flowers/oxford-102-flowers/valid.txt
W1031 02:28:12.918593 11295 device_context.cc:404] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W1031 02:28:12.923264 11295 device_context.cc:422] device: 0, cuDNN Version: 7.6.
[2021/10/31 02:28:21] root INFO: [Eval][Epoch 0][Iter: 0/4]CELoss: 0.47912, loss: 0.47912, top1: 0.91797, top5: 0.96094, batch_cost: 3.39170s, reader_cost: 2.99661, ips: 75.47843 images/sec
[2021/10/31 02:28:22] root INFO: [Eval][Epoch 0][Avg]CELoss: 0.54982, loss: 0.54982, top1: 0.88922, top5: 0.96667
Copy the code

The eval result

W1031 02:28:12.923264 11295 Device_Context. cc:422] DEVICE: 0, cuDNN Version: 7.6. [2021/10/31 02:28:21] root INFO: [Eval][Epoch 0][Iter: 0/4]CELoss: 0.47912, Loss: 0.47912, TOP1:0.91797, TOP5:0.96094, batCH_cost: 3.39170s, reader_cost: 2.99661, IPS: 75.47843 images/ SEC [2021/10/31 02:28:22] root INFO: [Eval][Epoch 0][Avg]CELoss: 0.54982, Loss: 0.54982, TOP1:0.88922, TOP5:0.96667Copy the code
Copy the code