Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.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_Tensorflow - Fatal编程技术网

Python 属性错误:';张量';对象没有属性';形状';

Python 属性错误:';张量';对象没有属性';形状';,python,tensorflow,Python,Tensorflow,堆栈跟踪 Traceback (most recent call last): File "main.py", line 6, in <module> connection.start_socket(8089, callback=handler.message_processor) File "/mnt/d/workspace/SketchRecognitionWithTensorFlow/src/main/python/connection/python_socke

堆栈跟踪

Traceback (most recent call last):
  File "main.py", line 6, in <module>
    connection.start_socket(8089, callback=handler.message_processor)
  File "/mnt/d/workspace/SketchRecognitionWithTensorFlow/src/main/python/connection/python_socket_server.py", line 13, in start_socket
    process_message(connection, callback=callback)
  File "/mnt/d/workspace/SketchRecognitionWithTensorFlow/src/main/python/connection/python_socket_server.py", line 38, in process_message
    result = callback(general_proto)
  File "/mnt/d/workspace/SketchRecognitionWithTensorFlow/src/main/python/recognition/proto_handler.py", line 39, in message_processor
    return train_shape(general_proto.template)
  File "/mnt/d/workspace/SketchRecognitionWithTensorFlow/src/main/python/recognition/proto_handler.py", line 23, in train_shape
    rec.add_training_data(recognition_template.interpretation.label, recognition_template.shape)
  File "/mnt/d/workspace/SketchRecognitionWithTensorFlow/src/main/python/recognition/recognition_manager.py", line 98, in add_training_data
    self.recognizers[label].train(label, points)
  File "/mnt/d/workspace/SketchRecognitionWithTensorFlow/src/main/python/recognition/simple/recognizer.py", line 78, in train
    self.classifier.fit(x=reshaped_tensor, y=target, steps=1)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 173, in fit
    input_fn, feed_fn = _get_input_fn(x, y, batch_size)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 67, in _get_input_fn
    x, y, n_classes=None, batch_size=batch_size)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/io/data_feeder.py", line 117, in setup_train_data_feeder
    X, y, n_classes, batch_size, shuffle=shuffle, epochs=epochs)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/io/data_feeder.py", line 239, in __init__
    self.X.shape, None if self.y is None else self.y.shape, n_classes,
AttributeError: 'Tensor' object has no attribute 'shape'
标签是一个字符串 点列表是x,y值数组的列表 例:


我不知道为什么张量没有形状属性,或者如何解决这个问题。非常感谢您的帮助。

对于没有行号的代码段,堆栈跟踪没有多大帮助。但我可以告诉你们,当我看到那个错误的时候,是因为我在numpy数组上使用了tf.reforme,而不是真正的张量流张量。当我试图确定形状时,结果对象抛出了该错误。希望这能有所帮助。

从提供的代码中很难看出,特别是因为我无法确定错误发生在哪里。但无论如何,我以前遇到过一个相关的问题:


在我看来,一些代码试图处理tf张量,就像它是np数组一样。张量没有
shape
属性,因为它们的形状存储为更复杂的对象。如果你想从np中获取信息,你必须调用
my\u tensor.get\u shape().as\u list()
。但是,由于您的代码(您发布的)中的非用户试图访问
张量上的任何
形状
属性,我不确定如何使用这些信息来解决您的问题。

因为没有可接受的答案,而且我自己来自谷歌:
归功于mrry,其内容如下:

由于TensorFlow 1.0,
tf.Tensor
现在有一个属性,它返回与相同的值。

那么解决方案是什么呢???@YanKingYin我看不出问题所在-你被困在哪里了?如果这个答案对你没有帮助,就打开另一个问题
def create_classifier(self):
        hiddenLayers = [self.num_points, self.num_points * 2, 10]
        self.classifier = tf.contrib.learn.DNNClassifier(hidden_units=hiddenLayers)
[[1,2],[2,3],[3,4],...]


def train(self, label, point_list):
    points = self.resample(point_list, self.num_points)
    utils.strip_ids_from_points(points)
    value_class = 1 if label == self.label else 0
    target = tf.reshape(tf.constant(value_class), [1])
    print 'training classifier to recognize value as: [' + str(value_class) + '] label is ' + label + ' class is ' + self.label
    point_tensor = tf.convert_to_tensor(points, dtype=tf.float32)
    reshaped_tensor = tf.reshape(point_tensor, [1, self.num_points * 2])
    print reshaped_tensor
    print target
    self.classifier.fit(x=reshaped_tensor, y=target, steps=1)