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

adaptive cropping #22

Open
nanmehta opened this issue Oct 27, 2020 · 3 comments
Open

adaptive cropping #22

nanmehta opened this issue Oct 27, 2020 · 3 comments

Comments

@nanmehta
Copy link

thanks for the wonderful concept.
can u please let me know exactly where in the code is this strategy of adaptive cropping

@Zheng222
Copy link
Owner

@nan-rock

IMDN/test_IMDN_AS.py

Lines 30 to 60 in f1170cf

def crop_forward(x, model, shave=32):
b, c, h, w = x.size()
h_half, w_half = h // 2, w // 2
h_size, w_size = h_half + shave - (h_half + shave) % 4, w_half + shave - (w_half + shave) % 4
inputlist = [
x[:, :, 0:h_size, 0:w_size],
x[:, :, 0:h_size, (w - w_size):w],
x[:, :, (h - h_size):h, 0:w_size],
x[:, :, (h - h_size):h, (w - w_size):w]]
outputlist = []
with torch.no_grad():
input_batch = torch.cat(inputlist, dim=0)
output_batch = model(input_batch)
outputlist.extend(output_batch.chunk(4, dim=0))
output = torch.zeros_like(x)
output[:, :, 0:h_half, 0:w_half] \
= outputlist[0][:, :, 0:h_half, 0:w_half]
output[:, :, 0:h_half, w_half:w] \
= outputlist[1][:, :, 0:h_half, (w_size - w + w_half):w_size]
output[:, :, h_half:h, 0:w_half] \
= outputlist[2][:, :, (h_size - h + h_half):h_size, 0:w_half]
output[:, :, h_half:h, w_half:w] \
= outputlist[3][:, :, (h_size - h + h_half):h_size, (w_size - w + w_half):w_size]
return output

@nanmehta
Copy link
Author

thanks for the quick response.
i just wanted to ask as you mentioned in issue #9 regarding adaptive cropping tha it allows us to output exactly the same size as the target size. But does it make a difference in the overall result. As in the example you gave the output using this strategy is (2801x 2001) instead of 2800 X2000. But even we ignore 1 pixel from the boundary it wont make much difference

@EvelyneCalista
Copy link

Hello, may I ask if I would like to use ACS, shall I modify the train code with the crop_forward too?
thank you.

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

No branches or pull requests

3 participants