简体   繁体   English

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

[英]ValueError: x and y must have same first dimension, but have shapes (6,) and (8,)

I've been following the step by step tutorial for this web app for plant disease detection and there's an error in this part where it suppose to show the line graph but there's an error at the line 3 which said "ValueError: x and y must have same first dimension, but have shapes (6,) and (8,)" I hope someone can help me to solve this thank you in advance Im just a beginner in coding so it will be a huge help for me.我一直在按照此 web 应用程序进行植物病害检测的分步教程进行操作,这部分有一个错误,它应该显示折线图,但第 3 行有一个错误,上面写着“ValueError: x and y must具有相同的第一个维度,但具有形状(6,)和(8,)“我希望有人可以帮助我解决这个问题,谢谢你我只是编码的初学者,所以这对我有很大的帮助。

n = 6
plt.figure(figsize=(8,5))
plt.plot(np.arange(1, n + 1),history.history['loss'], label = 'train_loss')
plt.plot(np.arange(1,n + 1), history.history['val_loss'], label = 'val_loss')
plt.plot(np.arange(1,n + 1), history.history['val_accuracy'], label = 'val_accuracy')
plt.grid(True)
plt.legend(loc = "best")
plt.savefig('/content/drive/My Drive/PlantDRecognition/performance.jpg')
plt.show()

The problem is that the the length of history.history['loss'] and n are not equal.问题是history.history['loss']n的长度不相等。

Actually, x values of matplotlib.pyplot.plot(x, y) are optional and default to range(len(y)) .实际上, matplotlib.pyplot.plot(x, y)x值是可选的,默认为range(len(y)) You only need你只需要

plt.plot(history.history['loss'], label = 'train_loss')
plt.plot(history.history['val_loss'], label = 'val_loss')
plt.plot(history.history['val_accuracy'], label = 'val_accuracy')

If you want x to start with 1,如果您希望x以 1 开头,

plt.plot(range(1, len(history.history['loss'])+1), history.history['loss'], label = 'train_loss')
plt.plot(range(1, len(history.history['val_loss'])+1), history.history['val_loss'], label = 'val_loss')
plt.plot(range(1, len(history.history['val_accuracy'])+1), history.history['val_accuracy'], label = 'val_accuracy')

暂无
暂无

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

相关问题 ValueError:x 和 y 必须具有相同的第一维,但具有形状 (1, 2) 和 (2,) - ValueError: x and y must have same first dimension, but have shapes (1, 2) and (2,) ValueError:x 和 y 必须具有相同的第一维,但具有形状 - ValueError: x and y must have same first dimension, but have shapes 线性回归模型形状 - ValueError:x 和 y 必须具有相同的第一维,但具有形状 (5,) 和 (1, 5) - Linear regression model shapes - ValueError: x and y must have same first dimension, but have shapes (5,) and (1, 5) ValueError: x 和 y 必须具有相同的第一维,但具有形状 (101,) 和 (100,) - ValueError: x and y must have same first dimension, but have shapes (101,) and (100,) ValueError: x 和 y 必须具有相同的第一维,但具有形状 (1,) 和 (224, 224, 3) - ValueError: x and y must have same first dimension, but have shapes (1,) and (224, 224, 3) 谁能帮我? ValueError:x 和 y 必须具有相同的第一维,但具有形状 (10,) 和 (0,) - Can anyone help me? ValueError: x and y must have same first dimension, but have shapes (10,) and (0,) ValueError: x 和 y 必须具有相同的第一维,但具有形状 (50,) 和 (1, 50)/ 多处理 - ValueError: x and y must have same first dimension, but have shapes (50,) and (1, 50)/ Multiprocessing Matplotlib 'ValueError: x 和 y 必须具有相同的第一维,但具有形状 (20,) 和 (1,)' - Matplotlib 'ValueError: x and y must have same first dimension, but have shapes (20,) and (1,)' ValueError: x 和 y 必须具有相同的第一维,但有形状,tkinter 和 matplotlib 问题 - ValueError: x and y must have same first dimension, but have shapes, tkinter and matplotlib problem ValueError:x和y必须具有相同的第一尺寸,但形状为(4200,)和(16800,1) - ValueError: x and y must have same first dimension, but have shapes (4200,) and (16800, 1)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM