-
Notifications
You must be signed in to change notification settings - Fork 304
Add random_erasing #558
base: master
Are you sure you want to change the base?
Add random_erasing #558
Conversation
Args: | ||
img (~numpy.ndarray): An image array. This is in CHW format. | ||
prob (float): Erasing probability. | ||
scale_ratio_interval (tuple of two floats): Determines |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
.
I think the following code is more simple. if np.random.unifrom() < prob:
random_sized_crop(img, ...)[:] = mean
return img |
…kitotakeki/chainercv into akitotakeki-add-random-erasing
* **aspect_ratio** (float): :math:`a` in the description. | ||
|
||
""" | ||
if random.uniform(0.0, 1.0) > prob: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
This reverts commit 6bf2ef6.
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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…kitotakeki/chainercv into akitotakeki-add-random-erasing
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.