AttributeError:“Tensor”对象没有属性“initialized\u value”

2024-10-01 13:40:37 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码 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中的bug


Tags: inpyhomelibpackageslinetrainingsite
1条回答
网友
1楼 · 发布于 2024-10-01 13:40:37

上面的错误在tf1.2.0中有点模糊,但在tf1.0.1中就更清楚了

ValueError: Cannot convert a partially known TensorShape to a Tensor: (?, 784)

这是我的问题tf.random_正常其中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

我用tf1.2.0测试了这个无错误版本,效果非常好 https://gist.github.com/Wermarter/9e0e29ee80adaa0f7af17b72d8e58a67

Click to see the result of 2D MNIST latent space

相关问题 更多 >