mmagic icon indicating copy to clipboard operation
mmagic copied to clipboard

Using owndata train EDSR ,error occur when reference

Open dzz416 opened this issue 3 years ago • 9 comments

I used my own data to train EDSR, the size of the training data LRHR is 100100; 400400, but I also used the 100*100 test image to make a mistake during the test. the command is: CUDA_VISIBLE_DEVICES=2 python demo/restoration_demo.py expedsr/edsrconfigs/edsr01.py expedsr/real_train/iter_200000.pth expedvr/testimg2/testlr1.png demo/demoo.png

A part of the test set can run normally, but some errors are:

Use load_from_local loader Traceback (most recent call last): File "demo/restoration_demo.py", line 46, in main() File "demo/restoration_demo.py", line 37, in main output = restoration_inference(model, args.img_path) File "/home1/dzzHD/mmediting/mmedit/apis/restoration_inference.py", line 36, in restoration_inference data = test_pipeline(data) File "/home1/dzzHD/mmediting/mmedit/datasets/pipelines/compose.py", line 42, in call data = t(data) File "/home1/dzzHD/mmediting/mmedit/datasets/pipelines/normalization.py", line 54, in call self.std, self.to_rgb) File "/home/dzz/.local/lib/python3.7/site-packages/mmcv/image/photometric.py", line 21, in imnormalize return imnormalize_(img, mean, std, to_rgb) File "/home/dzz/.local/lib/python3.7/site-packages/mmcv/image/photometric.py", line 42, in imnormalize_ cv2.subtract(img, mean, img) # inplace cv2.error: OpenCV(4.2.0) /io/opencv/modules/core/src/arithm.cpp:669: error: (-209:Sizes of input arguments do not match) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function 'arithm_op'

dzz416 avatar Nov 22 '21 01:11 dzz416

I have solved this problem. the mmediting/mmedit/datasets/pipelines/normlization.py ,in the class RescaleToZeroOne: the results dict has different 'lq' shape while running different imgs. add this :

class RescaleToZeroOne: """Transform the images into a range between 0 and 1.

Required keys are the keys in attribute "keys", added or modified keys are
the keys in attribute "keys".
It also supports rescaling a list of images.

Args:
    keys (Sequence[str]): The images to be transformed.
"""

def __init__(self, keys):
    self.keys = keys

def __call__(self, results):
    """Call function.

    Args:
        results (dict): A dict containing the necessary information and
            data for augmentation.

    Returns:
        dict: A dict containing the processed data and information.
    """
    for key in self.keys:
        if isinstance(results[key], list):
            results[key] = [
                v.astype(np.float32) / 255. for v in results[key]
            ]
        else:
            #print('same')
            results[key] = results[key].astype(np.float32) / 255.

####################################### #这里的结果results就已经不一样了,多了一层,添加判断 #print( results.keys())#result.keys='lq_path','lq','lq_ori_shape'#the lq_ori_shape' should be (H,W,3),get (H,W,4) if (results['lq_ori_shape'][2]==3): pass

    else:
        results['lq']=results['lq'][:,:,0:3]
    return results

####################################### def repr(self): return self.class.name + f'(keys={self.keys})'

dzz416 avatar Nov 22 '21 02:11 dzz416

Hello, do you mean that you encountered an error when the input has 4 channels?

ckkelvinchan avatar Nov 22 '21 05:11 ckkelvinchan

the input imgs has 3 channels,but get 4 channels results durning normlization

dzz416 avatar Nov 22 '21 06:11 dzz416

the input imgs has 3 channels,but get 4 channels results durning normlization

If this is the case, I guess all images will cause the error? But it seems that it works for most images (at least during training).

ckkelvinchan avatar Nov 23 '21 07:11 ckkelvinchan

the input imgs has 3 channels,but get 4 channels results durning normlization

If this is the case, I guess all images will cause the error? But it seems that it works for most images (at least during training).

Yes, there is no error during the training process. Some pictures can also run normally when running the demo, but some pictures will report errors. the results['lq'] has a fourth element which is 1.0

dzz416 avatar Nov 23 '21 07:11 dzz416

the input imgs has 3 channels,but get 4 channels results durning normlization

If this is the case, I guess all images will cause the error? But it seems that it works for most images (at least during training).

Yes, there is no error during the training process. Some pictures can also run normally when running the demo, but some pictures will report errors. the results['lq'] has a fourth element which is 1.0

Could you help have a look at the image that gives you this error? For example, maybe this image itself has 4 channels?

I think there must be something this image is different from the others.

ckkelvinchan avatar Nov 23 '21 08:11 ckkelvinchan

the input img's shape is both 100,100,3 and the dtype of it is both uint8

dzz416 avatar Nov 23 '21 08:11 dzz416

As RescaleToZeroOne does only a division, I think it will not give you an additional channel. It is probably that results['lq'] has 4 channels before entering RescaleToZeroOne.

ckkelvinchan avatar Nov 23 '21 09:11 ckkelvinchan

@dzz416 If an image whose format is png, it may have a hidden channel: alpha.

I think you can check the channel number of images by

img=cv2.imread('path', flag=cv2.IMREAD_UNCHANGED)
print(img.shape)

PS: cv2.IMREAD_COLOR will ignore the alpha channel.

Yshuo-Li avatar Jan 14 '22 06:01 Yshuo-Li

Closing this Issue due to no more feedback. Please feel free to reopen it if needed.

zengyh1900 avatar Oct 09 '22 06:10 zengyh1900