Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误:';str';对象没有属性';流行音乐';在matplotlib中_Python_Tensorflow_Matplotlib_Keras - Fatal编程技术网

Python 属性错误:';str';对象没有属性';流行音乐';在matplotlib中

Python 属性错误:';str';对象没有属性';流行音乐';在matplotlib中,python,tensorflow,matplotlib,keras,Python,Tensorflow,Matplotlib,Keras,我正在努力学习Tensorflow和深层神经网络。这个错误出现了,我找不到解释。我正在研究Pycharm,还尝试了Anaconda命令提示符。我应该在windows命令提示符下尝试吗 import tensorflow as tf from tensorflow import keras import numpy as np import matplotlib.pyplot as plt data = keras.datasets.fashion_mnist (train_images, tra

我正在努力学习Tensorflow和深层神经网络。这个错误出现了,我找不到解释。我正在研究Pycharm,还尝试了Anaconda命令提示符。我应该在windows命令提示符下尝试吗

import tensorflow as tf
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
data = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = data.load_data()

class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
           'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']

 train_images = train_images/255
 test_images = test_images/255
 model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)), # First layer
keras.layers.Dense(128, activation='relu'), #Second layer
keras.layers.Dense(10, activation='softmax') # Third layer
])


 model.compile(optimizer='adam',
          loss='sparse_categorical_crossentropy',
          metrics=['accuracy'])
 model.fit(train_images, train_labels, epochs=5)

 # test_loss, test_acc = model.evaluate(test_images,  test_labels, verbose=2)

 # print('\nTest accuracy:', test_acc)

  prediction = model.predict(test_images)
 # print(class_names[np.argmax(prediction[1])])

 for i in range(5):
    plt.grid(False)
    plt.imshow(test_images[i], cmap=plt.cm.binary)
    plt.xlabel("Actual: ", class_names[test_labels[i]])
    plt.title("Prediction : ", class_names[np.argmax(prediction[i])])
    plt.show()
''' 我得到了这个错误 '''

回溯(最近一次呼叫最后一次):
文件“C:/Users/Kullanici/Desktop/MachineLearningProjects/neuralNetworkTutorial/TensorDeepNN.py”,
第40行,在
plt.xlabel(“实际:”,类名称[测试标签[i])
文件“C:\Users\Kullanici\Anaconda3\envs\tensor\lib\site packages\matplotlib\pyplot.py”,第行
3063,在xlabel中
xlabel,fontdict=fontdict,labelpad=labelpad,**kwargs)
文件“C:\Users\Kullanici\Anaconda3\envs\tensor\lib\site packages\matplotlib\axes\u axes.py”,第行
247,在集合标签中
返回self.xaxis.set_label_text(xlabel、fontdict、**kwargs)
文件“C:\Users\Kullanici\Anaconda3\envs\tensor\lib\site packages\matplotlib\axis.py”,第行
1598,在set_标签_文本中
self.label.update(fontdict)
文件“C:\Users\Kullanici\Anaconda3\envs\tensor\lib\site packages\matplotlib\text.py”,第176行,
更新中
bbox=kwargs.pop(“bbox”,哨兵)
**AttributeError:“str”对象没有属性“pop”**

我找不到解决方案。

在函数中,
matplotlib.pyplot.xlabel(xlabel,fontdict=None,labelpad=None,**kwargs)
第一个参数应该是字符串。然而,你是通过的

    plt.xlabel("Actual: ", class_names[test_labels[i]])
    plt.title("Prediction : ", class_names[np.argmax(prediction[i])])
这不是字符串。你应该打电话

    plt.xlabel("Actual: " + class_names[test_labels[i]])
    plt.title("Prediction : " + class_names[np.argmax(prediction[i])])

bbox=kwargs.pop(“bbox”,sentinel)
您试图对字符串调用
pop()
,但
pop()
是一种列表方法。在Windows命令提示符下运行不会更改输出。感谢您的回答。从错误消息中您不明白什么?
    plt.xlabel("Actual: " + class_names[test_labels[i]])
    plt.title("Prediction : " + class_names[np.argmax(prediction[i])])