Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Add random_erasing #558

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

akitotakeki
Copy link
Contributor

@akitotakeki akitotakeki commented Apr 8, 2018

This PR is the implementation of Random Erasing (https://arxiv.org/abs/1708.04896).
Random Erasing is a new data augmentation method for training the convolutional neural network (CNN).

Please merge after #432.

Args:
img (~numpy.ndarray): An image array. This is in CHW format.
prob (float): Erasing probability.
scale_ratio_interval (tuple of two floats): Determines
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the arguments, scale_ratio_range is used.

prob (float): Erasing probability.
scale_ratio_interval (tuple of two floats): Determines
the distribution from which a scale ratio is sampled.
aspect_ratio_interval (tuple of two floats): Determines
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the arguments, aspect_ratio_range is used.

scale_ratio_interval (tuple of two floats): Determines
the distribution from which a scale ratio is sampled.
aspect_ratio_interval (tuple of two floats): Determines
the distribution from which an aspect ratio is sampled.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mean is not described.

* **aspect_ratio** (float): :math:`a` in the description.

"""
if random.randint(0, 1) > prob:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

randint(0, 1) returns 0 or 1. When 0 < prob < 1, this condition means 50% regardless of prob.

@Hakuyume
Copy link
Member

Hakuyume commented Apr 11, 2018

I think the following code is more simple.

if np.random.unifrom() < prob:
    random_sized_crop(img, ...)[:] = mean
return img

* **aspect_ratio** (float): :math:`a` in the description.

"""
if random.uniform(0.0, 1.0) > prob:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

< prob

crop, params = random_sized_crop(img, scale_ratio_range,
aspect_ratio_range, return_param=True)
if random_value:
crop[:] = np.random.random(crop.shape) * scale
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line modifies the input image.

the distribution from which an aspect ratio is sampled.
random_value (bool): Fill the rectangle region with random values.
scale (float): Pixel value scale.
fixed_value (~numpy.ndarray): Determines pixel values
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the consistency with other functions, how about using fill?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using random value when fill='random'? We can remove scale and random_value.

Copy link
Contributor Author

@akitotakeki akitotakeki Nov 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing from fixed_value to fill is fine.
However, if scale is deleted, the range of random values can not be defined.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to specify the range of random value? The range of pixel is always [0, 255] in ChainerCV

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood the situation. I'll fix the point.
However, the pixel range is always [0, 255] in ChainerCV, but in Chainer, it seems to be [0, 1].
https://github.com/chainer/chainer/blob/master/chainer/datasets/mnist.py
https://github.com/chainer/chainer/blob/master/chainer/datasets/svhn.py
https://github.com/chainer/chainer/blob/master/chainer/datasets/fashion_mnist.py

The difference seems inconvenient when using Chainer and ChainerCV at the same time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in Chainer, it seems to be [0, 1].

This is not true. Chainer sometimes uses [0, 255]. For example, ResNet in Chainer assumes the input range is [0, 255].
https://github.com/chainer/chainer/blob/master/chainer/links/model/vision/resnet.py#L547-L548

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mismatch of the pixel range in Chainer seems awkward.
However, this has nothing to do with ChainerCV, so I will follow your suggestion.

scale_ratio_range=(0.02, 0.4),
aspect_ratio_range=(0.3, 1 / 0.3),
random_value=True,
scale=1.0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be 255 since we use [0, 255] as the default range of images.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this option.

@knorth55 knorth55 added this to the 0.12 milestone Nov 1, 2018
@knorth55 knorth55 modified the milestones: 0.12, 0.13 Feb 2, 2019
@yuyu2172 yuyu2172 modified the milestones: 0.13, 1.0 May 21, 2019
@knorth55 knorth55 modified the milestones: 1.0, 0.14 Dec 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants