gpt4 book ai didi

python - 属性错误 : 'Tensor' object has no attribute 'shape'

转载 作者:行者123 更新时间:2023-11-28 16:23:54 25 4
gpt4 key购买 nike

堆栈跟踪

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'

下面是一些代码示例:

def create_classifier(self):
hiddenLayers = [self.num_points, self.num_points * 2, 10]
self.classifier = tf.contrib.learn.DNNClassifier(hidden_units=hiddenLayers)

标签是一个字符串point list 是 x, y 值数组的列表例如:

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

我不知道为什么说张量没有形状属性或如何解决这个问题。任何帮助表示赞赏。

最佳答案

由于没有公认的答案,而且我本人来自 Google:
归功于this answer。 ,内容如下:
从 TensorFlow 1.0 开始,tf.Tensor 现在有一个 tf.Tensor.shape属性,返回与 tf.Tensor.get_shape() 相同的值.

关于python - 属性错误 : 'Tensor' object has no attribute 'shape' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38167388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com