data preprocessing error pytorch

 

Error:

Traceback (most recent call last):
  File "train.py", line 305, in <module>
    train_model(model_conv, criterion, optimizer_conv, exp_lr_scheduler)
  File "train.py", line 145, in train_model
    for inputs, age_labels, gender_labels in dataloaders[phase]:
  File "/home/home/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 637, in __next__
    return self._process_next_batch(batch)
  File "/home/home/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 658, in _process_next_batch
    raise batch.exc_type(batch.exc_msg)
RuntimeError: Traceback (most recent call last):
  File "/home/home/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop
    samples = collate_fn([dataset[i] for i in batch_indices])
  File "/home/home/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 232, in default_collate
    return [default_collate(samples) for samples in transposed]
  File "/home/home/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 232, in <listcomp>
    return [default_collate(samples) for samples in transposed]
  File "/home/home/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 209, in default_collate
    return torch.stack(batch, 0, out=out)
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 224 and 228 in dimension 3 at /pytorch/aten/src/TH/generic/THTensorMoreMath.cpp:1307

This is because they do not match the size of the input, with the relevant data set, but also with the data preprocessing function:

transforms.Resize(input_size)

This function is scaled, probably because of the different resolution of the data set, so the results are not out (224, 224), the solution is to instead use:

transforms.Resize((input_size, input_size))

To

Guess you like

Origin www.cnblogs.com/wanghui-garcia/p/12091128.html