アプリケーション開発ポータルサイト
ServerNote.NET
Amazon.co.jpでPC関連商品タイムセール開催中!
カテゴリー【GooglePython
Google ColaboratoryのTensorFlowバージョンを変更する(1.X←→2.X)
POSTED BY
2023-05-15

Google ColabでTensorFlow/Kerasコードを動かしていると、

TypeError: Cannot convert a symbolic Keras input/output to a numpy array. This error may indicate that you're trying to pass a symbolic value to a NumPy call, which is not supported. Or, you may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model.

のようなエラーが出るときがある。超ざっくばらんに解釈すると今動かしてるTensorFlowじゃそれサポートしてないよと言っているように見える。

こういう場合、TensorFlowのバージョンを1系から2系、またはその逆をしてみると解決する場合がある。

変更方法は以下コードを実行後「メニュー→ランタイム→ランタイムを再起動」すると反映される。

TensorFlow 2.x系をやめて1.x系で動かす

%tensorflow_version 1.x

TensorFlow 1.x系をやめて2.x系で動かす

%tensorflow_version 2.x

確認方法

import tensorflow as tf
print(tf.__version__)
※本記事は当サイト管理人の個人的な備忘録です。本記事の参照又は付随ソースコード利用後にいかなる損害が発生しても当サイト及び管理人は一切責任を負いません。
※本記事内容の無断転載を禁じます。
【WEBMASTER/管理人】
自営業プログラマーです。お仕事ください!
ご連絡は以下アドレスまでお願いします★

☆ServerNote.NETショッピング↓
ShoppingNote / Amazon.co.jp
☆お仲間ブログ↓
一人社長の不動産業務日誌
【キーワード検索】