アプリケーション開発ポータルサイト
ServerNote.NET
Amazon.co.jpでPC関連商品タイムセール開催中!
カテゴリー【PythonGoogle
TensorFlow公式のチュートリアルを進める(2)
POSTED BY
2023-01-03
Google TensorFlowバージョン2 の公式チュートリアルをすすめるメモ(1)

続きです。

映画レビューのテキスト分類
https://www.tensorflow.org/tutorials/keras/text_classification?hl=ja

★出現したエラー

<string>:6: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/datasets/imdb.py:159: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
  x_train, y_train = np.array(xs[:idx]), np.array(labels[:idx])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/datasets/imdb.py:160: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
  x_test, y_test = np.array(xs[idx:]), np.array(labels[idx:])

★解決法

Warningであるため以後の実行に支障は無かったのでそのままとした。

TensorFlowハブによるテキスト分類:映画レビュー
https://www.tensorflow.org/tutorials/keras/text_classification_with_hub?hl=ja

★追加モジュールのインストール

sudo pip3 install tfds-nightly
sudo pip3 install tensorflow-hub

★出現したエラー:なし

回帰:燃費を予測する
https://www.tensorflow.org/tutorials/keras/regression?hl=ja

★追加モジュールのインストール

sudo pip3 install seaborn

★出現したエラー:なし

過学習と学習不足について知る
https://www.tensorflow.org/tutorials/keras/overfit_and_underfit?hl=ja

★出現したエラー

<string>:6: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/datasets/imdb.py:159: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
  x_train, y_train = np.array(xs[:idx]), np.array(labels[:idx])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/datasets/imdb.py:160: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
  x_test, y_test = np.array(xs[idx:]), np.array(labels[idx:])

★解決法

Warningであるため以後の実行に支障は無かったのでそのままとした。
しかしながらこの章のサンプルの「より小さいモデルの構築~より大きなモデルの構築」のところで、しばしばNotebookのフリーズ&リスタートが見られた。
いったんCtrl-Cでノートブックを終了し、ブラウザを閉じ、ノートブックを再起動してまた1から実行し直したら、問題無くなった。

モデルの保存と復元
https://www.tensorflow.org/tutorials/keras/save_and_load?hl=ja

★追加モジュールのインストール

sudo pip3 install pyyaml h5py

★出現したエラー

# my_model ディレクトリ
ls saved_model

# assets フォルダと saved_model.pb, variables フォルダが含まれる
ls saved_model/my_model

File "<ipython-input-15-017179a2f945>", line 2
    ls saved_model
                 ^
SyntaxError: invalid syntax

★解決法

# my_model ディレクトリ
%ls saved_model

# assets フォルダと saved_model.pb, variables フォルダが含まれる
%ls saved_model/my_model

OSコマンドには%を付与する。このへんはColab Notebookとの違いか。

Kerasチューナーの紹介
https://www.tensorflow.org/tutorials/keras/keras_tuner?hl=ja

★追加モジュールのインストール

sudo pip3 install keras-tuner

★出現したエラー

特に無し。最後の「ハイパーパラメータ検索を実行」が時間がかかり画面上無限ループ出力のように見えるが、待っていればちゃんと終わる。

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

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