Converting my np.ndarray input and mask to tensor but got an error

Hi! I am trying to convert my input images and its masks to tensor from numpy.ndarray but I encountered an error along the way.

for img in train_gen:
  img = torch.from_numpy(img)

and this is the error I got

TypeError                                 Traceback (most recent call last)
<ipython-input-40-658119f1f5a6> in <module>()
      1 for img in train_gen:
----> 2   img = torch.from_numpy(img)
      3   print(img)

TypeError: expected np.ndarray (got tuple)

Can someone help me? please.


From the error message, it looks like “img” is a tuple and not a numpy array. So you should fix your code to make sure it is actually a numpy array.