我正在尝试通过tensorflow进行MNIST图像分类,并且在打包时遇到了一些麻烦。我的代码如下:
import tensorflow as tf
import matplotlib.pyplot as plt
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
image_index = 7777
print(y_train(image_index))
plt.inshow(x_train(image_index))
plt.show()
我在Anaconda-Navigator中使用matplotlib,tensorflow和numpy创建了一个环境。然后,我在终端中启动了这个env并导航到我上面的代码(我确定终端在bash中)。在终端中运行时
python3 filename.py
我收到错误消息:
Traceback (most recent call last):
File "filename.py", line 3, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
我用pip安装了包装。pip install matplotlib为我工作。
您的代码有误。
将您的代码更新为:
import tensorflow as tf
import matplotlib.pyplot as plt
import matplotlib
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
image_index = 7777
print(y_train[image_index])
plt.imshow(x_train[image_index])
plt.show()