TypeError: only integer scalar arrays can be converted to a scalar index


(Bhabani) #1

This is a new kind of error throwing while using the plots function. Here’s the traceback

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-37-bc14e8ee4a40> in <module>()
----> 1 plots(img=img, titles=labels)

/home/ai/Project/IPI_old/IPI_DL/plots.py in plots(img, figsize, rows, interpolation, titles)
     13 def plots(img, figsize=(12,6), rows = 1, interpolation = False, titles = None):
     14     if type(img[0]) is np.ndarray:
---> 15         img = np.array(img).astype(np.uint8)
     16         if (img.shape[-1] != 3):
     17             img = img.transpose((0,2,3,1))

TypeError: only integer scalar arrays can be converted to a scalar index

Any ideas why its happening ?


(Chris Palmer) #2

Hi @WaterRocket8236, did you get sorted on this? I am experiencing the same error in the new part 1 when loading images in the first notebook, in the local function load_img_id


D:\Anaconda3\envs\fastai\lib\site-packages\ipykernel_launcher.py:7: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.
  import sys
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-71-25e3ed2c5e21> in <module>()
----> 1 plot_val_with_title(most_by_correct(0, False), "Most incorrect cats")

<ipython-input-70-1889715aa722> in plot_val_with_title(idxs, title)
      1 def plot_val_with_title(idxs, title):
----> 2     imgs = [load_img_id(data.val_ds,x) for x in idxs]
      3     title_probs = [probs[x] for x in idxs]
      4     print(title)
      5     return plots(imgs, rows=1, titles=title_probs, figsize=(16,8))

<ipython-input-70-1889715aa722> in <listcomp>(.0)
      1 def plot_val_with_title(idxs, title):
----> 2     imgs = [load_img_id(data.val_ds,x) for x in idxs]
      3     title_probs = [probs[x] for x in idxs]
      4     print(title)
      5     return plots(imgs, rows=1, titles=title_probs, figsize=(16,8))

<ipython-input-21-81ef77890be4> in load_img_id(ds, idx)
----> 1 def load_img_id(ds, idx): return np.array(PIL.Image.open(PATH+ds.fnames[idx]))

TypeError: only integer scalar arrays can be converted to a scalar index