Skip to content

Commit

Permalink
deeplabv3 bug fix (#754)
Browse files Browse the repository at this point in the history
Co-authored-by: Fzilan <Fzilan@users.noreply.github.com>
  • Loading branch information
Fzilan and Fzilan authored Jan 11, 2024
1 parent 9c6dc67 commit 67ba9a2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions examples/seg/deeplabv3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ This example provides implementations of DeepLabV3 and DeepLabV3+ using backbone

* Download Pascal VOC 2012 dataset, [VOC2012](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/) and Semantic Boundaries Dataset, [SBD](https://www2.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/semantic_contours/benchmark.tgz).

* Prepare training and test data list files with the path to image and annotation pairs. You could simply run `python examples/seg/deeplabv3/preprocess/get_dataset_list.py --data_root=/path/to/data` to generate the list files. This command results in 5 data list files. The lines in a list file should be like as follows:
* Prepare training and test data list files with the path to image and annotation pairs. You could simply run `python examples/seg/deeplabv3/preprocess/get_data_list.py --data_root=/path/to/data` to generate the list files. This command results in 5 data list files. The lines in a list file should be like as follows:

```
/path/to/data/JPEGImages/2007_000032.jpg /path/to/data/SegmentationClassGray/2007_000032.png
Expand Down Expand Up @@ -116,20 +116,20 @@ python examples/seg/deeplabv3/train.py --config [the path to the config file]

```shell
# for deeplabv3
mpirun -n 8 python examples/seg/deeplabv3/train.py --config examples/seg/deeplabv3/deeplabv3_s16_dilated_resnet101.yaml
mpirun -n 8 python examples/seg/deeplabv3/train.py --config examples/seg/deeplabv3/config/deeplabv3_s16_dilated_resnet101.yaml

# for deeplabv3+
mpirun -n 8 python examples/seg/deeplabv3/train.py --config examples/seg/deeplabv3/deeplabv3plus_s16_dilated_resnet101.yaml
mpirun -n 8 python examples/seg/deeplabv3/train.py --config examples/seg/deeplabv3/config/deeplabv3plus_s16_dilated_resnet101.yaml
```

- Step 2: Employ output_stride=8, fine-tune model from step 1 on *trainaug* dataset with smaller base learning rate. In config file, please specify the path of checkpoint from previous step in `ckpt_path`, set `ckpt_pre_trained` to `True` and set `output_stride` to `8` .

```shell
# for deeplabv3
mpirun -n 8 python examples/seg/deeplabv3/train.py --config examples/seg/deeplabv3/deeplabv3_s8_dilated_resnet101.yaml
mpirun -n 8 python examples/seg/deeplabv3/train.py --config examples/seg/deeplabv3/config/deeplabv3_s8_dilated_resnet101.yaml

# for deeplabv3+
mpirun -n 8 python examples/seg/deeplabv3/train.py --config examples/seg/deeplabv3/deeplabv3plus_s8_dilated_resnet101.yaml
mpirun -n 8 python examples/seg/deeplabv3/train.py --config examples/seg/deeplabv3/config/deeplabv3plus_s8_dilated_resnet101.yaml
```

### Test
Expand All @@ -138,7 +138,7 @@ For testing the trained model, first specify the path to the model checkpoint at

For example, after replacing `ckpt_path` in config file with [checkpoint](https://download.mindspore.cn/toolkits/mindcv/deeplabv3/deeplabv3_s8_resnet101-a297e7af.ckpt) from 2-step training of deeplabv3, commands below employ os=8 without left-right filpped or muticale inputs.
```shell
python examples/seg/deeplabv3/eval.py --config examples/seg/deeplabv3/deeplabv3_s8_dilated_resnet101.yaml
python examples/seg/deeplabv3/eval.py --config examples/seg/deeplabv3/config/deeplabv3_s8_dilated_resnet101.yaml
```

## Results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ image_std: [57.375, 57.120, 58.395]
max_scale: 2.0
min_scale: 0.5
ignore_label: 255
num_classes: 21x
num_classes: 21
shuffle: True

# backbone
Expand Down
6 changes: 3 additions & 3 deletions examples/seg/deeplabv3/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import yaml
from addict import Dict
from data import create_segment_dataset
from deeplabv3 import DeeplabInferNetwork, DeepLabV3, DeeplabV3Plus
from deeplabv3 import DeepLabInferNetwork, DeepLabV3, DeepLabV3Plus
from dilated_resnet import * # noqa: F403, F401
from postprocess import apply_eval

Expand Down Expand Up @@ -34,11 +34,11 @@ def eval(args):
if args.model == "deeplabv3":
deeplab = DeepLabV3(backbone, args, is_training=False)
elif args.model == "deeplabv3plus":
deeplab = DeeplabV3Plus(backbone, args, is_training=False)
deeplab = DeepLabV3Plus(backbone, args, is_training=False)
else:
NotImplementedError("support deeplabv3 and deeplabv3plus only")

eval_model = DeeplabInferNetwork(deeplab, input_format=args.input_format)
eval_model = DeepLabInferNetwork(deeplab, input_format=args.input_format)

param_dict = load_checkpoint(args.ckpt_path)
net_param_not_load, _ = load_param_into_net(eval_model, param_dict)
Expand Down

0 comments on commit 67ba9a2

Please sign in to comment.