2016-07-03 11 views
1

スタックトレースここはAttributeError:「テンソル」オブジェクトが属性「形状」

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) 

ラベルは、文字列 ポイントリストである配列のリストされそれはと言っている理由

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

わからない。:Xの、yは 元の値テンソルは形状属性を持たないか、この問題をどのように修正するかです。どんな助けもありがたい。

答えて

1

そこには受け入れられた答えはありませんし、私は自分自身では、Googleから来ているので:
をTensorFlow 1.0、tf.Tensorは今と同じ値を返しますtf.Tensor.shape性質を持っているので:
クレジットを読み取る、this answerでmrryに行きますtf.Tensor.get_shape()

1

スタックトレースは、行番号を持たないコードスニペットではあまり役に立ちません。しかし、私はエラーを見たときに、真のテンソルフローテンソルの代わりにnumpy配列でtf.reshapeを使用したためだと言えます。結果のオブジェクトは、形状を決定しようとしたときにそのエラーを投げた。希望が役立ちます。

0

エラーがどこで発生するのかわからないので、提供されたコードからは分かりません。しかし、それが価値のあるものについては、前に関連する問題に遭遇しました:

私には、いくつかのコードがtpテンソルをnp配列のように扱うように見えます。テンソルにはshapeという属性がありません。これは、その形状がより複雑なオブジェクトとして保存されているためです。情報を取得したい場合は、npから慣れているので、my_tensor.get_shape().as_list()に電話する必要があります。しかし、(あなたが投稿した)あなたのコードのどれかがTensorshapeアトリビュートにアクセスしようとしているので、この情報を使って問題を解決する方法がわかりません。

関連する問題