chaiNNer-org / spandrel

Spandrel gives your project support for various PyTorch architectures meant for AI Super-Resolution, restoration, and inpainting. Based on the model support implemented in chaiNNer.
MIT License
105 stars 7 forks source link

Pad images to size requirements in call API #137

Closed RunDevelopment closed 5 months ago

RunDevelopment commented 5 months ago

Changes:

RunDevelopment commented 5 months ago

Getting padding right turned out to be more interesting than I thought. The issue is that torch.nn.functional.pad(t, (0, pad_w, 0, pad_h), "reflect") only works if pad_w and pad_h are less than the width and height of the image respectively. So we first have to pad as much as we can with reflect and then use something else to cover the rest (if anything). Surprisingly non-trivial.