diff --git a/fluid/PaddleCV/icnet/cityscape.py b/fluid/PaddleCV/icnet/cityscape.py index c5c08afcf3a3c85b9f43c9110e8a8dedc5900d5b..281658fa1e00bf38a9e7f0fa1a7ed2e9b7559539 100644 --- a/fluid/PaddleCV/icnet/cityscape.py +++ b/fluid/PaddleCV/icnet/cityscape.py @@ -155,6 +155,17 @@ class DataGenerater: else: return np.pad(image, ((0, pad_h), (0, pad_w)), 'constant') + def random_crop(self, im, out_shape, is_color=True): + h, w = im.shape[:2] + h_start = np.random.randint(0, h - out_shape[0] + 1) + w_start = np.random.randint(0, w - out_shape[1] + 1) + h_end, w_end = h_start + out_shape[0], w_start + out_shape[1] + if is_color: + im = im[h_start:h_end, w_start:w_end, :] + else: + im = im[h_start:h_end, w_start:w_end] + return im + def resize(self, image, label, out_size): """ Resize image and label by padding or cropping. @@ -166,8 +177,7 @@ class DataGenerater: combined = np.concatenate((image, label), axis=2) combined = self.padding_as( combined, out_size[0], out_size[1], is_color=True) - combined = dataset.image.random_crop( - combined, out_size[0], is_color=True) + combined = self.random_crop(combined, out_size, is_color=True) image = combined[:, :, 0:3] label = combined[:, :, 3:4] + ignore_label return image, label diff --git a/fluid/PaddleCV/icnet/icnet.py b/fluid/PaddleCV/icnet/icnet.py index d640621eb9def4bfb1411667ea68f5384fbd5489..3286ce74072f0fde2b215763d50156dcd152a99c 100644 --- a/fluid/PaddleCV/icnet/icnet.py +++ b/fluid/PaddleCV/icnet/icnet.py @@ -235,12 +235,12 @@ def proj_block(input, filter_num, padding=0, dilation=None, stride=1, def sub_net_4(input, input_shape): - tmp = interp(input, out_shape=np.ceil(input_shape // 32)) + tmp = interp(input, out_shape=(input_shape // 32)) tmp = dilation_convs(tmp) tmp = pyramis_pooling(tmp, input_shape) tmp = conv(tmp, 1, 1, 256, 1, 1, name="conv5_4_k1") tmp = bn(tmp, relu=True) - tmp = interp(tmp, input_shape // 16) + tmp = interp(tmp, out_shape=np.ceil(input_shape / 16)) return tmp