TypeError:Expected String,取而代之的是int类型的0

时间:2017-12-28 03:21:12

标签: python image-processing tensorflow machine-learning

我一直在使用tf.estimate.quickstart中的代码来运行我自己的图像分类任务,并且我不断收到标题中所述的错误,这是完整的代码:

from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys

class App:

    def mainGui(self):
        self.mainWin = QMainWindow()
        self.mainWin.setGeometry(200,200,500,432)
        self.mainWin.show()
        mainMenu = self.mainWin.menuBar()
        mainMenu.setNativeMenuBar(False)
        aboutMenu = mainMenu.addMenu('A&bout')
        helpButton = QAction(QIcon(),'Help',self.mainWin)
        helpButton.setShortcut('F4')
        helpButton.triggered.connect(self.helpPopup)
        aboutMenu.addAction(helpButton)

    def helpPopup(self):
        self.popup = QDialog()
        self.popup.setWindowTitle('Help')
        self.popup.setGeometry(800,200,300,500)
        self.popup.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    a = App()
    a.mainGui()
    sys.exit(app.exec_())

我使用的数据集是EMNIST数据集,其中包含28 x 28维度的手写字母图像,我已将其转换为.csv文件,这是正确的图像识别方式训练? 行import numpy as np import tensorflow as tf import pandas as pd train_x = pd.read_csv('train_set_x.csv') train_y = pd.read_csv('train_set_y.csv') test_x = pd.read_csv('test_set_x.csv') test_y = pd.read_csv('test_set_y.csv') feature_columns = [tf.feature_column.numeric_column("x", shape=[784])] uni = set() for i in range(0,26): str(i) uni.add(i) uni = list(uni) train_input_fn = tf.estimator.inputs.numpy_input_fn( x={"x": np.array(train_x)}, y=np.array(train_y), num_epochs=None, shuffle=True) classifier = tf.estimator.DNNClassifier(feature_columns=feature_columns, hidden_units=[10, 20, 10], n_classes=26, model_dir="/tmp/test_run", label_vocabulary=uni) classifier.train(input_fn=train_input_fn, steps=1) test_input_fn = tf.estimator.inputs.numpy_input_fn( x={"x": np.array(test_x)}, y=np.array(test_y), num_epochs=1, shuffle=False) accuracy_score = classifier.evaluate(input_fn = test_input_fn)["Accuracy"] print("\nTest Accuracy: {0:f}\n".format(accuracy_score)) 中出现错误 这是完整的堆栈跟踪:

classifier.train(input_fn=train_input_fn, steps=1)

1 个答案:

答案 0 :(得分:0)

词汇表应该是字符串,但是你要添加整数(你调用str(i)并忽略结果,你可能意味着i = str(i))。