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

Crop or Pad transform. #562

Closed
ryanpeach opened this issue Jul 30, 2018 · 12 comments
Closed

Crop or Pad transform. #562

ryanpeach opened this issue Jul 30, 2018 · 12 comments

Comments

@ryanpeach
Copy link
Contributor

ryanpeach commented Jul 30, 2018

So, tensorflow has a transform function called resize_image_with_crop_or_pad. I recently needed this function for my own work. Moreover, it'd be nice to have all of the following:

  • RandomPad - Makes an image a certain size by padding but performs random offset on the padding.
  • CenterCropOrPad - Replicates Tensorflows function
  • RandomCropOrPad - A conditional mix of RandomCrop and RandomPad, guaranteeing size but w random offset.

If I put in a pull request would you be open to these methods?

What are the standards for writing transforms?

@fmassa
Copy link
Member

fmassa commented Jul 30, 2018

Isn't RandomCrop what you want?

@ryanpeach
Copy link
Contributor Author

I tried RandomCrop and it threw an error when the desired size was bigger than the source. Is it supposed to be able to pad also?

@fmassa
Copy link
Member

fmassa commented Jul 30, 2018

Yes, latest version of torchvision supports padding as well, check the link I sent you. There is an option for optionally adding padding if the input is too small

@ryanpeach
Copy link
Contributor Author

Oh I see in the documentation it is, never mind, maybe the bug was something else then. Maybe there's a way to change the description of this method in the list of transforms so that it mentions padding as well? (Maybe that's the case and I missed it as well).

Sorry, just now learning the library. I'll try to be more careful before making issues next time.

@fmassa
Copy link
Member

fmassa commented Jul 30, 2018

No worries.
We can definitely improve the documentation. Could you please send a PR?

@ryanpeach
Copy link
Contributor Author

Yes I'll look into it.

@ryanpeach
Copy link
Contributor Author

ryanpeach commented Aug 1, 2018

So I also learned that RandomCrop when you set pad_if_needed to True does not RandomPad. AKA, whereas random crop applies a crop at a random offset to the image, pad_if_needed performs a centered padding, which does not randomly place the image in the padded image. The goal for padding should be that the image is in a random spot. Imagine the following:

Imagine the image, whatever size, on an infinite canvas.
Apply a random offset, and a random crop, to that canvas, such that:
if the crop is bigger than the original image, all of the original image remains in the output.
if the crop is smaller than the original image, all of the output is part of the original image.

@ryanpeach
Copy link
Contributor Author

ryanpeach commented Aug 1, 2018

The easy fix for this is to over-pad the image in RandomCrop.

@fmassa
Copy link
Member

fmassa commented Aug 2, 2018

The random crop behavior was fixed by #564. @ryanpeach could you also send a PR improving the documentation?

@ryanpeach
Copy link
Contributor Author

Yes sorry, I have limited time for that but next time I work on my project I'll get to it!

@ekagra-ranjan
Copy link
Contributor

Can be closed via #791.

@soumith
Copy link
Member

soumith commented Mar 11, 2019

closed via #791

@soumith soumith closed this as completed Mar 11, 2019
rajveerb pushed a commit to rajveerb/vision that referenced this issue Nov 30, 2023
* [llm] Init draft NVIDIA reference

* [LLM] Add exact HPs used to match NVIDIA's convergence curves

* [LLM] Add data preprocessing steps and remove dropout

* [LLM] fix eval, add ckpt load util, remove unnecessary files

* [LLM] Update data preprocessing stage in README

* Full validation and google settings

* Apply review comments

* Anmolgupt/nvidia llm reference update (pytorch#3)

* Update Nvidia LLM reference code version

Co-authored-by: Anmol Gupta <anmolg@nvidia.com>

* fixes to imports (pytorch#5)

Co-authored-by: Anmol Gupta <14880251+anmolgupt@users.noreply.github.com>

* distributed checkpoint and mlperf logger support (pytorch#6)

* readme and mllogger keywords update (pytorch#7)

Co-authored-by: Anmol Gupta <anmolg@nvidia.com>

* Update fp32_checkpoint_checksum.log

* Update README.md

* Update README.md

* Update README.md

* mlperf logger keywords update (pytorch#8)

Co-authored-by: Anmol Gupta <anmolg@nvidia.com>

* [LLM] Create framework folder

* [LLM] Update README to follow reference template

* Describe LLM checkpoint format in README (pytorch#9)

Describe LLM checkpoint format in README

* [LLM] Readme updates, small fixes

* readme update and run script eval update (pytorch#10)

Co-authored-by: Anmol Gupta <anmolg@nvidia.com>

---------

Co-authored-by: Mikołaj Błaż <mblaz@nvidia.com>
Co-authored-by: anmolgupt <14880251+anmolgupt@users.noreply.github.com>
Co-authored-by: Anmol Gupta <anmolg@nvidia.com>
Co-authored-by: mikolajblaz <mikolajblaz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants