kerasでCVAEというAEの一種のモデルを作って、いざ学習させようというところで以下の様なエラーが一気に出てきました。モデルはfanctional APIで書いていきました。まずエラーの意味が分からず困っています。。以下のエラーの文からある程度どの実装のどこに問題があったか判断できますでしょうか?Epoch 1/10という様に学習が始まるところまでいきエラーがでたといった感じです。
------------------追記ーーーーーーーーーーーーーーーーーーーーーーーーー
すみません、確かにinput4は使わないのに宣言していたせいだった様です!
ただ次に以下の様なエラーが出たのですがこれも良くわかりません。
Traceback (most recent call last):
File "training_m2.py", line 83, in <module>
training.compile(optimizer='adam', loss=vaem2.cost)
File "/usr/local/lib/python3.6/site-packages/keras/engine/training.py", line 830, in compile
sample_weight, mask)
File "/usr/local/lib/python3.6/site-packages/keras/engine/training.py", line 429, in weighted
score_array = fn(y_true, y_pred)
File "/Users/tmsmac/Google ドライブ/Python/SemiSupervised/keras-VAE-master/vae_m2.py", line 185, in cost
if np.any(y_true > 0):
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 614, in bool
raise TypeError("Using a tf.Tensor
as a Python bool
is not allowed. "
TypeError: Using a tf.Tensor
as a Python bool
is not allowed. Use if t is not None:
instead of if t:
to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor.
以下にエラーに関連しているだろう部分のコードを載せます。基本的にhttps://github.com/rarilurelo/keras-VAE
こちらのコードを編集しています。
Python
1def cost(self, y_true, y_false): 2 ########### 3 # Labeled # 4 ########### 5 L = 0 6 if np.any(y_true > 0): 7 self.mean, self.var = self.q_z_xy.get_params(givens=[self.x_l, self.y_l]) 8 KL = self._KL(self.mean, self.var) 9 logliklihood = -self.p_x_yz.logliklihood(self.x_l, givens=[self.y_l, self.sampling_z])-self.p_y.logliklihood(self.y_l) 10 L = KL+logliklihood 11 L = L+self.alpha*self.q_y_x.logliklihood(self.y_l, givens=[self.x_l]) 12 13 ############# 14 # UnLabeled # 15 ############# 16 U = 0 17 # marginalization 18 if not np.any(y_true > 0) : 19 y = y_false 20 mean, var = self.q_z_xy.get_params(givens=[self.x_u, y]) 21 sampling_z = self.q_z_xy.sampling(givens=[self.x_u, y]) 22 U += self.q_y_x.prob(y, givens=[self.x_u])*(-self.p_x_yz.logliklihood(self.x_u, givens=[y, sampling_z]) 23 -self.p_y.logliklihood(y) 24 +self._KL(mean, var) 25 +self.q_y_x.logliklihood(y, givens=[self.x_u]) 26 ) 27 return U+L 28 29
Python
1vaem2 = VAEM2() 2training = vaem2.training_model() 3training.compile(optimizer='adam', loss=vaem2.cost)