提交 e287034d 编写于 作者: D dangqingqing

minus mean in flowers dataset.

上级 0c70f34c
......@@ -61,7 +61,8 @@ def default_mapper(is_train, sample):
'''
img, label = sample
img = load_image_bytes(img)
img = simple_transform(img, 256, 224, is_train)
img = simple_transform(
img, 256, 224, is_train, mean=[103.94, 116.78, 123, 68])
return img.flatten().astype('float32'), label
......
......@@ -262,7 +262,12 @@ def left_right_flip(im):
return im[:, ::-1, :]
def simple_transform(im, resize_size, crop_size, is_train, is_color=True):
def simple_transform(im,
resize_size,
crop_size,
is_train,
is_color=True,
mean=None):
"""
Simply data argumentation for training. These operations include
resizing, croping and flipping.
......@@ -288,8 +293,20 @@ def simple_transform(im, resize_size, crop_size, is_train, is_color=True):
im = left_right_flip(im)
else:
im = center_crop(im, crop_size)
if len(im.shape) == 3:
im = to_chw(im)
im = im.astype('float32')
if mean is not None:
mean = np.array(mean, dtype=np.float32)
# mean value, may be one value per channel
if mean.ndim == 1:
mean = mean[:, np.newaxis, np.newaxis]
else:
# elementwise mean
assert len(mean.shape) == len(im)
im -= mean
return im
......@@ -297,7 +314,8 @@ def load_and_transform(filename,
resize_size,
crop_size,
is_train,
is_color=True):
is_color=True,
mean=None):
"""
Load image from the input file `filename` and transform image for
data argumentation. Please refer to the `simple_transform` interface
......@@ -318,5 +336,5 @@ def load_and_transform(filename,
:type is_train: bool
"""
im = load_image(filename)
im = simple_transform(im, resize_size, crop_size, is_train, is_color)
im = simple_transform(im, resize_size, crop_size, is_train, is_color, mean)
return im
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册