4

Stack trace

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'

Here is some code examples:

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

label is a string point list is a list of an array of x, y values ex:

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

I do not know why it is saying that a tensor does not have a shape attribute or how to fix this problem. Any help appreciated.

3 Answers 3

3

Since there is no accepted answer and I'm myself coming from Google:
Credit goes to mrry with this answer, which reads:
Since TensorFlow 1.0, tf.Tensor now has a tf.Tensor.shape property, which returns the same value as tf.Tensor.get_shape().

Sign up to request clarification or add additional context in comments.

2 Comments

So what is the solution??
@YanKingYin I don't see the problem - where are you stuck? if this answer doesn't help you, just open another question
1

The stack trace doesn't help a lot with code snippets that don't have line numbers. But I can tell you that when I saw that error it was because I used tf.reshape on a numpy array instead of a true tensorflow tensor. The resulting object threw that error when I tried to determine the shape. Hope that helps.

Comments

0

It's hard to see from the code provided, especially since I cannot figure out, where your error occurs. But for what it's worth, I have run into a related problem before:

It looks to me, like some code is trying to handle a tf-tensor as if it was a np-array. Tensors don't have a shape attribute, since their shape is stored as a more complicated object. If you want to get the information, you are used to from np, you'd have to call my_tensor.get_shape().as_list(). But since non of your code (that you posted) tries to access any shape attribute on a Tensor, I'm not sure how this information could be used to fix your problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.