Colaboratoryでtensorflow 1系へのサポートが終わっていたので、2系に書き換えた。
TecoGAN
TecoGANについてはこちらから
https://qiita.com/kannkyo/items/4d515ca988f536fadf44
Tensorflow 2系への書き換え
自動書き換え
まずは1系から2系への自動アップデートスクリプトを行った。
https://www.tensorflow.org/guide/migrate?hl=ja
lib/ops.py
とmain.py
が対象となる
!tf_upgrade_v2 \
--intree ./ \
--outtree ./ \
--reportfile report.txt
!tf_upgrade_v2 \
--intree ./lib/ \
--outtree ./lib/ \
--reportfile report_lib.txt
ただ、これだけだと動かないので色々書き換える
手動書き換え
上記で直りきらなかった部分を治していった結果を覚えている限り書く
tf_slim
tensorflow.contrib.slim
が無くなっていた。調べたところ新たにtf_slim
に置き換わったみたいなので、こちらに書き換えた。該当コードはmain.py
の21行目あたりとlib/ops.py
の2行目
+ import tf_slim as slim
- import tensorflow.contrib.slim as slim
もちろんtf_slim
はインストール
!pip install tf_slim
tensorflow_addons
tensorflow.contrib
が2系から無くなったみたいなので、どこに移行されたのか調べていたらここに行きついた。該当コードは216行目当たり
https://www.tensorflow.org/addons/api_docs/python/tfa/image/dense_image_warp
+ import tensorflow_addons as tfa
+ pre_warp_hi = tfa.image.dense_image_warp(pre_gen, gen_flow)
- pre_warp_hi = tf.contrib.image.dense_image_warp(pre_gen, gen_flow)
eager execution を無効化
eager executionの意味を調べたところ切実な実行らしい。このままだと
inputs_raw = tf.compat.v1.placeholder(tf.float32, shape=input_shape, name='inputs_raw')
のところでエラーが生じる。tf.compat.v1
は2系で無理矢理1系を使う形だから切実に実行しようとするとダメ?
import tensorflow_addons as tfa
+ tf.compat.v1.disable_eager_execution()
これを追加してeager execution を無効化する。
結果
coraboratoryでtecoGANを動かせた!