You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.0 KiB
60 lines
2.0 KiB
3 years ago
|
import sys
|
||
|
|
||
|
sys.path.append("/mnt/chulutao/PaddleRS")
|
||
|
|
||
|
import paddlers as pdrs
|
||
|
from paddlers import transforms as T
|
||
|
|
||
3 years ago
|
# 下载和解压多光谱地块分类数据集
|
||
|
dataset = 'https://paddleseg.bj.bcebos.com/dataset/remote_sensing_seg.zip'
|
||
|
pdrs.utils.download_and_decompress(dataset, path='./data')
|
||
3 years ago
|
|
||
|
# 定义训练和验证时的transforms
|
||
|
# API说明:https://github.com/PaddlePaddle/paddlers/blob/develop/docs/apis/transforms/transforms.md
|
||
3 years ago
|
channel = 10
|
||
3 years ago
|
train_transforms = T.Compose([
|
||
|
T.Resize(target_size=512),
|
||
|
T.RandomHorizontalFlip(),
|
||
|
T.Normalize(
|
||
3 years ago
|
mean=[0.5] * 10, std=[0.5] * 10),
|
||
3 years ago
|
])
|
||
|
|
||
|
eval_transforms = T.Compose([
|
||
|
T.Resize(target_size=512),
|
||
|
T.Normalize(
|
||
3 years ago
|
mean=[0.5] * 10, std=[0.5] * 10),
|
||
3 years ago
|
])
|
||
|
|
||
|
# 定义训练和验证所用的数据集
|
||
|
# API说明:https://github.com/PaddlePaddle/paddlers/blob/develop/docs/apis/datasets.md
|
||
|
train_dataset = pdrs.datasets.SegDataset(
|
||
3 years ago
|
data_dir='./data/remote_sensing_seg',
|
||
|
file_list='./data/remote_sensing_seg/train.txt',
|
||
|
label_list='./data/remote_sensing_seg/labels.txt',
|
||
3 years ago
|
transforms=train_transforms,
|
||
|
num_workers=0,
|
||
|
shuffle=True)
|
||
|
|
||
|
eval_dataset = pdrs.datasets.SegDataset(
|
||
3 years ago
|
data_dir='./data/remote_sensing_seg',
|
||
|
file_list='./data/remote_sensing_seg/val.txt',
|
||
|
label_list='./data/remote_sensing_seg/labels.txt',
|
||
3 years ago
|
transforms=eval_transforms,
|
||
|
num_workers=0,
|
||
|
shuffle=False)
|
||
|
|
||
|
# 初始化模型,并进行训练
|
||
|
# 可使用VisualDL查看训练指标,参考https://github.com/PaddlePaddle/paddlers/blob/develop/docs/visualdl.md
|
||
|
num_classes = len(train_dataset.labels)
|
||
3 years ago
|
model = pdrs.tasks.DeepLabV3P(input_channel=channel, num_classes=num_classes, backbone='ResNet50_vd')
|
||
3 years ago
|
|
||
|
# API说明:https://github.com/PaddlePaddle/paddlers/blob/develop/docs/apis/models/semantic_segmentation.md
|
||
|
# 各参数介绍与调整说明:https://github.com/PaddlePaddle/paddlers/blob/develop/docs/parameters.md
|
||
|
model.train(
|
||
|
num_epochs=10,
|
||
|
train_dataset=train_dataset,
|
||
|
train_batch_size=4,
|
||
|
eval_dataset=eval_dataset,
|
||
|
learning_rate=0.01,
|
||
|
save_dir='output/deeplabv3p_r50vd')
|