Place Arrange in transforms and Add ReloadMask

own
Bobholamovic 3 years ago
parent d5d9895950
commit d6daa3e38e
  1. 22
      paddlers/datasets/cd_dataset.py
  2. 22
      paddlers/datasets/seg_dataset.py
  3. 19
      paddlers/transforms/__init__.py
  4. 17
      paddlers/transforms/functions.py
  5. 81
      paddlers/transforms/operators.py
  6. 34
      tests/deploy/test_predictor.py
  7. 54
      tutorials/train/change_detection/bit.py
  8. 54
      tutorials/train/change_detection/cdnet.py
  9. 54
      tutorials/train/change_detection/dsamnet.py
  10. 54
      tutorials/train/change_detection/dsifn.py
  11. 54
      tutorials/train/change_detection/fc_ef.py
  12. 54
      tutorials/train/change_detection/fc_siam_conc.py
  13. 54
      tutorials/train/change_detection/fc_siam_diff.py
  14. 54
      tutorials/train/change_detection/snunet.py
  15. 54
      tutorials/train/change_detection/stanet.py
  16. 34
      tutorials/train/classification/condensenetv2_b_rs_mul.py
  17. 46
      tutorials/train/classification/hrnet.py
  18. 46
      tutorials/train/classification/mobilenetv3.py
  19. 46
      tutorials/train/classification/resnet50_vd.py
  20. 62
      tutorials/train/object_detection/faster_rcnn.py
  21. 62
      tutorials/train/object_detection/ppyolo.py
  22. 62
      tutorials/train/object_detection/ppyolotiny.py
  23. 62
      tutorials/train/object_detection/ppyolov2.py
  24. 62
      tutorials/train/object_detection/yolov3.py
  25. 46
      tutorials/train/semantic_segmentation/deeplabv3p.py
  26. 46
      tutorials/train/semantic_segmentation/unet.py

@ -18,7 +18,6 @@ import os.path as osp
from .base import BaseDataset
from paddlers.utils import logging, get_encoding, norm_path, is_pic
from paddlers.transforms import decode_seg_mask
class CDDataset(BaseDataset):
@ -36,7 +35,6 @@ class CDDataset(BaseDataset):
系统的实际CPU核数设置`num_workers`: 如果CPU核数的一半大于8`num_workers`为8否则为CPU核数的
一半
shuffle (bool): 是否需要对数据集中样本打乱顺序默认为False
apply_im_only (bool, optional): 是否绕过对标签的数据增强和预处理在模型验证和推理阶段一般指定此选项为True默认为False
with_seg_labels (bool, optional): 数据集中是否包含两个时相的语义分割标签默认为False
binarize_labels (bool, optional): 是否对数据集中的标签进行二值化操作默认为False
"""
@ -48,7 +46,6 @@ class CDDataset(BaseDataset):
transforms=None,
num_workers='auto',
shuffle=False,
apply_im_only=False,
with_seg_labels=False,
binarize_labels=False):
super(CDDataset, self).__init__(data_dir, label_list, transforms,
@ -61,7 +58,6 @@ class CDDataset(BaseDataset):
self.file_list = list()
self.labels = list()
self.with_seg_labels = with_seg_labels
self.apply_im_only = apply_im_only
if self.with_seg_labels:
num_items = 5 # RGB1, RGB2, CD, Seg1, Seg2
else:
@ -131,26 +127,8 @@ class CDDataset(BaseDataset):
def __getitem__(self, idx):
sample = copy.deepcopy(self.file_list[idx])
if self.apply_im_only:
has_mask, has_aux_masks = False, False
if 'mask' in sample:
has_mask = True
mask = decode_seg_mask(sample['mask'])
del sample['mask']
if 'aux_masks' in sample:
has_aux_masks = True
aux_masks = list(map(decode_seg_mask, sample['aux_masks']))
del sample['aux_masks']
sample = self.transforms.apply_transforms(sample)
if self.apply_im_only:
if has_mask:
sample['mask'] = mask
if has_aux_masks:
sample['aux_masks'] = aux_masks
if self.binarize_labels:
# Requires 'mask' to exist
sample['mask'] = self._binarize(sample['mask'])

@ -17,7 +17,6 @@ import copy
from .base import BaseDataset
from paddlers.utils import logging, get_encoding, norm_path, is_pic
from paddlers.transforms import decode_seg_mask
class SegDataset(BaseDataset):
@ -32,7 +31,6 @@ class SegDataset(BaseDataset):
系统的实际CPU核数设置`num_workers`: 如果CPU核数的一半大于8`num_workers`为8否则为CPU核数的
一半
shuffle (bool): 是否需要对数据集中样本打乱顺序默认为False
apply_im_only (bool, optional): 是否绕过对标签的数据增强和预处理在模型验证和推理阶段一般指定此选项为True默认为False
"""
def __init__(self,
@ -41,15 +39,13 @@ class SegDataset(BaseDataset):
label_list=None,
transforms=None,
num_workers='auto',
shuffle=False,
apply_im_only=False):
shuffle=False):
super(SegDataset, self).__init__(data_dir, label_list, transforms,
num_workers, shuffle)
# TODO batch padding
self.batch_transforms = None
self.file_list = list()
self.labels = list()
self.apply_im_only = apply_im_only
# TODO:非None时,让用户跳转数据集分析生成label_list
# 不要在此处分析label file
@ -86,21 +82,5 @@ class SegDataset(BaseDataset):
logging.info("{} samples in file {}".format(
len(self.file_list), file_list))
def __getitem__(self, idx):
sample = copy.deepcopy(self.file_list[idx])
if self.apply_im_only:
has_mask = False
if 'mask' in sample:
has_mask = True
mask = decode_seg_mask(sample['mask'])
del sample['mask']
sample = self.transforms.apply_transforms(sample)
if has_mask:
sample['mask'] = mask
outputs = self.transforms.arrange_outputs(sample)
else:
outputs = super().__getitem__(idx)
return outputs
def __len__(self):
return len(self.file_list)

@ -15,9 +15,6 @@
import copy
import os.path as osp
import numpy as np
from PIL import Image
from .operators import *
from .batch_operators import BatchRandomResize, BatchRandomResizeByShort, _BatchPad
from paddlers import transforms as T
@ -39,6 +36,9 @@ def decode_image(im_path,
Defaults to True.
decode_sar (bool, optional): If True, automatically interpret a two-channel geo image (e.g. geotiff images) as a
SAR image, set this argument to True. Defaults to True.
Returns:
np.ndarray: Decoded image.
"""
# Do a presence check. osp.exists() assumes `im_path` is a path-like object.
@ -55,19 +55,6 @@ def decode_image(im_path,
return sample['image']
def decode_seg_mask(mask_path):
"""
Decode a segmentation mask image.
Args:
mask_path (str): Path of the mask image to decode.
"""
mask = np.asarray(Image.open(mask_path))
mask = mask.astype('int64')
return mask
def build_transforms(transforms_info):
transforms = list()
for op_info in transforms_info:

@ -21,6 +21,7 @@ from shapely.geometry import Polygon, MultiPolygon, GeometryCollection
from sklearn.linear_model import LinearRegression
from skimage import exposure
from joblib import load
from PIL import Image
def normalize(im, mean, std, min_value=[0, 0, 0], max_value=[255, 255, 255]):
@ -623,3 +624,19 @@ def inv_pca(im, joblib_path):
r_im = pca.inverse_transform(n_im)
r_im = np.reshape(r_im, (H, W, -1))
return r_im
def decode_seg_mask(mask_path):
"""
Decode a segmentation mask image.
Args:
mask_path (str): Path of the mask image to decode.
Returns:
np.ndarray: Decoded mask image.
"""
mask = np.asarray(Image.open(mask_path))
mask = mask.astype('int64')
return mask

@ -30,39 +30,21 @@ from PIL import Image
from joblib import load
import paddlers
from .functions import normalize, horizontal_flip, permute, vertical_flip, center_crop, is_poly, \
horizontal_flip_poly, horizontal_flip_rle, vertical_flip_poly, vertical_flip_rle, crop_poly, \
crop_rle, expand_poly, expand_rle, resize_poly, resize_rle, dehaze, select_bands, \
to_intensity, to_uint8, img_flip, img_simple_rotate
from .functions import (
normalize, horizontal_flip, permute, vertical_flip, center_crop, is_poly,
horizontal_flip_poly, horizontal_flip_rle, vertical_flip_poly,
vertical_flip_rle, crop_poly, crop_rle, expand_poly, expand_rle,
resize_poly, resize_rle, dehaze, select_bands, to_intensity, to_uint8,
img_flip, img_simple_rotate, decode_seg_mask)
__all__ = [
"Compose",
"DecodeImg",
"Resize",
"RandomResize",
"ResizeByShort",
"RandomResizeByShort",
"ResizeByLong",
"RandomHorizontalFlip",
"RandomVerticalFlip",
"Normalize",
"CenterCrop",
"RandomCrop",
"RandomScaleAspect",
"RandomExpand",
"Pad",
"MixupImage",
"RandomDistort",
"RandomBlur",
"RandomSwap",
"Dehaze",
"ReduceDim",
"SelectBand",
"ArrangeSegmenter",
"ArrangeChangeDetector",
"ArrangeClassifier",
"ArrangeDetector",
"RandomFlipOrRotate",
"Compose", "DecodeImg", "Resize", "RandomResize", "ResizeByShort",
"RandomResizeByShort", "ResizeByLong", "RandomHorizontalFlip",
"RandomVerticalFlip", "Normalize", "CenterCrop", "RandomCrop",
"RandomScaleAspect", "RandomExpand", "Pad", "MixupImage", "RandomDistort",
"RandomBlur", "RandomSwap", "Dehaze", "ReduceDim", "SelectBand",
"ArrangeSegmenter", "ArrangeChangeDetector", "ArrangeClassifier",
"ArrangeDetector", "RandomFlipOrRotate", "ReloadMask"
]
interp_dict = {
@ -80,16 +62,15 @@ class Compose(object):
All input images should be in Height-Width-Channel ([H, W, C]) format.
Args:
transforms (list[paddlers.transforms.Transform]): List of data preprocess or augmentation operators.
arrange (list[paddlers.transforms.Arrange]|None, optional): If not None, the Arrange operator will be used to
arrange the outputs of `transforms`. Defaults to None.
transforms (list[paddlers.transforms.Transform]): List of data preprocess or
augmentation operators.
Raises:
TypeError: Invalid type of transforms.
ValueError: Invalid length of transforms.
"""
def __init__(self, transforms, arrange=None):
def __init__(self, transforms):
super(Compose, self).__init__()
if not isinstance(transforms, list):
raise TypeError(
@ -99,12 +80,14 @@ class Compose(object):
raise ValueError(
"Length of transforms must not be less than 1, but received is {}."
.format(len(transforms)))
transforms = copy.deepcopy(transforms)
self.arrange = self._pick_arrange(transforms)
self.transforms = transforms
self.arrange = arrange
def __call__(self, sample):
"""
This is equivalent to sequentially calling compose_obj.apply_transforms() and compose_obj.arrange_outputs().
This is equivalent to sequentially calling compose_obj.apply_transforms()
and compose_obj.arrange_outputs().
"""
sample = self.apply_transforms(sample)
@ -126,6 +109,17 @@ class Compose(object):
sample = self.arrange(sample)
return sample
def _pick_arrange(self, transforms):
arrange = None
for idx, op in enumerate(transforms):
if isinstance(op, Arrange):
if idx != len(transforms) - 1:
raise ValueError(
"Arrange operator must be placed at the end of the list."
)
arrange = transforms.pop(idx)
return arrange
class Transform(object):
"""
@ -270,7 +264,9 @@ class DecodeImg(Transform):
Returns:
dict: Decoded sample.
"""
if 'image' in sample:
sample['image_ori'] = copy.deepcopy(sample['image'])
sample['image'] = self.apply_im(sample['image'])
if 'image2' in sample:
sample['image2'] = self.apply_im(sample['image2'])
@ -280,6 +276,7 @@ class DecodeImg(Transform):
sample['image'] = self.apply_im(sample['image_t1'])
sample['image2'] = self.apply_im(sample['image_t2'])
if 'mask' in sample:
sample['mask_ori'] = copy.deepcopy(sample['mask'])
sample['mask'] = self.apply_mask(sample['mask'])
im_height, im_width, _ = sample['image'].shape
se_height, se_width = sample['mask'].shape
@ -287,6 +284,7 @@ class DecodeImg(Transform):
raise ValueError(
"The height or width of the image is not same as the mask.")
if 'aux_masks' in sample:
sample['aux_masks_ori'] = copy.deepcopy(sample['aux_masks_ori'])
sample['aux_masks'] = list(
map(self.apply_mask, sample['aux_masks']))
# TODO: check the shape of auxiliary masks
@ -1759,6 +1757,15 @@ class RandomSwap(Transform):
return sample
class ReloadMask(Transform):
def apply(self, sample):
sample['mask'] = decode_seg_mask(sample['mask_ori'])
if 'aux_masks' in sample:
sample['aux_masks'] = list(
map(decode_seg_mask, sample['aux_masks_ori']))
return sample
class Arrange(Transform):
def __init__(self, mode):
super().__init__()

@ -120,12 +120,10 @@ class TestCDPredictor(TestPredictor):
t2_path = "data/ssmt/optical_t2.bmp"
single_input = (t1_path, t2_path)
num_inputs = 2
transforms = pdrs.transforms.Compose(
[
pdrs.transforms.DecodeImg(),
pdrs.transforms.Normalize(),
],
arrange=pdrs.transforms.ArrangeChangeDetector('test'))
transforms = pdrs.transforms.Compose([
pdrs.transforms.DecodeImg(), pdrs.transforms.Normalize(),
pdrs.transforms.ArrangeChangeDetector('test')
])
# Expected failure
with self.assertRaises(ValueError):
@ -189,9 +187,10 @@ class TestClasPredictor(TestPredictor):
def check_predictor(self, predictor, trainer):
single_input = "data/ssmt/optical_t1.bmp"
num_inputs = 2
transforms = pdrs.transforms.Compose(
[pdrs.transforms.DecodeImg(), pdrs.transforms.Normalize()],
arrange=pdrs.transforms.ArrangeClassifier('test'))
transforms = pdrs.transforms.Compose([
pdrs.transforms.DecodeImg(), pdrs.transforms.Normalize(),
pdrs.transforms.ArrangeClassifier('test')
])
labels = list(range(2))
trainer.labels = labels
predictor._model.labels = labels
@ -256,9 +255,10 @@ class TestDetPredictor(TestPredictor):
# given that the network is (partially?) randomly initialized.
single_input = "data/ssmt/optical_t1.bmp"
num_inputs = 2
transforms = pdrs.transforms.Compose(
[pdrs.transforms.DecodeImg(), pdrs.transforms.Normalize()],
arrange=pdrs.transforms.ArrangeDetector('test'))
transforms = pdrs.transforms.Compose([
pdrs.transforms.DecodeImg(), pdrs.transforms.Normalize(),
pdrs.transforms.ArrangeDetector('test')
])
labels = list(range(80))
trainer.labels = labels
predictor._model.labels = labels
@ -312,12 +312,10 @@ class TestSegPredictor(TestPredictor):
def check_predictor(self, predictor, trainer):
single_input = "data/ssmt/optical_t1.bmp"
num_inputs = 2
transforms = pdrs.transforms.Compose(
[
pdrs.transforms.DecodeImg(),
pdrs.transforms.Normalize(),
],
arrange=pdrs.transforms.ArrangeSegmenter('test'))
transforms = pdrs.transforms.Compose([
pdrs.transforms.DecodeImg(), pdrs.transforms.Normalize(),
pdrs.transforms.ArrangeSegmenter('test')
])
# Single input (file path)
input_ = single_input

@ -22,34 +22,33 @@ pdrs.utils.download_and_decompress(airchange_dataset, path=DATA_DIR)
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeChangeDetector('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ReloadMask(),
T.ArrangeChangeDetector('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.CDDataset(
@ -69,7 +68,6 @@ eval_dataset = pdrs.datasets.CDDataset(
transforms=eval_transforms,
num_workers=0,
shuffle=False,
apply_im_only=True,
with_seg_labels=False,
binarize_labels=True)

@ -22,34 +22,33 @@ pdrs.utils.download_and_decompress(airchange_dataset, path=DATA_DIR)
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeChangeDetector('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ReloadMask(),
T.ArrangeChangeDetector('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.CDDataset(
@ -69,7 +68,6 @@ eval_dataset = pdrs.datasets.CDDataset(
transforms=eval_transforms,
num_workers=0,
shuffle=False,
apply_im_only=True,
with_seg_labels=False,
binarize_labels=True)

@ -22,34 +22,33 @@ pdrs.utils.download_and_decompress(airchange_dataset, path=DATA_DIR)
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeChangeDetector('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ReloadMask(),
T.ArrangeChangeDetector('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.CDDataset(
@ -69,7 +68,6 @@ eval_dataset = pdrs.datasets.CDDataset(
transforms=eval_transforms,
num_workers=0,
shuffle=False,
apply_im_only=True,
with_seg_labels=False,
binarize_labels=True)

@ -22,34 +22,33 @@ pdrs.utils.download_and_decompress(airchange_dataset, path=DATA_DIR)
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeChangeDetector('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ReloadMask(),
T.ArrangeChangeDetector('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.CDDataset(
@ -69,7 +68,6 @@ eval_dataset = pdrs.datasets.CDDataset(
transforms=eval_transforms,
num_workers=0,
shuffle=False,
apply_im_only=True,
with_seg_labels=False,
binarize_labels=True)

@ -22,34 +22,33 @@ pdrs.utils.download_and_decompress(airchange_dataset, path=DATA_DIR)
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeChangeDetector('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ReloadMask(),
T.ArrangeChangeDetector('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.CDDataset(
@ -69,7 +68,6 @@ eval_dataset = pdrs.datasets.CDDataset(
transforms=eval_transforms,
num_workers=0,
shuffle=False,
apply_im_only=True,
with_seg_labels=False,
binarize_labels=True)

@ -22,34 +22,33 @@ pdrs.utils.download_and_decompress(airchange_dataset, path=DATA_DIR)
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeChangeDetector('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ReloadMask(),
T.ArrangeChangeDetector('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.CDDataset(
@ -69,7 +68,6 @@ eval_dataset = pdrs.datasets.CDDataset(
transforms=eval_transforms,
num_workers=0,
shuffle=False,
apply_im_only=True,
with_seg_labels=False,
binarize_labels=True)

@ -22,34 +22,33 @@ pdrs.utils.download_and_decompress(airchange_dataset, path=DATA_DIR)
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeChangeDetector('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ReloadMask(),
T.ArrangeChangeDetector('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.CDDataset(
@ -69,7 +68,6 @@ eval_dataset = pdrs.datasets.CDDataset(
transforms=eval_transforms,
num_workers=0,
shuffle=False,
apply_im_only=True,
with_seg_labels=False,
binarize_labels=True)

@ -22,34 +22,33 @@ pdrs.utils.download_and_decompress(airchange_dataset, path=DATA_DIR)
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeChangeDetector('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ReloadMask(),
T.ArrangeChangeDetector('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.CDDataset(
@ -69,7 +68,6 @@ eval_dataset = pdrs.datasets.CDDataset(
transforms=eval_transforms,
num_workers=0,
shuffle=False,
apply_im_only=True,
with_seg_labels=False,
binarize_labels=True)

@ -22,34 +22,33 @@ pdrs.utils.download_and_decompress(airchange_dataset, path=DATA_DIR)
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 随机裁剪
T.RandomCrop(
# 裁剪区域将被缩放到256x256
crop_size=256,
# 裁剪区域的横纵比在0.5-2之间变动
aspect_ratio=[0.5, 2.0],
# 裁剪区域相对原始影像长宽比例在一定范围内变动,最小不低于原始长宽的1/5
scaling=[0.2, 1.0]),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeChangeDetector('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeChangeDetector('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ReloadMask(),
T.ArrangeChangeDetector('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.CDDataset(
@ -69,7 +68,6 @@ eval_dataset = pdrs.datasets.CDDataset(
transforms=eval_transforms,
num_workers=0,
shuffle=False,
apply_im_only=True,
with_seg_labels=False,
binarize_labels=True)

@ -2,25 +2,23 @@ import paddlers as pdrs
from paddlers import transforms as T
# 定义训练和验证时的transforms
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
T.SelectBand([5, 10, 15, 20, 25]), # for tet
T.Resize(target_size=224),
T.RandomHorizontalFlip(),
T.Normalize(
mean=[0.5, 0.5, 0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5, 0.5, 0.5])
],
arrange=T.ArrangeClassifier('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
T.SelectBand([5, 10, 15, 20, 25]), # for tet
T.Resize(target_size=224),
T.RandomHorizontalFlip(),
T.Normalize(
mean=[0.5, 0.5, 0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5, 0.5, 0.5]),
T.ArrangeClassifier('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(), T.SelectBand([5, 10, 15, 20, 25]),
T.Resize(target_size=224), T.Normalize(
mean=[0.5, 0.5, 0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5, 0.5, 0.5])
],
arrange=T.ArrangeClassifier('eval'))
eval_transforms = T.Compose([
T.DecodeImg(), T.SelectBand([5, 10, 15, 20, 25]), T.Resize(target_size=224),
T.Normalize(
mean=[0.5, 0.5, 0.5, 0.5, 0.5],
std=[0.5, 0.5, 0.5, 0.5, 0.5]), T.ArrangeClassifier('eval')
])
# 定义训练和验证所用的数据集
train_dataset = pdrs.datasets.ClasDataset(

@ -26,31 +26,29 @@ pdrs.utils.download_and_decompress(ucmerced_dataset, path=DOWNLOAD_DIR)
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 将影像缩放到256x256大小
T.Resize(target_size=256),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 以50%的概率实施随机垂直翻转
T.RandomVerticalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeClassifier('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 将影像缩放到256x256大小
T.Resize(target_size=256),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 以50%的概率实施随机垂直翻转
T.RandomVerticalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeClassifier('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
T.Resize(target_size=256),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeClassifier('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
T.Resize(target_size=256),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeClassifier('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.ClasDataset(

@ -26,31 +26,29 @@ pdrs.utils.download_and_decompress(ucmerced_dataset, path=DOWNLOAD_DIR)
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 将影像缩放到256x256大小
T.Resize(target_size=256),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 以50%的概率实施随机垂直翻转
T.RandomVerticalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeClassifier('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 将影像缩放到256x256大小
T.Resize(target_size=256),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 以50%的概率实施随机垂直翻转
T.RandomVerticalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeClassifier('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
T.Resize(target_size=256),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeClassifier('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
T.Resize(target_size=256),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeClassifier('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.ClasDataset(

@ -26,31 +26,29 @@ pdrs.utils.download_and_decompress(ucmerced_dataset, path=DOWNLOAD_DIR)
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 将影像缩放到256x256大小
T.Resize(target_size=256),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 以50%的概率实施随机垂直翻转
T.RandomVerticalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeClassifier('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 将影像缩放到256x256大小
T.Resize(target_size=256),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 以50%的概率实施随机垂直翻转
T.RandomVerticalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeClassifier('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
T.Resize(target_size=256),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
],
arrange=T.ArrangeClassifier('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
T.Resize(target_size=256),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeClassifier('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.ClasDataset(

@ -29,39 +29,37 @@ if not os.path.exists(DATA_DIR):
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 对输入影像施加随机色彩扰动
T.RandomDistort(),
# 在影像边界进行随机padding
T.RandomExpand(),
# 随机裁剪,裁块大小在一定范围内变动
T.RandomCrop(),
# 随机水平翻转
T.RandomHorizontalFlip(),
# 对batch进行随机缩放,随机选择插值方式
T.BatchRandomResize(
target_sizes=[320, 352, 384, 416, 448, 480, 512, 544, 576, 608],
interp='RANDOM'),
# 影像归一化
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
],
arrange=T.ArrangeDetector('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 对输入影像施加随机色彩扰动
T.RandomDistort(),
# 在影像边界进行随机padding
T.RandomExpand(),
# 随机裁剪,裁块大小在一定范围内变动
T.RandomCrop(),
# 随机水平翻转
T.RandomHorizontalFlip(),
# 对batch进行随机缩放,随机选择插值方式
T.BatchRandomResize(
target_sizes=[320, 352, 384, 416, 448, 480, 512, 544, 576, 608],
interp='RANDOM'),
# 影像归一化
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
T.ArrangeDetector('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
# 使用双三次插值将输入影像缩放到固定大小
T.Resize(
target_size=608, interp='CUBIC'),
# 验证阶段与训练阶段的归一化方式必须相同
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
],
arrange=T.ArrangeDetector('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
# 使用双三次插值将输入影像缩放到固定大小
T.Resize(
target_size=608, interp='CUBIC'),
# 验证阶段与训练阶段的归一化方式必须相同
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
T.ArrangeDetector('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.VOCDetection(

@ -30,39 +30,37 @@ if not os.path.exists(DATA_DIR):
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 对输入影像施加随机色彩扰动
T.RandomDistort(),
# 在影像边界进行随机padding
T.RandomExpand(),
# 随机裁剪,裁块大小在一定范围内变动
T.RandomCrop(),
# 随机水平翻转
T.RandomHorizontalFlip(),
# 对batch进行随机缩放,随机选择插值方式
T.BatchRandomResize(
target_sizes=[320, 352, 384, 416, 448, 480, 512, 544, 576, 608],
interp='RANDOM'),
# 影像归一化
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
],
arrange=T.ArrangeDetector('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 对输入影像施加随机色彩扰动
T.RandomDistort(),
# 在影像边界进行随机padding
T.RandomExpand(),
# 随机裁剪,裁块大小在一定范围内变动
T.RandomCrop(),
# 随机水平翻转
T.RandomHorizontalFlip(),
# 对batch进行随机缩放,随机选择插值方式
T.BatchRandomResize(
target_sizes=[320, 352, 384, 416, 448, 480, 512, 544, 576, 608],
interp='RANDOM'),
# 影像归一化
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
T.ArrangeDetector('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
# 使用双三次插值将输入影像缩放到固定大小
T.Resize(
target_size=608, interp='CUBIC'),
# 验证阶段与训练阶段的归一化方式必须相同
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
],
arrange=T.ArrangeDetector('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
# 使用双三次插值将输入影像缩放到固定大小
T.Resize(
target_size=608, interp='CUBIC'),
# 验证阶段与训练阶段的归一化方式必须相同
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
T.ArrangeDetector('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.VOCDetection(

@ -30,39 +30,37 @@ if not os.path.exists(DATA_DIR):
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 对输入影像施加随机色彩扰动
T.RandomDistort(),
# 在影像边界进行随机padding
T.RandomExpand(),
# 随机裁剪,裁块大小在一定范围内变动
T.RandomCrop(),
# 随机水平翻转
T.RandomHorizontalFlip(),
# 对batch进行随机缩放,随机选择插值方式
T.BatchRandomResize(
target_sizes=[320, 352, 384, 416, 448, 480, 512, 544, 576, 608],
interp='RANDOM'),
# 影像归一化
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
],
arrange=T.ArrangeDetector('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 对输入影像施加随机色彩扰动
T.RandomDistort(),
# 在影像边界进行随机padding
T.RandomExpand(),
# 随机裁剪,裁块大小在一定范围内变动
T.RandomCrop(),
# 随机水平翻转
T.RandomHorizontalFlip(),
# 对batch进行随机缩放,随机选择插值方式
T.BatchRandomResize(
target_sizes=[320, 352, 384, 416, 448, 480, 512, 544, 576, 608],
interp='RANDOM'),
# 影像归一化
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
T.ArrangeDetector('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
# 使用双三次插值将输入影像缩放到固定大小
T.Resize(
target_size=608, interp='CUBIC'),
# 验证阶段与训练阶段的归一化方式必须相同
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
],
arrange=T.ArrangeDetector('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
# 使用双三次插值将输入影像缩放到固定大小
T.Resize(
target_size=608, interp='CUBIC'),
# 验证阶段与训练阶段的归一化方式必须相同
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
T.ArrangeDetector('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.VOCDetection(

@ -30,39 +30,37 @@ if not os.path.exists(DATA_DIR):
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 对输入影像施加随机色彩扰动
T.RandomDistort(),
# 在影像边界进行随机padding
T.RandomExpand(),
# 随机裁剪,裁块大小在一定范围内变动
T.RandomCrop(),
# 随机水平翻转
T.RandomHorizontalFlip(),
# 对batch进行随机缩放,随机选择插值方式
T.BatchRandomResize(
target_sizes=[320, 352, 384, 416, 448, 480, 512, 544, 576, 608],
interp='RANDOM'),
# 影像归一化
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
],
arrange=T.ArrangeDetector('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 对输入影像施加随机色彩扰动
T.RandomDistort(),
# 在影像边界进行随机padding
T.RandomExpand(),
# 随机裁剪,裁块大小在一定范围内变动
T.RandomCrop(),
# 随机水平翻转
T.RandomHorizontalFlip(),
# 对batch进行随机缩放,随机选择插值方式
T.BatchRandomResize(
target_sizes=[320, 352, 384, 416, 448, 480, 512, 544, 576, 608],
interp='RANDOM'),
# 影像归一化
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
T.ArrangeDetector('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
# 使用双三次插值将输入影像缩放到固定大小
T.Resize(
target_size=608, interp='CUBIC'),
# 验证阶段与训练阶段的归一化方式必须相同
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
],
arrange=T.ArrangeDetector('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
# 使用双三次插值将输入影像缩放到固定大小
T.Resize(
target_size=608, interp='CUBIC'),
# 验证阶段与训练阶段的归一化方式必须相同
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
T.ArrangeDetector('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.VOCDetection(

@ -30,39 +30,37 @@ if not os.path.exists(DATA_DIR):
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 对输入影像施加随机色彩扰动
T.RandomDistort(),
# 在影像边界进行随机padding
T.RandomExpand(),
# 随机裁剪,裁块大小在一定范围内变动
T.RandomCrop(),
# 随机水平翻转
T.RandomHorizontalFlip(),
# 对batch进行随机缩放,随机选择插值方式
T.BatchRandomResize(
target_sizes=[320, 352, 384, 416, 448, 480, 512, 544, 576, 608],
interp='RANDOM'),
# 影像归一化
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
],
arrange=T.ArrangeDetector('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 对输入影像施加随机色彩扰动
T.RandomDistort(),
# 在影像边界进行随机padding
T.RandomExpand(),
# 随机裁剪,裁块大小在一定范围内变动
T.RandomCrop(),
# 随机水平翻转
T.RandomHorizontalFlip(),
# 对batch进行随机缩放,随机选择插值方式
T.BatchRandomResize(
target_sizes=[320, 352, 384, 416, 448, 480, 512, 544, 576, 608],
interp='RANDOM'),
# 影像归一化
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
T.ArrangeDetector('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
# 使用双三次插值将输入影像缩放到固定大小
T.Resize(
target_size=608, interp='CUBIC'),
# 验证阶段与训练阶段的归一化方式必须相同
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
],
arrange=T.ArrangeDetector('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
# 使用双三次插值将输入影像缩放到固定大小
T.Resize(
target_size=608, interp='CUBIC'),
# 验证阶段与训练阶段的归一化方式必须相同
T.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
T.ArrangeDetector('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.VOCDetection(

@ -29,29 +29,28 @@ pdrs.utils.download_and_decompress(seg_dataset, path=DOWNLOAD_DIR)
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 将影像缩放到512x512大小
T.Resize(target_size=512),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5] * NUM_BANDS, std=[0.5] * NUM_BANDS)
],
arrange=T.ArrangeSegmenter('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 将影像缩放到512x512大小
T.Resize(target_size=512),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5] * NUM_BANDS, std=[0.5] * NUM_BANDS),
T.ArrangeSegmenter('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
T.Resize(target_size=512),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5] * NUM_BANDS, std=[0.5] * NUM_BANDS)
],
arrange=T.ArrangeSegmenter('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
T.Resize(target_size=512),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5] * NUM_BANDS, std=[0.5] * NUM_BANDS),
T.ReloadMask(),
T.ArrangeSegmenter('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.SegDataset(
@ -68,8 +67,7 @@ eval_dataset = pdrs.datasets.SegDataset(
label_list=LABEL_LIST_PATH,
transforms=eval_transforms,
num_workers=0,
shuffle=False,
apply_im_only=True)
shuffle=False)
# 构建DeepLab V3+模型,使用ResNet-50作为backbone
# 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md

@ -29,29 +29,28 @@ pdrs.utils.download_and_decompress(seg_dataset, path=DOWNLOAD_DIR)
# 定义训练和验证时使用的数据变换(数据增强、预处理等)
# 使用Compose组合多种变换方式。Compose中包含的变换将按顺序串行执行
# API说明:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/transforms.md
train_transforms = T.Compose(
[
# 读取影像
T.DecodeImg(),
# 将影像缩放到512x512大小
T.Resize(target_size=512),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5] * NUM_BANDS, std=[0.5] * NUM_BANDS)
],
arrange=T.ArrangeSegmenter('train'))
train_transforms = T.Compose([
# 读取影像
T.DecodeImg(),
# 将影像缩放到512x512大小
T.Resize(target_size=512),
# 以50%的概率实施随机水平翻转
T.RandomHorizontalFlip(prob=0.5),
# 将数据归一化到[-1,1]
T.Normalize(
mean=[0.5] * NUM_BANDS, std=[0.5] * NUM_BANDS),
T.ArrangeSegmenter('train')
])
eval_transforms = T.Compose(
[
T.DecodeImg(),
T.Resize(target_size=512),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5] * NUM_BANDS, std=[0.5] * NUM_BANDS)
],
arrange=T.ArrangeSegmenter('eval'))
eval_transforms = T.Compose([
T.DecodeImg(),
T.Resize(target_size=512),
# 验证阶段与训练阶段的数据归一化方式必须相同
T.Normalize(
mean=[0.5] * NUM_BANDS, std=[0.5] * NUM_BANDS),
T.ReloadMask(),
T.ArrangeSegmenter('eval')
])
# 分别构建训练和验证所用的数据集
train_dataset = pdrs.datasets.SegDataset(
@ -68,8 +67,7 @@ eval_dataset = pdrs.datasets.SegDataset(
label_list=LABEL_LIST_PATH,
transforms=eval_transforms,
num_workers=0,
shuffle=False,
apply_im_only=True)
shuffle=False)
# 构建UNet模型
# 目前已支持的模型请参考:https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/apis/model_zoo.md

Loading…
Cancel
Save