最近研究立体匹配,看了很多论文,发现很多输入图片都进行了随机的crop裁剪,
把图片裁剪为256x512后再进行训练。 这样可以增加数据集和减少训练时间。
但是测试的时候或者验证的时候就用原图片大小,或者一个新的图片大小。
请问这样不会再全连接层的时候因为参数数量不一样而出问题吗?
求大神解答一下,下面贴一下我看到的代码
if self.training:
w, h = left_img.size
th, tw = 256, 512
x1 = random.randint(0, w - tw)
y1 = random.randint(0, h - th)
left_img = left_img.crop((x1, y1, x1 + tw, y1 + th))
right_img = right_img.crop((x1, y1, x1 + tw, y1 + th))
dataL = np.array(dataL, dtype=np.float32) / 256
dataL = dataL[y1:y1 + th, x1:x1 + tw]
processed = preprocess.get_transform(augment=False)
left_img = processed(left_img)
right_img = processed(right_img)
return left_img, right_img, dataL
else:
w, h = left_img.size
left_img = left_img.crop((w - 1232, h - 368, w, h))
right_img = right_img.crop((w - 1232, h - 368, w, h))
w1, h1 = left_img.size
dataL = dataL.crop((w - 1232, h - 368, w, h))
dataL = np.ascontiguousarray(dataL, dtype=np.float32) / 256
processed = preprocess.get_transform(augment=False)
left_img = processed(left_img)
right_img = processed(right_img)
return left_img, right_img, dataL
这里的preprocess是进行归一化和标准化
transforms.ToTensor(),
transforms.Normalize(**normalize),