-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
…nto develop
- Loading branch information
Showing
11 changed files
with
385 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
batch_size: 4 | ||
iters: 40000 | ||
|
||
train_dataset: | ||
type: PascalContext | ||
dataset_root: data/VOC2010/ | ||
transforms: | ||
- type: ResizeStepScaling | ||
min_scale_factor: 0.5 | ||
max_scale_factor: 2.0 | ||
scale_step_size: 0.25 | ||
- type: RandomPaddingCrop | ||
crop_size: [520, 520] | ||
- type: RandomHorizontalFlip | ||
- type: RandomDistort | ||
brightness_range: 0.4 | ||
contrast_range: 0.4 | ||
saturation_range: 0.4 | ||
- type: Normalize | ||
mode: train | ||
|
||
val_dataset: | ||
type: PascalContext | ||
dataset_root: data/VOC2010/ | ||
transforms: | ||
- type: Padding | ||
target_size: [520, 520] | ||
- type: Normalize | ||
mode: val | ||
|
||
|
||
optimizer: | ||
type: sgd | ||
momentum: 0.9 | ||
weight_decay: 4.0e-5 | ||
|
||
learning_rate: | ||
value: 0.001 | ||
decay: | ||
type: poly | ||
power: 0.9 | ||
end_lr: 0.0 | ||
|
||
loss: | ||
types: | ||
- type: CrossEntropyLoss | ||
coef: [1] | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright (c) 2020 PaddlePaddle 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. | ||
|
||
import os | ||
|
||
from PIL import Image | ||
from paddleseg.datasets import Dataset | ||
from paddleseg.cvlibs import manager | ||
from paddleseg.transforms import Compose | ||
|
||
|
||
@manager.DATASETS.add_component | ||
class PascalContext(Dataset): | ||
""" | ||
PascalVOC2010 dataset `http://host.robots.ox.ac.uk/pascal/VOC/`. | ||
If you want to use pascal context dataset, please run the convert_voc2010.py in tools firstly. | ||
Args: | ||
transforms (list): Transforms for image. | ||
dataset_root (str): The dataset directory. Default: None | ||
mode (str): Which part of dataset to use. it is one of ('train', 'trainval', 'context', 'val'). | ||
If you want to set mode to 'context', please make sure the dataset have been augmented. Default: 'train'. | ||
""" | ||
|
||
def __init__(self, transforms=None, dataset_root=None, mode='train'): | ||
self.dataset_root = dataset_root | ||
self.transforms = Compose(transforms) | ||
mode = mode.lower() | ||
self.mode = mode | ||
self.file_list = list() | ||
self.num_classes = 59 | ||
self.ignore_index = 255 | ||
|
||
if mode not in ['train', 'trainval', 'val']: | ||
raise ValueError( | ||
"`mode` should be one of ('train', 'trainval', 'val') in PascalContext dataset, but got {}." | ||
.format(mode)) | ||
|
||
if self.transforms is None: | ||
raise ValueError("`transforms` is necessary, but it is None.") | ||
if self.dataset_root is None: | ||
raise ValueError( | ||
"The dataset is not Found or the folder structure is nonconfoumance.") | ||
|
||
image_set_dir = os.path.join(self.dataset_root, 'ImageSets','Segmentation') | ||
|
||
if mode == 'train': | ||
file_path = os.path.join(image_set_dir, 'train_context.txt') | ||
elif mode == 'val': | ||
file_path = os.path.join(image_set_dir, 'val_context.txt') | ||
elif mode == 'trainval': | ||
file_path = os.path.join(image_set_dir, 'trainval_context.txt') | ||
if not os.path.exists(file_path): | ||
raise RuntimeError( | ||
"PASCAL-Context annotations are not ready, " | ||
"Please make sure voc_context.py has been properly run.") | ||
|
||
img_dir = os.path.join(self.dataset_root, 'JPEGImages') | ||
label_dir = os.path.join(self.dataset_root, 'Context') | ||
|
||
with open(file_path, 'r') as f: | ||
for line in f: | ||
line = line.strip() | ||
image_path = os.path.join(img_dir, ''.join([line, '.jpg'])) | ||
label_path = os.path.join(label_dir, ''.join([line, '.png'])) | ||
self.file_list.append([image_path, label_path]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.