BasicSR icon indicating copy to clipboard operation
BasicSR copied to clipboard

matlab_functions.py bug

Open BaseBlank opened this issue 3 years ago • 0 comments

The location of the bug file is as follows:

BasicSR/basicsr/utils/matlab_functions.py The imresize() function is very clear and accurate, which is excellent work, But when I used the imresize () function independently, founding that this part of the code was not robust enough, and an error occurred.

Some of the code involved is as follows:

=================================================================================== image = cv2.imread(f"./kelee.jpg", cv2.IMREAD_UNCHANGED) print(image.shape) lr_image = imresize(image, 1 / 4, antialiasing=False)

Run>>>>>>>>>>>>>>>>>>>>>>>> (1000, 796, 3) RuntimeError: The size of tensor a (0) must match the size of tensor b (1000) at non-singleton dimension 1

Debug

Discover through debug code, 123~124 lines in matlab_functions.py weights_h, indices_h, sym_len_hs, sym_len_he = calculate_weights_indices(in_h, out_h, scale, kernel, kernel_width, antialiasing) the reason for this error is that the return values of calculate_weights_Indices () function sym_len_hs and sym_len_he are both 0, Resulting in the following code error: 140 line in matlab_functions.py img_aug.narrow(1, sym_len_hs + in_h, sym_len_he).copy_(sym_patch_inv)

Linking images

https://www.bing.com/images/search?view=detailV2&ccid=jnK2NH9s&id=47D58AB3BE07A7E26AD6154982DAEEDA6A4DB4A1&thid=OIP.jnK2NH9s7u-RwCVAK5MP4AHaJT&mediaurl=https%3a%2f%2fupload-bbs.mihoyo.com%2fupload%2f2021%2f07%2f10%2f218246419%2f652545c653839da4f9fd45eb2ae6234c_435824677028746461.jpg&cdnurl=https%3a%2f%2fth.bing.com%2fth%2fid%2fR.8e72b6347f6ceeef91c025402b930fe0%3frik%3dobRNatru2oJJFQ%26pid%3dImgRaw%26r%3d0&exph=1000&expw=796&q=%e5%8f%af%e8%8e%89&simid=607989454870820594&FORM=IRPRST&ck=003360B53E2504F14ADAF7EDD800F022&selectedIndex=8&ajaxhist=0&ajaxserp=0

The image used in the code kelee.jpg Right click and save as image

The other additional

A new set of code has been tested:

================================================================================== image = cv2.imread(f"./kelee.jpg", cv2.IMREAD_UNCHANGED) print(image.shape) lr_image = imresize(image, 1 / 8, antialiasing=False)

Run>>>>>>>>>>>>>>>>>>>>>>>> (1000, 796, 3) RuntimeError: start (994) + length (1000) exceeds dimension size (996). Discover through debug code, 123~124 lines in matlab_functions.py weights_h, indices_h, sym_len_hs, sym_len_he = calculate_weights_indices(in_h, out_h, scale, kernel, kernel_width, antialiasing) the reason for this error is that the return values of calculate_weights_Indices () function sym_len_hs and sym_len_he are both -2, Resulting in the following code error:

Complete save information


RuntimeError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_4628\3154877855.py in 184 185 return out_2 --> 186 lr_image = imresize(image, 1 / 4, antialiasing=False)

D:\Anaconda\installer\envs\PyTorch(1.9)\lib\site-packages\torch\autograd\grad_mode.py in decorate_context(*args, **kwargs) 26 def decorate_context(*args, **kwargs): 27 with self.class(): ---> 28 return func(*args, **kwargs) 29 return cast(F, decorate_context) 30

~\AppData\Local\Temp\ipykernel_4628\3154877855.py in imresize(img, scale, antialiasing) 145 inv_idx = torch.arange(sym_patch.size(1) - 1, -1, -1).long() 146 sym_patch_inv = sym_patch.index_select(1, inv_idx) --> 147 img_aug.narrow(1, sym_len_hs + in_h, sym_len_he).copy_(sym_patch_inv) 148 149 out_1 = torch.FloatTensor(in_c, out_h, in_w)

RuntimeError: The size of tensor a (0) must match the size of tensor b (1000) at non-singleton dimension 1

Looking forward to your reply and sincerely thank you.

BaseBlank avatar Sep 21 '22 13:09 BaseBlank