繁体   English   中英

ValueError: x 和 y 必须具有相同的第一维,但具有形状 (1,) 和 (224, 224, 3)

[英]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)

你的来电

plt.plot('image',img)

正在生成错误,因为第一个和第二个参数必须具有相同的维度。

也许,你应该考虑

plt.imshow(img)

替换这条线?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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