In W = tf.Variable(tf.random_uniform(shape, -1.0, 0.0))
verwendet habe ich versucht, die folgenden drei Datentypen für shape
:Tensorflow variable und konstante Differenz, wenn für die Form
shape = tf.constant([1]) # 1
shape = [1] # 2
shape = tf.Variable([1]) # 3
Dann rufen I:
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
print(sess.run(W))
Sowohl 1
und 2
Ausgänge richtig, etwas wie [-0.25340891]
. Allerdings gibt 3
mir
ValueError: initial_value must have a shape specified: Tensor("random_uniform:0", shape=(?,), dtype=float32)
Ein vollständiges Codebeispiel:
import tensorflow as tf
import numpy as np
# shape = tf.constant([1]) # 1
# shape = [1] # 2
shape = tf.Variable([1]) # 3
W = tf.Variable(tf.random_uniform(shape, -1.0, 0.0))
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
print(sess.run(W))
Warum sollte dies geschehen?