代码之家  ›  专栏  ›  技术社区  ›  Dinesh

Tensorflow:静态和动态形状

  •  1
  • Dinesh  · 技术社区  · 7 年前

    我有

    shape=tf.shape(net)
    s1=tf.cast(shape[2],tf.int32)
    s2=tf.cast(shape[2]/2,tf.int32)
    a0=tf.random_normal([s1,s2],mean=0.,stdev=1.)
    b0 = tf.get_variable(some_name, initializer=a0)
    

    ValueError: initial_value must have a shape specified:
    

    对于线b0=…,我添加了形状信息:

    b0 = tf.get_variable(some_name, initializer=a0,shape=[s1,s2])
    

    现在我得到了错误:

    If initializer is a constant, do not specify shape.
    

    shape = net.get_shape().as_list()
    

    现在,我得到了错误:

    ValueError: None values not supported.
    

    我经历了: How to understand static shape and dynamic shape in TensorFlow?

    1 回复  |  直到 7 年前
        1
  •  1
  •   P-Gn    7 年前

    您需要指定 validate_shape=False 在争论中 tf.get_variable ,例如

    init = tf.random_normal((s1, s2))
    tf.get_variable(name, initializer=init, validate_shape=False)