From 63cf3ba4d1f5e99f7c76cd79973c86f0929957e7 Mon Sep 17 00:00:00 2001 From: littletomatodonkey <2120160898@bit.edu.cn> Date: Thu, 10 Jun 2021 21:13:38 +0800 Subject: [PATCH] fix imread (#824) * fix imread * rm unused decode * rm decode --- .../Cartoonface/ResNet50_icartoon.yaml | 69 +++++++++++-------- .../MobileNetV3/MobileNetV3_large_x1_0.yaml | 6 ++ ppcls/configs/ImageNet/ResNet/ResNet50.yaml | 6 ++ ppcls/configs/Logo/ResNet50_ReID.yaml | 61 +++++++++------- .../Products/ResNet50_vd_Aliproduct.yaml | 6 ++ .../configs/Products/ResNet50_vd_Inshop.yaml | 9 +++ ppcls/configs/Products/ResNet50_vd_SOP.yaml | 9 +++ ppcls/configs/Vehicle/ResNet50.yaml | 20 ++++-- ppcls/configs/Vehicle/ResNet50_ReID.yaml | 9 +++ ppcls/data/dataloader/common_dataset.py | 4 +- 10 files changed, 134 insertions(+), 65 deletions(-) diff --git a/ppcls/configs/Cartoonface/ResNet50_icartoon.yaml b/ppcls/configs/Cartoonface/ResNet50_icartoon.yaml index 9640b7be..01ab83e1 100644 --- a/ppcls/configs/Cartoonface/ResNet50_icartoon.yaml +++ b/ppcls/configs/Cartoonface/ResNet50_icartoon.yaml @@ -60,19 +60,22 @@ Optimizer: DataLoader: Train: dataset: - name: ICartoonDataset - image_root: "./dataset/iCartoonFace" - cls_label_path: "./dataset/iCartoonFace/train_list.txt" - transform_ops: - - RandCropImage: - size: 224 - - RandFlipImage: - flip_code: 1 - - NormalizeImage: - scale: 0.00392157 - mean: [0.485, 0.456, 0.406] - std: [0.229, 0.224, 0.225] - order: '' + name: ICartoonDataset + image_root: "./dataset/iCartoonFace" + cls_label_path: "./dataset/iCartoonFace/train_list.txt" + transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False + - RandCropImage: + size: 224 + - RandFlipImage: + flip_code: 1 + - NormalizeImage: + scale: 0.00392157 + mean: [0.485, 0.456, 0.406] + std: [0.229, 0.224, 0.225] + order: '' sampler: name: DistributedBatchSampler #num_instances: 2 @@ -86,27 +89,30 @@ DataLoader: Eval: Query: dataset: - name: ICartoonDataset - image_root: "./dataset/iCartoonFace" - cls_label_path: "./dataset/iCartoonFace/query.txt" - transform_ops: - - ResizeImage: - resize_short: 256 - - CropImage: - size: 224 - - NormalizeImage: - scale: 0.00392157 - mean: [0.485, 0.456, 0.406] - std: [0.229, 0.224, 0.225] - order: '' + name: ICartoonDataset + image_root: "./dataset/iCartoonFace" + cls_label_path: "./dataset/iCartoonFace/query.txt" + transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False + - ResizeImage: + resize_short: 256 + - CropImage: + size: 224 + - NormalizeImage: + scale: 0.00392157 + mean: [0.485, 0.456, 0.406] + std: [0.229, 0.224, 0.225] + order: '' sampler: name: DistributedBatchSampler batch_size: 64 drop_last: False shuffle: False loader: - num_workers: 6 - use_shared_memory: False + num_workers: 8 + use_shared_memory: True Gallery: dataset: @@ -114,6 +120,9 @@ DataLoader: image_root: "./dataset/iCartoonFace" cls_label_path: "./dataset/iCartoonFace/gallery.txt" transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: resize_short: 256 - CropImage: @@ -129,8 +138,8 @@ DataLoader: drop_last: False shuffle: False loader: - num_workers: 6 - use_shared_memory: False + num_workers: 8 + use_shared_memory: True Metric: Train: diff --git a/ppcls/configs/ImageNet/MobileNetV3/MobileNetV3_large_x1_0.yaml b/ppcls/configs/ImageNet/MobileNetV3/MobileNetV3_large_x1_0.yaml index 16798a0a..c3f9be69 100644 --- a/ppcls/configs/ImageNet/MobileNetV3/MobileNetV3_large_x1_0.yaml +++ b/ppcls/configs/ImageNet/MobileNetV3/MobileNetV3_large_x1_0.yaml @@ -49,6 +49,9 @@ DataLoader: image_root: ./dataset/ILSVRC2012/ cls_label_path: ./dataset/ILSVRC2012/train_list.txt transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - RandCropImage: size: 224 - RandFlipImage: @@ -76,6 +79,9 @@ DataLoader: image_root: ./dataset/ILSVRC2012/ cls_label_path: ./dataset/ILSVRC2012/val_list.txt transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: resize_short: 256 - CropImage: diff --git a/ppcls/configs/ImageNet/ResNet/ResNet50.yaml b/ppcls/configs/ImageNet/ResNet/ResNet50.yaml index 257cbef9..5206bfb0 100644 --- a/ppcls/configs/ImageNet/ResNet/ResNet50.yaml +++ b/ppcls/configs/ImageNet/ResNet/ResNet50.yaml @@ -50,6 +50,9 @@ DataLoader: image_root: ./dataset/ILSVRC2012/ cls_label_path: ./dataset/ILSVRC2012/train_list.txt transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - RandCropImage: size: 224 - RandFlipImage: @@ -76,6 +79,9 @@ DataLoader: image_root: ./dataset/ILSVRC2012/ cls_label_path: ./dataset/ILSVRC2012/val_list.txt transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: resize_short: 256 - CropImage: diff --git a/ppcls/configs/Logo/ResNet50_ReID.yaml b/ppcls/configs/Logo/ResNet50_ReID.yaml index 5b129911..6e6a825d 100644 --- a/ppcls/configs/Logo/ResNet50_ReID.yaml +++ b/ppcls/configs/Logo/ResNet50_ReID.yaml @@ -65,6 +65,9 @@ DataLoader: image_root: "dataset/LogoDet-3K-crop/train/" cls_label_path: "dataset/LogoDet-3K-crop/LogoDet-3K+train.txt" transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: size: 224 - RandFlipImage: @@ -91,25 +94,28 @@ DataLoader: Query: # TOTO: modify to the latest trainer dataset: - name: LogoDataset - image_root: "dataset/LogoDet-3K-crop/val/" - cls_label_path: "LogoDet-3K-crop/LogoDet-3K+query.txt" - transform_ops: - - ResizeImage: - size: 224 - - NormalizeImage: - scale: 0.00392157 - mean: [0.485, 0.456, 0.406] - std: [0.229, 0.224, 0.225] - order: '' + name: LogoDataset + image_root: "dataset/LogoDet-3K-crop/val/" + cls_label_path: "LogoDet-3K-crop/LogoDet-3K+query.txt" + transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False + - ResizeImage: + size: 224 + - NormalizeImage: + scale: 0.00392157 + mean: [0.485, 0.456, 0.406] + std: [0.229, 0.224, 0.225] + order: '' sampler: name: DistributedBatchSampler batch_size: 128 drop_last: False shuffle: False loader: - num_workers: 10 - use_shared_memory: False + num_workers: 8 + use_shared_memory: True Gallery: # TOTO: modify to the latest trainer @@ -118,6 +124,9 @@ DataLoader: image_root: "dataset/LogoDet-3K-crop/train/" cls_label_path: "dataset/LogoDet-3K-crop/LogoDet-3K+gallery.txt" transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: size: 224 - NormalizeImage: @@ -131,8 +140,8 @@ DataLoader: drop_last: False shuffle: False loader: - num_workers: 10 - use_shared_memory: False + num_workers: 8 + use_shared_memory: True Metric: Eval: @@ -145,14 +154,14 @@ Infer: infer_imgs: "docs/images/whl/demo.jpg" batch_size: 10 transforms: - - DecodeImage: - to_rgb: True - channel_first: False - - ResizeImage: - resize_short: 224 - - NormalizeImage: - scale: 1.0/255.0 - mean: [0.485, 0.456, 0.406] - std: [0.229, 0.224, 0.225] - order: '' - - ToCHWImage: + - DecodeImage: + to_rgb: True + channel_first: False + - ResizeImage: + resize_short: 224 + - NormalizeImage: + scale: 1.0/255.0 + mean: [0.485, 0.456, 0.406] + std: [0.229, 0.224, 0.225] + order: '' + - ToCHWImage: diff --git a/ppcls/configs/Products/ResNet50_vd_Aliproduct.yaml b/ppcls/configs/Products/ResNet50_vd_Aliproduct.yaml index 2b5f1f2e..263e266d 100644 --- a/ppcls/configs/Products/ResNet50_vd_Aliproduct.yaml +++ b/ppcls/configs/Products/ResNet50_vd_Aliproduct.yaml @@ -60,6 +60,9 @@ DataLoader: image_root: ./dataset/Aliproduct/ cls_label_path: ./dataset/Aliproduct/train_list.txt transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: size: 224 - RandFlipImage: @@ -85,6 +88,9 @@ DataLoader: image_root: ./dataset/Aliproduct/ cls_label_path: ./dataset/Aliproduct/val_list.txt transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: resize_short: 256 - CropImage: diff --git a/ppcls/configs/Products/ResNet50_vd_Inshop.yaml b/ppcls/configs/Products/ResNet50_vd_Inshop.yaml index ba1fbd91..d6c4da86 100644 --- a/ppcls/configs/Products/ResNet50_vd_Inshop.yaml +++ b/ppcls/configs/Products/ResNet50_vd_Inshop.yaml @@ -74,6 +74,9 @@ DataLoader: image_root: ./dataset/Inshop/ cls_label_path: ./dataset/Inshop/train_list.txt transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: size: 224 - RandFlipImage: @@ -106,6 +109,9 @@ DataLoader: image_root: ./dataset/Inshop/ cls_label_path: ./dataset/Inshop/query_list.txt transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: size: 224 - NormalizeImage: @@ -128,6 +134,9 @@ DataLoader: image_root: ./dataset/Inshop/ cls_label_path: ./dataset/Inshop/gallery_list.txt transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: size: 224 - NormalizeImage: diff --git a/ppcls/configs/Products/ResNet50_vd_SOP.yaml b/ppcls/configs/Products/ResNet50_vd_SOP.yaml index 22c9c5e4..9c078a41 100644 --- a/ppcls/configs/Products/ResNet50_vd_SOP.yaml +++ b/ppcls/configs/Products/ResNet50_vd_SOP.yaml @@ -73,6 +73,9 @@ DataLoader: image_root: ./dataset/Stanford_Online_Products/ cls_label_path: ./dataset/Stanford_Online_Products/train_list.txt transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: size: 224 - RandFlipImage: @@ -105,6 +108,9 @@ DataLoader: image_root: ./dataset/Stanford_Online_Products/ cls_label_path: ./dataset/Stanford_Online_Products/test_list.txt transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: size: 224 - NormalizeImage: @@ -127,6 +133,9 @@ DataLoader: image_root: ./dataset/Stanford_Online_Products/ cls_label_path: ./dataset/Stanford_Online_Products/test_list.txt transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: size: 224 - NormalizeImage: diff --git a/ppcls/configs/Vehicle/ResNet50.yaml b/ppcls/configs/Vehicle/ResNet50.yaml index e7c4736d..df8f26eb 100644 --- a/ppcls/configs/Vehicle/ResNet50.yaml +++ b/ppcls/configs/Vehicle/ResNet50.yaml @@ -71,6 +71,9 @@ DataLoader: bbox_crop: True cls_label_path: "/work/dataset/CompCars/train_test_split/classification/train_label.txt" transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: size: 224 - RandFlipImage: @@ -96,18 +99,21 @@ DataLoader: drop_last: False shuffle: True loader: - num_workers: 6 - use_shared_memory: False + num_workers: 8 + use_shared_memory: True Eval: # TOTO: modify to the latest trainer dataset: name: "CompCars" - image_root: "/work/dataset/CompCars/image/" - label_root: "/work/dataset/CompCars/label/" - cls_label_path: "/work/dataset/CompCars/train_test_split/classification/test_label.txt" + image_root: ".dataset/CompCars/image/" + label_root: "./dataset/CompCars/label/" + cls_label_path: "./dataset/CompCars/train_test_split/classification/test_label.txt" bbox_crop: True transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: size: 224 - NormalizeImage: @@ -121,8 +127,8 @@ DataLoader: drop_last: False shuffle: False loader: - num_workers: 6 - use_shared_memory: False + num_workers: 8 + use_shared_memory: True Infer: infer_imgs: "docs/images/whl/demo.jpg" diff --git a/ppcls/configs/Vehicle/ResNet50_ReID.yaml b/ppcls/configs/Vehicle/ResNet50_ReID.yaml index a8d20474..4548174c 100644 --- a/ppcls/configs/Vehicle/ResNet50_ReID.yaml +++ b/ppcls/configs/Vehicle/ResNet50_ReID.yaml @@ -69,6 +69,9 @@ DataLoader: image_root: "/work/dataset/VeRI-Wild/images/" cls_label_path: "/work/dataset/VeRI-Wild/train_test_split/train_list_start0.txt" transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: size: 224 - RandFlipImage: @@ -104,6 +107,9 @@ DataLoader: image_root: "/work/dataset/VeRI-Wild/images" cls_label_path: "/work/dataset/VeRI-Wild/train_test_split/test_3000_id_query.txt" transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: size: 224 - NormalizeImage: @@ -127,6 +133,9 @@ DataLoader: image_root: "/work/dataset/VeRI-Wild/images" cls_label_path: "/work/dataset/VeRI-Wild/train_test_split/test_3000_id.txt" transform_ops: + - DecodeImage: + to_rgb: True + channel_first: False - ResizeImage: size: 224 - NormalizeImage: diff --git a/ppcls/data/dataloader/common_dataset.py b/ppcls/data/dataloader/common_dataset.py index a99cc23c..b7b03d8b 100644 --- a/ppcls/data/dataloader/common_dataset.py +++ b/ppcls/data/dataloader/common_dataset.py @@ -63,8 +63,8 @@ class CommonDataset(Dataset): def __getitem__(self, idx): try: - img = cv2.imread(self.images[idx]) - img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) + with open(self.images[idx], 'rb') as f: + img = f.read() if self._transform_ops: img = transform(img, self._transform_ops) img = img.transpose((2, 0, 1)) -- GitLab