Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.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 当使用张量流拟合分类器时,是什么导致此属性错误?_Python_Numpy_Machine Learning_Tensorflow - Fatal编程技术网

Python 当使用张量流拟合分类器时,是什么导致此属性错误?

Python 当使用张量流拟合分类器时,是什么导致此属性错误?,python,numpy,machine-learning,tensorflow,Python,Numpy,Machine Learning,Tensorflow,我试图编辑一些示例张量代码流,用一些数据来训练和测试卷积神经网络。我目前有以下代码,用于设置张量流并从文件中获取图像数据: mnist_classifier = learn.Estimator( model_fn=cnn_model_fn, model_dir="/tmp/mnist_convnet_model") tensors_to_log = {"probabilities": "softmax_tensor"} logging_hook = tf.train.Loggin

我试图编辑一些示例张量代码流,用一些数据来训练和测试卷积神经网络。我目前有以下代码,用于设置张量流并从文件中获取图像数据:

mnist_classifier = learn.Estimator(
      model_fn=cnn_model_fn, model_dir="/tmp/mnist_convnet_model")


tensors_to_log = {"probabilities": "softmax_tensor"}
logging_hook = tf.train.LoggingTensorHook(
      tensors=tensors_to_log, every_n_iter=50)


testImages = []
testLabels = []
for filename in os.listdir('images'):
    im = cv2.imread('images/' + filename)
    testImages.append(im)
    testLabels.append(np.int32(1.0))

for filename in os.listdir('badImages'):
    im = cv2.imread('badImages/' + filename)
    testImages.append(im)
    testLabels.append(np.int32(0.0))
然后,我尝试用以下行拟合模型:

 mnist_classifier.fit(
      x=testImages,
      y=testLabels,
      batch_size=10,
      steps=20000,
      monitors=[logging_hook])
但这会在运行时崩溃,并出现以下错误:

if x_is_dict else check_array(x, x.dtype)
AttributeError: 'list' object has no attribute 'dtype'

它似乎在说我的testImages var的结构/格式有一些问题,但我已经确认它是正确的类型-一个numpy.ndarray的numpy.ndarray。有什么想法吗?

我认为你的
x
应该是类型,但看起来你在使用列表

>>> import numpy as np
>>> x= np.array([1,2,3])
>>> x.dtype
dtype('int64')
>>> y=[1,2,3]
>>> y.dtype
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'dtype'
>>将numpy作为np导入
>>>x=np.数组([1,2,3])
>>>x.D类型
数据类型('int64')
>>>y=[1,2,3]
>>>y.D类型
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
AttributeError:“list”对象没有属性“dtype”

错误说明
x
是一个
列表
,因此没有
数据类型
。在
fit
命令中,我看到

x=testImages,
更早

testImages = []   # and list append's

你在哪里确认这是一个数组?

在我附加到测试图像后,我打印了它的类型,它说bumpy.ndarray,但我会再次检查它