Tensorflow: Skalartensorwert als int für die Übergabe an set_shape() abrufenPython

Python-Programme
Anonymous
 Tensorflow: Skalartensorwert als int für die Übergabe an set_shape() abrufen

Post by Anonymous »

Ich versuche, 3D-Bilder und ihre Beschriftungen aus einem Numpy-Array in TensorFlow-Datensätze zu laden und sie dann aus einer Warteschlange zu lesen, während ich mein Netzwerk trainiere. Der Code für die Konvertierung basiert auf der Konvertierung für das Inception-Modell von TensorFlow.

Jedes Bild hat einen anderen Höhen-, Breiten- und Tiefenwert, daher muss ich diese Werte kennen, wenn ich das Array umforme. Ich erhalte jedoch eine Fehlermeldung, wenn ich versuche, set_shape zu verwenden, da irgendwo in der Zeile int() verwendet wird und es keine Tensorwerte akzeptiert.

Code: Select all

reader = tf.TFRecordReader()
_, value = reader.read(filename_queue)

# Features in Example proto
feature_map = {
'height': tf.VarLenFeature(dtype=tf.int64),
'width': tf.VarLenFeature(dtype=tf.int64),
'depth': tf.VarLenFeature(dtype=tf.int64),
'label': tf.VarLenFeature(dtype=tf.int64),
'image_raw': tf.VarLenFeature(dtype=tf.string)
}

features = tf.parse_single_example(value, feature_map)
result.label = tf.cast(features['label'].values[0], dtype=tf.int32)
result.height = tf.cast(features['height'].values[0], dtype=tf.int32)
result.width = tf.cast(features['width'].values[0], dtype=tf.int32)
result.depth = tf.cast(features['depth'].values[0], dtype=tf.int32)

image = tf.decode_raw(features['image_raw'].values[0], tf.int16)

image = tf.reshape(image, [result.depth, result.height, result.width])
image = tf.cast(tf.transpose(image, [1, 2, 0]), tf.float32)
result.image = tf.expand_dims(image, 3)

result.image.set_shape([result.height, result.width, result.depth, 1])
result.label = tf.expand_dims(result.label, 0)
result.label.set_shape([1])
Fehlerverfolgung:

Code: Select all

Traceback (most recent call last):
File "dsb17_multi_gpu_train.py", line 227, in 
tf.app.run()
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/platform/app.py", line 44, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "dsb17_multi_gpu_train.py", line 223, in main
train()
File "dsb17_multi_gpu_train.py", line 129, in train
loss = tower_loss(scope)
File "dsb17_multi_gpu_train.py", line 34, in tower_loss
images, labels = dsb17.inputs(False)
File "/home/ubuntu/dsb17/model/dsb17.py", line 104, in inputs
batch_size=FLAGS.batch_size)
File "/home/ubuntu/dsb17/model/dsb17_input.py", line 161, in inputs
read_input = read_data(filename_queue)
File "/home/ubuntu/dsb17/model/dsb17_input.py", line 62, in read_data
result.image.set_shape([result.height, result.width, result.depth, 1])
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/ops.py", line 425, in set_shape
self._shape = self._shape.merge_with(shape)
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/tensor_shape.py", line 573, in merge_with
other = as_shape(other)
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/tensor_shape.py", line 821, in as_shape
return TensorShape(shape)
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/tensor_shape.py", line 457, in __init__
self._dims = [as_dimension(d) for d in dims_iter]
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/tensor_shape.py", line 457, in 
self._dims = [as_dimension(d) for d in dims_iter]
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/tensor_shape.py", line 378, in as_dimension
return Dimension(value)
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/tensor_shape.py", line 33, in __init__
self._value = int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Tensor'
Ich dachte ursprünglich, dass das daran lag, dass der Tensor keinen Wert hatte, bis er in einer Sitzung ausgewertet wurde, der Verlust jedoch in einem sess.run() ausgewertet wird, was den Aufruf von Tower_loss() erfordert. Mein Trainingscode ist in der Struktur identisch mit cifar10_multi_gpu_train.py und auch die gesamte Dateistruktur ist sehr ähnlich.

Die Frage ist dann: Wird er tatsächlich in einer Sitzung ausgewertet, oder ist das Diagramm noch nicht erstellt? Muss ich irgendwie einen Wert aus dem nulldimensionalen Tensor extrahieren? Allgemeiner ausgedrückt: Welche Missverständnisse habe ich über Tensoren und Sitzungen, die dazu führen, dass mein Code nicht so funktioniert, wie ich es erwartet habe?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post