AttributeError:'Tensor'对象没有属性'initialized_value'

时间:2017-06-22 03:14:04

标签: python tensorflow tflearn

这是我的代码 https://gist.github.com/Wermarter/318756a2f4cda35ebb178a932e1f8c38

我正在尝试用TFLearn实现VAE,但编译器说:

Traceback (most recent call last):
  File "/home/wermarter/Desktop/ChienVAE_RawTF.py", line 107, in <module>
    main()
  File "/home/wermarter/Desktop/ChienVAE_RawTF.py", line 101, in main
    vae = VAE()
  File "/home/wermarter/Desktop/ChienVAE_RawTF.py", line 26, in __init__
    self._build_graph()
  File "/home/wermarter/Desktop/ChienVAE_RawTF.py", line 67, in _build_graph
    self.training_model = tflearn.Trainer(train_ops=trainop, tensorboard_dir=TENSORBOARD_DIR)
  File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tflearn/helpers/trainer.py", line 131, in __init__
    clip_gradients)
  File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tflearn/helpers/trainer.py", line 651, in initialize_training_ops
    ema_num_updates=self.training_steps)
  File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tflearn/summaries.py", line 239, in add_loss_summaries
    loss_averages_op = loss_averages.apply([loss] + other_losses)
  File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tensorflow/python/training/moving_averages.py", line 375, in apply
    colocate_with_primary=(var.op.type in ["Variable", "VariableV2"]))
  File "/home/wermarter/anaconda3/lib/python3.5/site-packages/tensorflow/python/training/slot_creator.py", line 169, in create_zeros_slot
    else array_ops.shape(primary.initialized_value()))
AttributeError: 'Tensor' object has no attribute 'initialized_value'

我已经尝试在github上运行一些例子并且它们运行良好,我认为这不是关于Tensorflow或TFlearn中的错误

1 个答案:

答案 0 :(得分:3)

上面的错误在TF 1.2.0中有点模糊,但在TF 1.0.1中它更清晰

  

ValueError:无法将部分已知的TensorShape转换为Tensor:   (?,784)

这是我的tf.random_normal的问题,其中TF无法理解输入形状(未指定批量大小)。所以我通过创建另一个数字来处理这个问题:

  

batch_size = tf.shape(z_mean)[0]

     

eps = tf.random_normal((batch_size,self.latent_dim))

而不是:

  

eps = tf.random_normal(tf.shape(z_mean))&lt; ====错误

我用TF 1.2.0测试了这个非错误版本并且效果很好 https://gist.github.com/Wermarter/9e0e29ee80adaa0f7af17b72d8e58a67

Click to see the result of 2D MNIST latent space