-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使用PaddleRS中的变化检测模型报错 #204
Comments
看起来是一个尺寸不匹配的问题,建议在训练阶段加入随机裁剪,在验证阶段加入resize,以保证输入图像具有固定的尺寸。受到U-Net型结构上下采样时的舍入误差影响,输入网络的图像长、宽最好是4或者8的整数倍(与具体的模型有关)。 |
请问现在的输入尺寸是多少呀? |
224*224 |
请问是通过数据预处理算子实现的吗?还是预先裁剪好图片呀?如果是前者的话,请贴一下代码~ |
train_transforms = T.Compose([ |
有点儿奇怪……建议在 |
fccdn模型是这样的 |
我阅读了一下源码,FCCDN这个模型可能需要输入尺寸是64的整数倍(因为encoder下采样16倍,而 |
好的,可以运行了!非常感谢您的耐心回答! |
Thanks for your bug report. To help us better solve the issue, please provide the following information:
log/worklog.0
by default)欢迎您反馈PaddleRS使用问题。辛苦您提供以下信息,以方便我们快速定位和解决问题:
导入PaddleRS库
import paddlers as pdrs
import paddlers.transforms as T
import os.path as osp
import paddle
train_transforms = T.Compose([
# 读取数据
T.DecodeImg(),
# 以50%的概率实施随机水平翻转
#T.RandomHorizontalFlip(prob=0.2),
# 以50%的概率实施随机垂直翻转
#T.RandomVerticalFlip(prob=0.3),
# 数据归一化到[-1,1]
T.Normalize(
mean=[0.5, 0.5, 0.5],
std=[0.5, 0.5, 0.5]
),
T.RandomFlipOrRotate(
probs = [0.1, 0.1], # p=0.3 to flip the image,p=0.2 to rotate the image,p=0.5 to keep the image unchanged.
probsf = [0.1, 0.1, 0, 0, 0], # p=0.3 and p=0.25 to perform horizontal and vertical flipping; probility of no-flipping is 0.45.
probsr = [0, 0.2, 0]), # p=0.65 to rotate the image by 180°; probility of no-rotation is 0.35.
T.ReloadMask(),
# 挑选训练过程中需要用到的数据,并按照指定顺序排列
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]
),
T.ReloadMask(),
# 挑选验证过程中需要用到的数据,并按照指定顺序排列
T.ArrangeChangeDetector('eval')
])
处理后数据集所在目录
DATA_DIR = "/home/aistudio/work/Landslide_CD/"
train_dataset = pdrs.datasets.CDDataset(
data_dir=DATA_DIR,
file_list=osp.join(DATA_DIR, 'train.txt'),
transforms=train_transforms,
label_list=None,
# 使用4个辅助进程加载数据
num_workers=4,
shuffle=True,
# 将取值为{0,255}的标签自动归一化到{0,1}
binarize_labels=True
)
val_dataset = pdrs.datasets.CDDataset(
data_dir=DATA_DIR,
file_list=osp.join(DATA_DIR, 'val.txt'),
transforms=eval_transforms,
label_list=None,
num_workers=0,
shuffle=False,
binarize_labels=True
)
#模型
model = pdrs.tasks.cd.FCCDN()
#学习率
lr_scheduler = paddle.optimizer.lr.StepDecay(
0.001,
step_size=5000,
# 学习率衰减系数,这里指定每次减半
gamma=0.5
)
#优化器
optimizer = paddle.optimizer.Lamb(
learning_rate=lr_scheduler,
parameters=model.net.parameters()
)
执行模型训练
model.train(
num_epochs=50,
train_dataset=train_dataset,
train_batch_size=20,
eval_dataset=val_dataset,
optimizer=optimizer,
save_interval_epochs=1,
# 每多少次迭代记录一次日志
log_interval_steps=10,
save_dir='/home/aistudio/work/output/fccdn',
#pretrain_weights='/home/aistudio/work/output/cdnet/best_model/model.pdparams',
# 是否使用early stopping策略,当精度不再改善时提前终止训练
early_stop=True,
# 是否启用VisualDL日志功能
use_vdl=True,
# 指定从某个检查点继续训练
resume_checkpoint=None
)
ValueError Traceback (most recent call last)
/tmp/ipykernel_64988/2465525996.py in
93 use_vdl=True,
94 # 指定从某个检查点继续训练
---> 95 resume_checkpoint=None
96 )
~/work/PaddleRS/paddlers/tasks/change_detector.py in train(self, num_epochs, train_dataset, train_batch_size, eval_dataset, optimizer, save_interval_epochs, log_interval_steps, save_dir, pretrain_weights, learning_rate, lr_decay_power, early_stop, early_stop_patience, use_vdl, resume_checkpoint)
333 early_stop=early_stop,
334 early_stop_patience=early_stop_patience,
--> 335 use_vdl=use_vdl)
336
337 def quant_aware_train(self,
~/work/PaddleRS/paddlers/tasks/base.py in train_loop(self, num_epochs, train_dataset, train_batch_size, eval_dataset, save_interval_epochs, log_interval_steps, save_dir, ema, early_stop, early_stop_patience, use_vdl)
372 outputs = self.train_step(step, data, ddp_net)
373 else:
--> 374 outputs = self.train_step(step, data, self.net)
375
376 scheduler_step(self.optimizer, outputs['loss'])
~/work/PaddleRS/paddlers/tasks/base.py in train_step(self, step, data, net)
663
664 def train_step(self, step, data, net):
--> 665 outputs = self.run(net, data, mode='train')
666
667 loss = outputs['loss']
~/work/PaddleRS/paddlers/tasks/change_detector.py in run(self, net, inputs, mode)
113
114 def run(self, net, inputs, mode):
--> 115 net_out = net(inputs[0], inputs[1])
116 logit = net_out[0]
117 outputs = OrderedDict()
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py in call(self, *inputs, **kwargs)
928 return self.forward(*inputs, **kwargs)
929 else:
--> 930 return self._dygraph_call_func(*inputs, **kwargs)
931
932 def forward(self, *inputs, **kwargs):
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py in _dygraph_call_func(self, *inputs, **kwargs)
913 outputs = self.forward(*inputs, **kwargs)
914 else:
--> 915 outputs = self.forward(*inputs, **kwargs)
916
917 for forward_post_hook in self._forward_post_hooks.values():
~/work/PaddleRS/paddlers/rs_models/cd/fccdn.py in forward(self, t1, t2)
453 y2 = self.block4(e3_2)
454
--> 455 y1 = self.center(y1)
456 y2 = self.center(y2)
457 c = self.df4(y1, y2)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py in call(self, *inputs, **kwargs)
928 return self.forward(*inputs, **kwargs)
929 else:
--> 930 return self._dygraph_call_func(*inputs, **kwargs)
931
932 def forward(self, *inputs, **kwargs):
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py in _dygraph_call_func(self, *inputs, **kwargs)
913 outputs = self.forward(*inputs, **kwargs)
914 else:
--> 915 outputs = self.forward(*inputs, **kwargs)
916
917 for forward_post_hook in self._forward_post_hooks.values():
~/work/PaddleRS/paddlers/rs_models/cd/fccdn.py in forward(self, x)
143 nl = self.nl3(d3)
144 d3 = self.upsample_x2(paddle.multiply(d3, nl)) ##2C,H/2,W/2
--> 145 d2 = self.conv_d2(e2 + d3) # C,H/2,W/2
146 nl = self.nl2(d2)
147 d2 = self.upsample_x2(paddle.multiply(d2, nl)) # C,H,W
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/math_op_patch.py in impl(self, other_var)
297 else:
298 math_op = getattr(_C_ops, op_type)
--> 299 return math_op(self, other_var, 'axis', axis)
300
301 comment = OpProtoHolder.instance().get_op_proto(op_type).comment
ValueError: (InvalidArgument) Broadcast dimension mismatch. Operands could not be broadcast together with the shape of X = [20, 128, 7, 7] and the shape of Y = [20, 128, 6, 6]. Received [7] in X is not equal to [6] in Y at i:2.
[Hint: Expected x_dims_array[i] == y_dims_array[i] || x_dims_array[i] <= 1 || y_dims_array[i] <= 1 == true, but received x_dims_array[i] == y_dims_array[i] || x_dims_array[i] <= 1 || y_dims_array[i] <= 1:0 != true:1.] (at /paddle/paddle/phi/kernels/funcs/common_shape.h:84)
[operator < elementwise_add > error]
9. 问题复现步骤:使用官方提供的训练脚本
11. 其他内容: 使用changestar、FCCDN、DSIFN模型均出现类似问题,报错信息几乎一致
The text was updated successfully, but these errors were encountered: