2017-06-22 72 views
1

這裏是我的代碼 https://gist.github.com/Wermarter/318756a2f4cda35ebb178a932e1f8c38AttributeError的:「張量」對象有「initialized_value」沒有屬性

我試圖用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

+0

你有什麼TF版本?我已經運行你的腳本,我看到「ValueError:不能將部分已知的TensorShape轉換爲張量:(?,784)」我有1.0.1 –

+0

@ S.Stas我正在使用TF 1.2.0。在1.0.1上運行時,它顯示出ValueError(?,784) –

回答

3

上面的錯誤是在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

我測試了這個非錯誤版本1.2.0 TF和它的工作很大 https://gist.github.com/Wermarter/9e0e29ee80adaa0f7af17b72d8e58a67

Click to see the result of 2D MNIST latent space

相關問題