前提・実現したいこと
anaconda promptで、仮想環境を作ってtensorflow とtensorflowjs をpipでインストールした後、ニューラルネットワークによる学習のコード(以下に添付)を実行したところ、以下の警告が発生した。
発生している問題・エラーメッセージ
H5pyDeprecationWarning: The default file mode will change to 'r' (read-only) in h5py 3.0. To suppress this warning, pass the mode you need to h5py.File(), or set the global default h5.get_config().default_file_mode, or set the environment variable H5PY_DEFAULT_READONLY=1. Available modes are: 'r', 'r+', 'w', 'w-'/'x', 'a'. See the docs for details. return h5py.File(h5file)
該当のソースコード
import numpy as np import tensorflow as tf from tensorflow import keras def get_data(): fashion_mnist = keras.datasets.fashion_mnist (train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data() train_images = train_images / 255.0 test_images = test_images / 255.0 return(train_images, train_labels, test_images, test_labels) def create_model(): model = keras.Sequential([ keras.layers.Flatten(input_shape=(28, 28)), keras.layers.Dense(128, activation='relu'), keras.layers.Dense(10, activation='softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) return model (train_images, train_labels, test_images, test_labels) = get_data() model = create_model() model.fit(train_images, train_labels, epochs=5) test_loss, test_acc = model.evaluate(test_images, test_labels) print('\n') print('Test accuracy: {}\n'.format(test_acc)) test_input = np.zeros(28 * 28).reshape((1, 28, 28)) predictions = model.predict(test_input) print('Predictions for zero input') print(predictions[0]) model.save_weights('model') print() print('Model was saved.')
import numpy as np import tensorflow as tf from tensorflow import keras import tensorflowjs as tfjs def create_model(): model = keras.Sequential([ keras.layers.Flatten(input_shape=(28, 28)), keras.layers.Dense(128, activation='relu'), keras.layers.Dense(10, activation='softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) return model model = create_model() model.load_weights('model') test_input = np.zeros(28 * 28).reshape((1, 28, 28)) predictions = model.predict(test_input) print() print('Predictions for zero input') print(predictions[0]) tfjs.converters.save_keras_model(model, "model") print() print('Model was exported.')
試したこと
githubで調べ、それらしいものがあったが、自分の力では理解できなかった。
補足情報(FW/ツールのバージョンなど)
python 3.8.5
tensorflow 2.3.1
OSはwindows10