diff --git a/model_zoo/deeplabv3/README.md b/model_zoo/official/cv/deeplabv3/README.md similarity index 87% rename from model_zoo/deeplabv3/README.md rename to model_zoo/official/cv/deeplabv3/README.md index c8df3dab8dd..179793a3f7a 100644 --- a/model_zoo/deeplabv3/README.md +++ b/model_zoo/official/cv/deeplabv3/README.md @@ -1,11 +1,16 @@ -# Deeplab-V3 Example +# DeeplabV3 Example ## Description -This is an example of training DeepLabv3 with PASCAL VOC 2012 dataset in MindSpore. +This is an example of training DeepLabV3 with PASCAL VOC 2012 dataset in MindSpore. ## Requirements - Install [MindSpore](https://www.mindspore.cn/install/en). - Download the VOC 2012 dataset for training. +- We need to run `./src/remove_gt_colormap.py` to remove the label colormap. + ``` bash + python remove_gt_colormap.py --original_gt_folder GT_FOLDER --output_dir OUTPUT_DIR + + ``` > Notes: If you are running a fine-tuning or evaluation task, prepare the corresponding checkpoint file. @@ -30,7 +35,7 @@ Set options in evaluation_config.py. Make sure the 'data_file' and 'finetune_ckp ``` ## Options and Parameters -It contains of parameters of Deeplab-V3 model and options for training, which is set in file config.py. +It contains of parameters of DeeplabV3 model and options for training, which is set in file config.py. ### Options: ``` diff --git a/model_zoo/deeplabv3/eval.py b/model_zoo/official/cv/deeplabv3/eval.py similarity index 100% rename from model_zoo/deeplabv3/eval.py rename to model_zoo/official/cv/deeplabv3/eval.py diff --git a/model_zoo/deeplabv3/scripts/run_distribute_train.sh b/model_zoo/official/cv/deeplabv3/scripts/run_distribute_train.sh similarity index 100% rename from model_zoo/deeplabv3/scripts/run_distribute_train.sh rename to model_zoo/official/cv/deeplabv3/scripts/run_distribute_train.sh diff --git a/model_zoo/deeplabv3/scripts/run_eval.sh b/model_zoo/official/cv/deeplabv3/scripts/run_eval.sh similarity index 100% rename from model_zoo/deeplabv3/scripts/run_eval.sh rename to model_zoo/official/cv/deeplabv3/scripts/run_eval.sh diff --git a/model_zoo/deeplabv3/scripts/run_standalone_train.sh b/model_zoo/official/cv/deeplabv3/scripts/run_standalone_train.sh similarity index 100% rename from model_zoo/deeplabv3/scripts/run_standalone_train.sh rename to model_zoo/official/cv/deeplabv3/scripts/run_standalone_train.sh diff --git a/model_zoo/deeplabv3/src/__init__.py b/model_zoo/official/cv/deeplabv3/src/__init__.py similarity index 100% rename from model_zoo/deeplabv3/src/__init__.py rename to model_zoo/official/cv/deeplabv3/src/__init__.py diff --git a/model_zoo/deeplabv3/src/backbone/__init__.py b/model_zoo/official/cv/deeplabv3/src/backbone/__init__.py similarity index 100% rename from model_zoo/deeplabv3/src/backbone/__init__.py rename to model_zoo/official/cv/deeplabv3/src/backbone/__init__.py diff --git a/model_zoo/deeplabv3/src/backbone/resnet_deeplab.py b/model_zoo/official/cv/deeplabv3/src/backbone/resnet_deeplab.py similarity index 100% rename from model_zoo/deeplabv3/src/backbone/resnet_deeplab.py rename to model_zoo/official/cv/deeplabv3/src/backbone/resnet_deeplab.py diff --git a/model_zoo/deeplabv3/src/config.py b/model_zoo/official/cv/deeplabv3/src/config.py similarity index 100% rename from model_zoo/deeplabv3/src/config.py rename to model_zoo/official/cv/deeplabv3/src/config.py diff --git a/model_zoo/deeplabv3/src/deeplabv3.py b/model_zoo/official/cv/deeplabv3/src/deeplabv3.py similarity index 100% rename from model_zoo/deeplabv3/src/deeplabv3.py rename to model_zoo/official/cv/deeplabv3/src/deeplabv3.py diff --git a/model_zoo/deeplabv3/src/ei_dataset.py b/model_zoo/official/cv/deeplabv3/src/ei_dataset.py similarity index 100% rename from model_zoo/deeplabv3/src/ei_dataset.py rename to model_zoo/official/cv/deeplabv3/src/ei_dataset.py diff --git a/model_zoo/deeplabv3/src/losses.py b/model_zoo/official/cv/deeplabv3/src/losses.py similarity index 100% rename from model_zoo/deeplabv3/src/losses.py rename to model_zoo/official/cv/deeplabv3/src/losses.py diff --git a/model_zoo/deeplabv3/src/md_dataset.py b/model_zoo/official/cv/deeplabv3/src/md_dataset.py similarity index 100% rename from model_zoo/deeplabv3/src/md_dataset.py rename to model_zoo/official/cv/deeplabv3/src/md_dataset.py diff --git a/model_zoo/deeplabv3/src/miou_precision.py b/model_zoo/official/cv/deeplabv3/src/miou_precision.py similarity index 100% rename from model_zoo/deeplabv3/src/miou_precision.py rename to model_zoo/official/cv/deeplabv3/src/miou_precision.py diff --git a/model_zoo/official/cv/deeplabv3/src/remove_gt_colormap.py b/model_zoo/official/cv/deeplabv3/src/remove_gt_colormap.py new file mode 100644 index 00000000000..725983d7dac --- /dev/null +++ b/model_zoo/official/cv/deeplabv3/src/remove_gt_colormap.py @@ -0,0 +1,76 @@ +# Copyright 2020 The Huawei Authors All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +"""Removes the color map from segmentation annotations. +Removes the color map from the ground truth segmentation annotations and save +the results to output_dir. +""" +import glob +import argparse +import os.path +import numpy as np + + +from PIL import Image + + +def _remove_colormap(filename): + """Removes the color map from the annotation. + Args: + filename: Ground truth annotation filename. + Returns: + Annotation without color map. + """ + return np.array(Image.open(filename)) + + +def _save_annotation(annotation, filename): + """Saves the annotation as png file. + Args: + annotation: Segmentation annotation. + filename: Output filename. + """ + pil_image = Image.fromarray(annotation.astype(dtype=np.uint8)) + pil_image.save(filename, 'PNG') + + +def main(): + parser = argparse.ArgumentParser(description="Demo of argparse") + parser.add_argument('--original_gt_folder', type=str, default='./VOCdevkit/VOC2012/SegmentationClass', + help='Original ground truth annotations.') + parser.add_argument('--segmentation_format', type=str, default='png', + help='Segmentation format.') + parser.add_argument('--output_dir', type=str, default='./VOCdevkit/VOC2012/SegmentationClassRaw', + help='folder to save modified ground truth annotations.') + args = parser.parse_args() + + # Create the output directory if not exists. + + if not os.path.isdir(args.output_dir): + os.mkdir(args.output_dir) + + annotations = glob.glob(os.path.join(args.original_gt_folder, + '*.' + args.segmentation_format)) + + for annotation in annotations: + raw_annotation = _remove_colormap(annotation) + filename = os.path.basename(annotation)[:-4] + _save_annotation(raw_annotation, + os.path.join( + args.output_dir, + filename + '.' + args.segmentation_format)) + +if __name__ == '__main__': + main() diff --git a/model_zoo/deeplabv3/src/utils/__init__.py b/model_zoo/official/cv/deeplabv3/src/utils/__init__.py similarity index 100% rename from model_zoo/deeplabv3/src/utils/__init__.py rename to model_zoo/official/cv/deeplabv3/src/utils/__init__.py diff --git a/model_zoo/deeplabv3/src/utils/adapter.py b/model_zoo/official/cv/deeplabv3/src/utils/adapter.py similarity index 100% rename from model_zoo/deeplabv3/src/utils/adapter.py rename to model_zoo/official/cv/deeplabv3/src/utils/adapter.py diff --git a/model_zoo/deeplabv3/src/utils/custom_transforms.py b/model_zoo/official/cv/deeplabv3/src/utils/custom_transforms.py similarity index 100% rename from model_zoo/deeplabv3/src/utils/custom_transforms.py rename to model_zoo/official/cv/deeplabv3/src/utils/custom_transforms.py diff --git a/model_zoo/deeplabv3/src/utils/file_io.py b/model_zoo/official/cv/deeplabv3/src/utils/file_io.py similarity index 100% rename from model_zoo/deeplabv3/src/utils/file_io.py rename to model_zoo/official/cv/deeplabv3/src/utils/file_io.py diff --git a/model_zoo/deeplabv3/train.py b/model_zoo/official/cv/deeplabv3/train.py similarity index 100% rename from model_zoo/deeplabv3/train.py rename to model_zoo/official/cv/deeplabv3/train.py diff --git a/model_zoo/resnext50/README.md b/model_zoo/official/cv/resnext50/README.md similarity index 93% rename from model_zoo/resnext50/README.md rename to model_zoo/official/cv/resnext50/README.md index c44844eecc9..55b54d84ac5 100644 --- a/model_zoo/resnext50/README.md +++ b/model_zoo/official/cv/resnext50/README.md @@ -2,12 +2,12 @@ ## Description -This is an example of training ResNext50 with ImageNet dataset in Mindspore. +This is an example of training ResNext50 in MindSpore. ## Requirements - Install [Mindspore](http://www.mindspore.cn/install/en). -- Downlaod the dataset ImageNet2012. +- Downlaod the dataset. ## Structure @@ -91,9 +91,9 @@ sh run_standalone_train.sh DEVICE_ID DATA_PATH ```bash # distributed training example(8p) -sh scripts/run_distribute_train.sh MINDSPORE_HCCL_CONFIG_PATH /ImageNet/train +sh scripts/run_distribute_train.sh MINDSPORE_HCCL_CONFIG_PATH /dataset/train # standalone training example -sh scripts/run_standalone_train.sh 0 /ImageNet_Original/train +sh scripts/run_standalone_train.sh 0 /dataset/train ``` #### Result @@ -123,6 +123,6 @@ sh scripts/run_eval.sh 0 /opt/npu/datasets/classification/val /resnext50_100.ckp Evaluation result will be stored in the scripts path. Under this, you can find result like the followings in log. ``` -acc=78,16%(TOP1) +acc=78.16%(TOP1) acc=93.88%(TOP5) ``` \ No newline at end of file diff --git a/model_zoo/resnext50/eval.py b/model_zoo/official/cv/resnext50/eval.py similarity index 100% rename from model_zoo/resnext50/eval.py rename to model_zoo/official/cv/resnext50/eval.py diff --git a/model_zoo/resnext50/scripts/run_distribute_train.sh b/model_zoo/official/cv/resnext50/scripts/run_distribute_train.sh similarity index 100% rename from model_zoo/resnext50/scripts/run_distribute_train.sh rename to model_zoo/official/cv/resnext50/scripts/run_distribute_train.sh diff --git a/model_zoo/resnext50/scripts/run_eval.sh b/model_zoo/official/cv/resnext50/scripts/run_eval.sh similarity index 100% rename from model_zoo/resnext50/scripts/run_eval.sh rename to model_zoo/official/cv/resnext50/scripts/run_eval.sh diff --git a/model_zoo/resnext50/scripts/run_standalone_train.sh b/model_zoo/official/cv/resnext50/scripts/run_standalone_train.sh similarity index 100% rename from model_zoo/resnext50/scripts/run_standalone_train.sh rename to model_zoo/official/cv/resnext50/scripts/run_standalone_train.sh diff --git a/model_zoo/resnext50/src/__init__.py b/model_zoo/official/cv/resnext50/src/__init__.py similarity index 100% rename from model_zoo/resnext50/src/__init__.py rename to model_zoo/official/cv/resnext50/src/__init__.py diff --git a/model_zoo/resnext50/src/backbone/__init__.py b/model_zoo/official/cv/resnext50/src/backbone/__init__.py similarity index 100% rename from model_zoo/resnext50/src/backbone/__init__.py rename to model_zoo/official/cv/resnext50/src/backbone/__init__.py diff --git a/model_zoo/resnext50/src/backbone/resnet.py b/model_zoo/official/cv/resnext50/src/backbone/resnet.py similarity index 100% rename from model_zoo/resnext50/src/backbone/resnet.py rename to model_zoo/official/cv/resnext50/src/backbone/resnet.py diff --git a/model_zoo/resnext50/src/config.py b/model_zoo/official/cv/resnext50/src/config.py similarity index 100% rename from model_zoo/resnext50/src/config.py rename to model_zoo/official/cv/resnext50/src/config.py diff --git a/model_zoo/resnext50/src/crossentropy.py b/model_zoo/official/cv/resnext50/src/crossentropy.py similarity index 100% rename from model_zoo/resnext50/src/crossentropy.py rename to model_zoo/official/cv/resnext50/src/crossentropy.py diff --git a/model_zoo/resnext50/src/dataset.py b/model_zoo/official/cv/resnext50/src/dataset.py similarity index 100% rename from model_zoo/resnext50/src/dataset.py rename to model_zoo/official/cv/resnext50/src/dataset.py diff --git a/model_zoo/resnext50/src/head.py b/model_zoo/official/cv/resnext50/src/head.py similarity index 100% rename from model_zoo/resnext50/src/head.py rename to model_zoo/official/cv/resnext50/src/head.py diff --git a/model_zoo/resnext50/src/image_classification.py b/model_zoo/official/cv/resnext50/src/image_classification.py similarity index 100% rename from model_zoo/resnext50/src/image_classification.py rename to model_zoo/official/cv/resnext50/src/image_classification.py diff --git a/model_zoo/resnext50/src/linear_warmup.py b/model_zoo/official/cv/resnext50/src/linear_warmup.py similarity index 100% rename from model_zoo/resnext50/src/linear_warmup.py rename to model_zoo/official/cv/resnext50/src/linear_warmup.py diff --git a/model_zoo/resnext50/src/utils/__init__.py b/model_zoo/official/cv/resnext50/src/utils/__init__.py similarity index 100% rename from model_zoo/resnext50/src/utils/__init__.py rename to model_zoo/official/cv/resnext50/src/utils/__init__.py diff --git a/model_zoo/resnext50/src/utils/cunstom_op.py b/model_zoo/official/cv/resnext50/src/utils/cunstom_op.py similarity index 100% rename from model_zoo/resnext50/src/utils/cunstom_op.py rename to model_zoo/official/cv/resnext50/src/utils/cunstom_op.py diff --git a/model_zoo/resnext50/src/utils/logging.py b/model_zoo/official/cv/resnext50/src/utils/logging.py similarity index 100% rename from model_zoo/resnext50/src/utils/logging.py rename to model_zoo/official/cv/resnext50/src/utils/logging.py diff --git a/model_zoo/resnext50/src/utils/optimizers__init__.py b/model_zoo/official/cv/resnext50/src/utils/optimizers__init__.py similarity index 100% rename from model_zoo/resnext50/src/utils/optimizers__init__.py rename to model_zoo/official/cv/resnext50/src/utils/optimizers__init__.py diff --git a/model_zoo/resnext50/src/utils/sampler.py b/model_zoo/official/cv/resnext50/src/utils/sampler.py similarity index 100% rename from model_zoo/resnext50/src/utils/sampler.py rename to model_zoo/official/cv/resnext50/src/utils/sampler.py diff --git a/model_zoo/resnext50/src/utils/var_init.py b/model_zoo/official/cv/resnext50/src/utils/var_init.py similarity index 100% rename from model_zoo/resnext50/src/utils/var_init.py rename to model_zoo/official/cv/resnext50/src/utils/var_init.py diff --git a/model_zoo/resnext50/src/warmup_cosine_annealing_lr.py b/model_zoo/official/cv/resnext50/src/warmup_cosine_annealing_lr.py similarity index 100% rename from model_zoo/resnext50/src/warmup_cosine_annealing_lr.py rename to model_zoo/official/cv/resnext50/src/warmup_cosine_annealing_lr.py diff --git a/model_zoo/resnext50/src/warmup_step_lr.py b/model_zoo/official/cv/resnext50/src/warmup_step_lr.py similarity index 100% rename from model_zoo/resnext50/src/warmup_step_lr.py rename to model_zoo/official/cv/resnext50/src/warmup_step_lr.py diff --git a/model_zoo/resnext50/train.py b/model_zoo/official/cv/resnext50/train.py similarity index 100% rename from model_zoo/resnext50/train.py rename to model_zoo/official/cv/resnext50/train.py