简体   繁体   中英

ValueError: x and y must have same first dimension, but have shapes (1,) and (224, 224, 3)

import os
import cv2

path1 = os.path.abspath('/content/drive/My Drive/dogbreed/test_set/n02085620-Chihuahua')
path2 = os.path.abspath('/content/drive/My Drive/dogbreed/test_set/n02085936-Maltese_dog')
path3 = os.path.abspath('/content/drive/My Drive/dogbreed/test_set/n02088238-basset')
folder = os.path.join(path1, path2, path3)

images = []
for filename in os.listdir(folder):

  if filename.endswith(".jpg"):
    img = cv2.imread(os.path.join(folder, filename))

    if img is not None:
      images.append(img)

from matplotlib import pyplot as plt
import numpy as np
img = np.array(images[0])
img = cv2.resize(img, (224, 224), interpolation = cv2.INTER_CUBIC)
plt.plot('image',img)

your call to

plt.plot('image',img)

is generating the error because the first and the second argument must have the same dimension.

Maybe, should you consider

plt.imshow(img)

to replace this line?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM