JingyunLiang / SwinIR

SwinIR: Image Restoration Using Swin Transformer (official repository)

Home Page:https://arxiv.org/abs/2108.10257

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

runtimeerror when using other dataset?

hcleung3325 opened this issue · comments

Hi.
I want to train the model with my own dataset.
However, it keeps reporting
RuntimeError: stack expects each tensor to be equal size, but got [3, 256, 256] at entry 0 and [3, 256, 252] at entry 1
Do I have any wrong setting?
Thanks.

The part of json:
"datasets": {
"train": {
"name": "train_dataset" // just name
, "dataset_type": "sr" // "dncnn" | "dnpatch" | "fdncnn" | "ffdnet" | "sr" | "srmd" | "dpsr" | "plain" | "plainpatch" | "jpeg"
, "dataroot_H": "HR" // path of H training dataset. DIV2K (800 training images)
, "dataroot_L": "LR" // path of L training dataset

  , "H_size": 256                   // 96/144|192/384 | 128/192/256/512. LR patch size is set to 48 or 64 when compared with RCAN or RRDB.

  , "dataloader_shuffle": true
  , "dataloader_num_workers": 16
  , "dataloader_batch_size": 8      // batch size 1 | 16 | 32 | 48 | 64 | 128. Total batch size =4x8=32 in SwinIR
}
, "test": {
  "name": "test_dataset"            // just name
  , "dataset_type": "sr"         // "dncnn" | "dnpatch" | "fdncnn" | "ffdnet" | "sr" | "srmd" | "dpsr" | "plain" | "plainpatch" | "jpeg"
  , "dataroot_H": "testsets/Set5/HR"  // path of H testing dataset
  , "dataroot_L": "testsets/Set5/LR_bicubic/X4"              // path of L testing dataset

}

}

, "netG": {
"net_type": "swinir"
, "upscale": 4 // 2 | 3 | 4 | 8
, "in_chans": 3
, "img_size": 64 // For fair comparison, LR patch size is set to 48 or 64 when compared with RCAN or RRDB.
, "window_size": 8
, "img_range": 1.0
, "depths": [6, 6, 6, 6, 6, 6]
, "embed_dim": 180
, "num_heads": [6, 6, 6, 6, 6, 6]
, "mlp_ratio": 2
, "upsampler": "pixelshuffle" // "pixelshuffle" | "pixelshuffledirect" | "nearest+conv" | null
, "resi_connection": "1conv" // "1conv" | "3conv"

, "init_type": "default"

}

Could you provide the complete error log? Is there a problem in training or testing? I guess one image is less than 256x256 in your training set.

Thanks for the reply.
I think I find the problem.
It is related to the datasets pixel boundary problem.
I will fixed the images in dataset.
Thanks.

Also, may I ask that when I load the pretrain_G, and pretrain E,
, "path": {
"root": "superresolution" // "denoising" | "superresolution" | "dejpeg"
, "pretrained_netG": "supersolution/swinir_sr_classical_patch64_x4_l1_test/model/5000_G.pth" // path of pretrained model. We fine-tune X3/X4/X8 models from X2 model, so that G_optimizer_lr and G_scheduler_milestones can be halved to save time.
, "pretrained_netE": "supersolution/swinir_sr_classical_patch64_x4_l1_test/model/5000_E.pth" // path of pretrained model
}
However, the printed status on the terminal mentioned pretrained_netG= null pretrained_netE=null
Is that I loaded the pretrain model?
Thanks.

Could you provide the complete error log? Is there a problem in training or testing? I guess one image is less than 256x256 in your training set.

Thanks for reply.
After I fixed the pixel problem of the image, there is another error comes out.
Do u have any idea for that?
Thanks.

data = [self.dataset[idx] for idx in possibly_batched_index]

File "/data1/anaconda3/envs/py37_pytorch1.6/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/data1/KAIR/data/dataset_sr.py", line 43, in getitem
img_H = util.imread_uint(H_path, self.n_channels)
File "/data1/KAIR/utils/utils_image.py", line 193, in imread_uint
if img.ndim == 2:
AttributeError: 'NoneType' object has no attribute 'ndim'

For 'NoneType' object has no attribute 'ndim', it's always due to that the image path in invalid.

For 'NoneType' object has no attribute 'ndim', it's always due to that the image path in invalid.

Thanks I got it.
May I ask that when I load the pretrain_G, and pretrain E,
, "path": {
"root": "superresolution" // "denoising" | "superresolution" | "dejpeg"
, "pretrained_netG": "supersolution/swinir_sr_classical_patch64_x4_l1_test/model/5000_G.pth" // path of pretrained model. We fine-tune X3/X4/X8 models from X2 model, so that G_optimizer_lr and G_scheduler_milestones can be halved to save time.
, "pretrained_netE": "supersolution/swinir_sr_classical_patch64_x4_l1_test/model/5000_E.pth" // path of pretrained model
}
However, the printed status on the terminal mentioned pretrained_netG= null pretrained_netE=null
Is that I loaded the pretrain model?
Thanks.

For loading pretrained models, see #24 (comment) for a temporary solution. We will work on it later.