LoginSignup
0
0

More than 3 years have passed since last update.

TensorFlow 2 メモ: TensorFlow2.0 にTensorFlow-addonsをインストールする

Posted at

画像認識のタスクでデータ拡張(水増し)をするために画像の回転を行いたいが,Tensorflow coreには90度ごとの回転をする関数しか提供されていない.拡張パッケージのTensorFlow addons には tfa.image.rotate() という任意の角度回転できる関数あるので,これをインストールして使いたい.

環境

  • macOs Catalina + Anaconda
  • TensorFlow2.0

問題点

MacのAnacondaを使ってTensorFlowの環境を準備している. mac版Anacondaでは(2020/7/9)の時点でtensorflow-2.0までしか用意されていないらしい(Linuxでは最新の2.2が用意されている).

anacondaのpipを使ってtensorflow-addons(0.10)をインストールすると, インポートしたときにエラーがでる.

import tensorflow as tf
import tensorflow_addons as tfa
/(path)/opt/anaconda3/envs/tf2/lib/python3.7/site-packages/tensorflow_addons/utils/ensure_tf_install.py:68: UserWarning: Tensorflow Addons supports using Python ops for all Tensorflow versions above or equal to 2.2.0 and strictly below 2.3.0 (nightly versions are not supported). 
 The versions of TensorFlow you are currently using is 2.0.0 and is not supported. 
Some things might work, some things might not.
If you were to encounter a bug, do not file an issue.
If you want to make sure you're using a tested and supported configuration, either change the TensorFlow version or the TensorFlow Addons's version. 
You can find the compatibility matrix in TensorFlow Addon's readme:
https://github.com/tensorflow/addons
  UserWarning,
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "(path)/opt/anaconda3/envs/tf2/lib/python3.7/site-packages/tensorflow_addons/__init__.py", line 21, in <module>
    from tensorflow_addons import activations
  File "(path)/opt/anaconda3/envs/tf2/lib/python3.7/site-packages/tensorflow_addons/activations/__init__.py", line 17, in <module>
    from tensorflow_addons.activations.gelu import gelu
  File "(path)/opt/anaconda3/envs/tf2/lib/python3.7/site-packages/tensorflow_addons/activations/gelu.py", line 27, in <module>
    @tf.keras.utils.register_keras_serializable(package="Addons")
AttributeError: module 'tensorflow_core.keras.utils' has no attribute 'register_keras_serializable'

エラーメッセージおよび tensorflow-addons のgithubによると,addonsの最新版はTensorflow2.2対応であり,2.0には対応していないらしい.
これを解消するためには,Tensorflowのバージョンを上げるか,tensorflow-addonsのバージョンを下げるかしかない.

暫定的な解決策 work around

今回はtensorflow-addonsのバージョンを下げる(古いバージョンを入れる)ことで対応した.

pip uninstall tensorflow-addons
pip install tensorflow-addons==0.6

これでエラーはでなくなる.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0