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

username: Jacky1
cooked: <p>After I changed scipy.misc.imresize to skimage.transform.resize, I reported an error:</p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "./drive/MyDrive/神经网络训练文件/DL-based-Intelligent-Diagnosis-Benchmark-master/train.py", line 89, in &lt;module&gt;
    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 &lt;listcomp&gt;
    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
</code></pre>
<p>I don’t know why that is. My original function is as follows. How should I modify it? Thank you code master <img src="https://discuss.pytorch.org/images/emoji/apple/smiling_face_with_three_hearts.png?v=12" title=":smiling_face_with_three_hearts:" class="emoji" alt=":smiling_face_with_three_hearts:" loading="lazy" width="20" height="20"></p>
<blockquote>
<p>class ReSize(object):<br>
def <strong>init</strong>(self, size=1):<br>
self.size = size<br>
def <strong>call</strong>(self, seq):<br>
# seq = scipy.misc.imresize(seq, self.size, interp=‘bilinear’, mode=None)<br>
seq = skimage.transform.resize(seq, output_shape=self.size, order=1, mode=‘constant’, preserve_range=True)<br>
seq = seq / 255<br>
return seq</p>
</blockquote>

username: ptrblck
cooked: <p>You need to pass <code>output_shape</code> as an <code>iterable</code> as seen here:</p>
<pre><code class="lang-python">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)
</code></pre>

username: Jacky1
cooked: <p>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.</p>