简体   繁体   English

类型错误:预期的字符串,而是得到 0 类型的 int

[英]TypeError: Expected String, got 0 of type int instead

i've been using the code from tf.estimate.quickstart to run my own image classification task and i keep getting the error stated in the title, this is the full code:我一直在使用 tf.estimate.quickstart 中的代码来运行我自己的图像分类任务,但我不断收到标题中所述的错误,这是完整的代码:

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))

the dataset i've used is the EMNIST dataset which contains handwritten letter images in the dimension of 28 x 28 which i've converted into a .csv file, is this the right way to go about image recognition training?我使用的数据集是 EMNIST 数据集,其中包含尺寸为 28 x 28 的手写字母图像,我已将其转换为 .csv 文件,这是进行图像识别训练的正确方法吗? the error is occurs in the line classifier.train(input_fn=train_input_fn, steps=1) here is the full stack trace:错误发生在行classifier.train(input_fn=train_input_fn, steps=1)这里是完整的堆栈跟踪:

Traceback (most recent call last):
  File "C:/Users/Slither/Documents/Scripts/lol.py", line 33, in <module>
    classifier.train(input_fn=train_input_fn, steps=1)
  File "C:\Users\Slither\Anaconda3\lib\site-packages\tensorflow\python\estimator\estimator.py", line 302, in train
    loss = self._train_model(input_fn, hooks, saving_listeners)
  File "C:\Users\Slither\Anaconda3\lib\site-packages\tensorflow\python\estimator\estimator.py", line 711, in _train_model
    features, labels, model_fn_lib.ModeKeys.TRAIN, self.config)
  File "C:\Users\Slither\Anaconda3\lib\site-packages\tensorflow\python\estimator\estimator.py", line 694, in _call_model_fn
    model_fn_results = self._model_fn(features=features, **kwargs)
  File "C:\Users\Slither\Anaconda3\lib\site-packages\tensorflow\python\estimator\canned\dnn.py", line 334, in _model_fn
    config=config)
  File "C:\Users\Slither\Anaconda3\lib\site-packages\tensorflow\python\estimator\canned\dnn.py", line 203, in _dnn_model_fn
    logits=logits)
  File "C:\Users\Slither\Anaconda3\lib\site-packages\tensorflow\python\estimator\canned\head.py", line 456, in create_estimator_spec
    name='class_string_lookup')
  File "C:\Users\Slither\Anaconda3\lib\site-packages\tensorflow\python\ops\lookup_ops.py", line 1197, in index_to_string_table_from_tensor
    vocabulary_list = ops.convert_to_tensor(vocabulary_list, dtypes.string)
  File "C:\Users\Slither\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 836, in convert_to_tensor
    as_ref=False)
  File "C:\Users\Slither\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 926, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "C:\Users\Slither\Anaconda3\lib\site-packages\tensorflow\python\framework\constant_op.py", line 229, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "C:\Users\Slither\Anaconda3\lib\site-packages\tensorflow\python\framework\constant_op.py", line 208, in constant
    value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "C:\Users\Slither\Anaconda3\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 383, in make_tensor_proto
    _AssertCompatible(values, dtype)
  File "C:\Users\Slither\Anaconda3\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 303, in _AssertCompatible
    (dtype.name, repr(mismatch), type(mismatch).__name__))
TypeError: Expected string, got 0 of type 'int' instead.

Process finished with exit code 1

词汇表应该是字符串,但您正在添加整数(您正在调用 str(i) 并在您可能表示 i = str(i) 时忽略结果)。

暂无
暂无

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

相关问题 预期的类型为“ int”,取值为“ IntegerField”,而不是Django - Expected type 'int', got 'IntegerField' instead Django keras:TypeError:预期为int32,获取的列表包含类型为&#39;_Message&#39;的张量 - keras: TypeError: Expected int32, got list containing Tensors of type '_Message' instead CNN:TypeError:预期为int32,列表改为包含“ _Message”类型的张量 - CNN: TypeError: Expected int32, got list containing Tensors of type '_Message' instead Tensorflow Slim:TypeError:预期为 int32,得到包含“_Message”类型张量的列表 - Tensorflow Slim: TypeError: Expected int32, got list containing Tensors of type '_Message' instead 发生此错误。 “ TypeError:预期为int64,取而代之的是&#39;float&#39;类型的1e-07。”。 我能怎么做? - This error was occured. “TypeError: Expected int64, got 1e-07 of type 'float' instead.” . How can I do? TypeError:预期为float32,而不是类型为“ complex”的() - TypeError: Expected float32, got () of type 'complex' instead 类型错误:预期为 float32,而是得到了类型为 &#39;str&#39; 的 &#39;auto&#39; - TypeError: Expected float32, got 'auto' of type 'str' instead PyCharm,范围,预期类型“_SupportsIndex”,改为“int” - PyCharm, range, Expected type '_SupportsIndex', got 'int' instead 当我运行“ tf.nn.dynamic_rnn”时,出现TypeError:预期为int32,得到的列表包含类型为“ _Message”的张量 - When I run “tf.nn.dynamic_rnn”, I got TypeError: Expected int32, got list containing Tensors of type '_Message' instead TypeError:参数“字符串”的类型不正确(预期为 str,得到浮点数) - TypeError: Argument 'string' has incorrect type (expected str, got float)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM