0

I tried to read images by using os.listdir(directory) and Keras:

import os
from PIL import Image
from keras.preprocessing import image

img_path = 'D:\folder\train'

images = [(img, label) for (img, label) in zip(label_train.Image[:5], label_train.Id[:5])]

fig, m_axs = plt.subplots(1, len(images), figsize = (20, 10))
#show the images and label them
for ii, c_ax in enumerate(m_axs):
    c_ax.imshow(imread(os.path.join(img_path,images[ii][0])))
    c_ax.set_title(images[ii][1])

I received error on this line: c_ax.imshow(imread(os.path.join(img_path,images[ii][0]))) error message Invalid argument: 'D:\\folder\train\\00001.jpg.

I'm using Python 3. How should I edit my code?

martineau
  • 119,623
  • 25
  • 170
  • 301
Osca
  • 1,588
  • 2
  • 20
  • 41
  • 1
    The `\t` in `'D:\folder\train'` will be interpreted as a `tab` character. Try instead `img_path = r'D:\folder\train'`, the [`r` prefix](https://stackoverflow.com/questions/4780088/what-does-preceding-a-string-literal-with-r-mean) for the string treats the entire thing as a raw string, such that the `'\'` character will not be escaped. – metatoaster Dec 07 '18 at 03:28
  • Wonderful !! thank you! – Osca Dec 07 '18 at 03:33

0 Answers0