Hello, I am unable to understand why this logic for crop function won’t work specifically for “test_unet” Unit test cell which is after putting the entire UNet together… but this logic works for previous unit test cells. Is it because of the round() which might not always be the case where delta_h is a decimal but needs pre-round off not post?
round off will always be an issue bcs I am dividing by 2 so either the number to be rounded off is ‘x’.0 or ‘x’.5
Looks like there might be multiple possibilities depending on image.shape and new_shape and the deciding factor will be the value of delta_h and delta_w so it will need conditions and all…but if anyone comes up with a better solution around this please leave a comment.
@Nandan_Bagadi, you’re right - rounding can be a problem, depending on the sizes of the original image shape and the new cropped shape. In particular, it looks like this code could run into a problem if the original image shape is an odd number, but the new cropped shape is even.
As an example, suppose image height = 101, and the cropped height = 100. Then, using the code above, h2 would be 0, but h1 would be 101 - round(1/2) = 101 - 0 = 101, which is not what you want, because now the size of your cropped image is 101 when it’s supposed to be 100.
One way to avoid using round() would be to just add the requested cropped image size to your start value: so, h1:h1+new_shape
That makes sense, I will be trying this. Thanks for the reply!