Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed size crops #272

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

Conversation

markusnagel
Copy link

I added a transformer that performs a fixed size crop. It is similar to the already existing RandomFixedSizeCrop transformer. One key difference is that the user can specify the crop with a relative location instead of taking a random crop. This is useful for example for predicting on imagenet where often a center crop of the image is used or a center crop plus the 4 corner crops.

@vdumoulin
Copy link
Contributor

@markusnagel Very sorry for the delay! I'll try to have a look at it by the end of the week.



class FixedSizeCrop(SourcewiseTransformer, ExpectsAxisLabels):
"""Crop images to a fixed window size.
Copy link
Member

Choose a reason for hiding this comment

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

Sections in the docstring should have newlines.

@vdumoulin
Copy link
Contributor

There seems to be quite a lot of overlap between FixedSizeCrop and RandomFixedSizeCrop. You could make FixedSizeCrop inherit from RandomFixedSizeCrop and factor cropping into _crop_batch and _crop_example methods which accept off_h and off_w arguments.

aukejw added 2 commits March 3, 2016 17:18
…_size_crops

Conflicts:
	fuel/transformers/image.py
	tests/transformers/test_image.py
@aukejw
Copy link
Contributor

aukejw commented Mar 3, 2016

The FixedSizeCrop transformer will afaik not benefit from using window_batch_bchw. The same offset is used for all images in the batch, so you can simply use

return source[:, :, off_h:off_h + windowed_height, off_w:off_w + windowed_width]

rather than first constructing arrays offsets_h and offsets_w of the same length as the batch, then invoking window_batch_bchw.

Therefore, the FixedSizeCrop transformer currently does not call _crop_batch. I haven't tested whether it actually makes a difference in terms of speed, but it seems like overkill to use window_batch_bchw here - though I agree that it would be intuitive to abstract the cropping functionality.

@aukejw aukejw deleted the fixed_size_crops branch November 10, 2016 08:49
@aukejw aukejw restored the fixed_size_crops branch March 23, 2017 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants