'float' object is not iterable after I changed scipy.misc.imresize to skimage.transform.resize

After I changed scipy.misc.imresize to skimage.transform.resize, I reported an error:

Traceback (most recent call last):
  File "./drive/MyDrive/神经网络训练文件/DL-based-Intelligent-Diagnosis-Benchmark-master/train.py", line 89, in <module>
    trainer.train()
  File "/content/drive/MyDrive/神经网络训练文件/DL-based-Intelligent-Diagnosis-Benchmark-master/utils/train_utils.py", line 203, in train
    for batch_idx, (inputs, labels) in enumerate(self.dataloaders[phase]):
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 628, in __next__
    data = self._next_data()
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 671, in _next_data
    data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/fetch.py", line 58, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/fetch.py", line 58, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/content/drive/MyDrive/神经网络训练文件/DL-based-Intelligent-Diagnosis-Benchmark-master/datasets/MatrixDatasets.py", line 44, in __getitem__
    seq = self.transforms(seq)
  File "/content/drive/MyDrive/神经网络训练文件/DL-based-Intelligent-Diagnosis-Benchmark-master/datasets/matrix_aug.py", line 30, in __call__
    seq = t(seq)
  File "/content/drive/MyDrive/神经网络训练文件/DL-based-Intelligent-Diagnosis-Benchmark-master/datasets/matrix_aug.py", line 52, in __call__
    seq = resize(seq, output_shape=self.size, order=1, mode='constant', preserve_range=True)
  File "/usr/local/lib/python3.8/dist-packages/skimage/transform/_warps.py", line 145, in resize
    image, output_shape = _preprocess_resize_output_shape(image, output_shape)
  File "/usr/local/lib/python3.8/dist-packages/skimage/transform/_warps.py", line 55, in _preprocess_resize_output_shape
    output_shape = tuple(output_shape)
TypeError: 'float' object is not iterable

I don’t know why that is. My original function is as follows. How should I modify it? Thank you code master :smiling_face_with_three_hearts:

class ReSize(object):
def init(self, size=1):
self.size = size
def call(self, seq):
# seq = scipy.misc.imresize(seq, self.size, interp=‘bilinear’, mode=None)
seq = skimage.transform.resize(seq, output_shape=self.size, order=1, mode=‘constant’, preserve_range=True)
seq = seq / 255
return seq

You need to pass output_shape as an iterable as seen here:

seq = np.random.randn(224, 224, 3)
skimage.transform.resize(seq, output_shape=200., order=1, mode='constant', preserve_range=True)
# TypeError: 'float' object is not iterable

out = skimage.transform.resize(seq, output_shape=[200, 200], order=1, mode='constant', preserve_range=True)
print(out.shape)
# (200, 200, 3)
1 Like

Thank U, I know why new errors have always happened, about the difference about “self.size” of “scipy.misc.imresize” and “output_shape” of “skimage.transform.resize”, first U are right , and in my code the “self.size”=1, it’s means The image size does not change. but only “output_shape” = seq.shape, they are consistant.