前提
プログラミングを勉強しているものです。
https://github.com/IDEALLab/bezier-gan
上記のプログラムを実装したいと思っています。
バージョンが違い現在は使われていないコードを書き直したりしてきました(調べながら)
その過程で以下のエラーが発生しました。
実現したいこと
if文ではなくtf.condを使って実装したい
tf.condの使い方を理解できていないため
発生している問題・エラーメッセージ
Traceback (most recent call last): File "C:/Users/phanton/Desktop/namiki_data/bezier-gan/bezier-gan-master/beziergan/train_gan.py", line 60, in <module> model.train(X_train, batch_size=batch_size, train_steps=train_steps, save_interval=args.save_interval, directory=directory) File "C:\Users\phanton\Desktop\namiki_data\bezier-gan\bezier-gan-master\beziergan\gan.py", line 257, in train d_real, _ = self.discriminator(self.x) File "C:\Users\phanton\Desktop\namiki_data\bezier-gan\bezier-gan-master\beziergan\gan.py", line 172, in discriminator strides=(2, 1), padding='same') File "C:\Users\phanton\Desktop\namiki_data\pycharm_env\python3.7\lib\site-packages\keras\dtensor\utils.py", line 96, in _wrap_function init_method(layer_instance, *args, **kwargs) File "C:\Users\phanton\Desktop\namiki_data\pycharm_env\python3.7\lib\site-packages\keras\layers\convolutional\conv2d.py", line 197, in __init__ **kwargs File "C:\Users\phanton\Desktop\namiki_data\pycharm_env\python3.7\lib\site-packages\keras\layers\convolutional\base_conv.py", line 128, in __init__ if filters is not None and filters <= 0: File "C:\Users\phanton\Desktop\namiki_data\pycharm_env\python3.7\lib\site-packages\tensorflow\python\framework\ops.py", line 955, in __bool__ self._disallow_bool_casting() File "C:\Users\phanton\Desktop\namiki_data\pycharm_env\python3.7\lib\site-packages\tensorflow\python\framework\ops.py", line 559, in _disallow_bool_casting "Using a symbolic `tf.Tensor` as a Python `bool`") File "C:\Users\phanton\Desktop\namiki_data\pycharm_env\python3.7\lib\site-packages\tensorflow\python\framework\ops.py", line 543, in _disallow_in_graph_mode f"{task} is not allowed in Graph execution. Use Eager execution or" tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: Using a symbolic `tf.Tensor` as a Python `bool` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.
該当のソースコード
python
1@tf.function 2 3 def generator(self, c, z, reuse=tf.AUTO_REUSE, training=True): 4 5 depth_cpw = 32 * 8 6 dim_cpw = int((self.bezier_degree + 1) / 8) 7 kernel_size = (4, 3) 8 # noise_std = 0.01 9 10 with tf.variable_scope('Generator', reuse=reuse): 11 12 if self.noise_dim == 0: 13 cz = c 14 else: 15 cz = tf.concat([c, z], axis=-1) 16 以下略 17
試したこと
エラー文を調べた結果(グーグル翻訳使って)下記のURL参照
https://www.5axxw.com/questions/content/744fmu
python boolはAutographでは使用できませんと記載されており、
他のサイトでも「Autographはif文を理解できないらしい」という記述がありました。
上記のURLではselfも使ってないけど、これは使えないのではなく簡略化できるから使ってないのかな。。。
まだまだ未熟なためご教授いただけると幸いです。
補足情報(FW/ツールのバージョンなど)
tensorflow 2.11
python 3.7
あなたの回答
tips
プレビュー