AttributeError: 'Tensor' object has no attribute 'initialized_value'

AttributeError: 'Tensor' object has no attribute 'initialized_value'

这是我的代码 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

中的错误无关

上述错误在 TF 1.2.0 中有些模糊,但在 TF 1.0.1 中更清楚

ValueError: Cannot convert a partially known TensorShape to a 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)) <==== Error

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

Click to see the result of 2D MNIST latent space