初歩的な質問ですが、ご教授いただけると幸いです。
Kerasを用いてMNISTを予測するAIを作りました。
上記をe-AIで変換しようとすると、「Translation Failure!」のポップが出て変換が失敗します。
ポップには「logを確認するように」と指示がありますが、pathで支持されたフォルダにはlogファイルは出力されていません。
文末に現在の状況の資料を添付させていただきます。
変換ができない理由をご教授いただけないでしょうか。
よろしくお願いいたします。
---------------------
e-AI側の状況の写真を以下に格納しました。
https://drive.google.com/drive/folders/1svVK_Kq3n6LTRSooPNvwPFyI6mY0nfks?usp=sharing
また、モデルを作成したコードは以下のようなものです。
-----*
import kerasfrom keras.datasets import mnistfrom sklearn.model_selection import train_test_splitfrom keras.models import Sequentialfrom keras.layers import Dense, Dropout, Flattenfrom keras.layers import Conv2D, MaxPooling2Dfrom keras.optimizers import RMSprop
(x_train, y_train), (x_test, y_test) = mnist.load_data()x_train1, x_valid, y_train1, y_valid = train_test_split(x_train, y_train, test_size=0.175)
model = Sequential()model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(28, 28, 1)))model.add(Conv2D(64, (3, 3), activation='relu'))model.add(MaxPooling2D(pool_size=(2, 2)))model.add(Flatten())model.add(Dense(128, activation='relu'))model.add(Dense(10, activation='relu'))
# 28 x 28の画像がgrayscaleで1chなので、28, 28, 1にreshapeするx_train = x_train.reshape(x_train.shape[0], 28, 28, 1)x_valid = x_valid.reshape(x_valid.shape[0], 28, 28, 1)x_test = x_test.reshape(x_test.shape[0], 28, 28, 1)
# 0-255の整数値を0〜1の小数に変換するx_train = x_train.astype('float32')x_valid = x_valid.astype('float32')x_test = x_test.astype('float32')x_train /= 255x_valid /= 255x_test /= 255
# one-hot vector形式に変換するy_train = keras.utils.to_categorical(y_train, 10)y_valid = keras.utils.to_categorical(y_valid, 10)y_test = keras.utils.to_categorical(y_test, 10)
model.compile(loss='categorical_crossentropy', optimizer=RMSprop(), metrics=['accuracy'])
history = model.fit(x_train, y_train, batch_size=128, epochs=1, verbose=1, validation_data=(x_valid, y_valid))
model.save("keras3.h5")
----*
<自己追記>
こちらのシンプルなコードでも同様の現象になり変換が失敗しました。
申し訳ありませんがご教授いただけると幸いです。
---------*
import tensorflow as tf
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
x_train = x_train / 255.0x_test = x_test / 255.0
model = tf.keras.models.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(10, activation='softmax')])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)
model.save("keras4.h5")
------------*
panpanpandaさん、こんにちは。スタッフのDartsmanと申します。ご連絡が遅くなりまして申し訳ありませんでした。
こちらでも追記いただいたシンプルなコードでモデルを作成し、e-AIトランスレータ V1.6.0で変換してみたところ、エラー無く変換出来ました。エラーログファイルが生成されない現象も踏まえてセットアップ関連の問題かと思います。https://www.renesas.com/jp/ja/application/technologies/e-ai/tool
上記のサイトよりe-AIトランスレータのUMがダウンロードできますので、特に以下の3項目のインストールに問題が無いかご確認をお願いいたします。・2.3章 Python3.5.3のインストール・2.4章 Python Packageのインストール・2.5章 Microsoft Visual Studio 2015 Visual C++ のインストール
dartsmanさん、お返事いただきありがとうございます。
初歩的なミスで失礼いたしました。
セットアップを行った結果、掲載のエラーはなくなりましたが、異なるエラーが出るようになりました。
本文にlogを添付いたしますので、追加の質問で恐縮なのですが、ご教授いただけないでしょうか。
作成したモデルは<自己追記>のコードをKerasで記述したものです。
以下にモデルのコードを記載いたします。
*==========*
from keras.datasets import mnist
from keras.models import Sequentialfrom keras.layers import Dense, Dropout, Flatten
(x_train, y_train), (x_test, y_test) = mnist.load_data()
model = Sequential()
model.add(Flatten(input_shape=(28, 28)))model.add(Dense(128, activation='relu'))model.add(Dense(10, activation='softmax'))
model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])
model.save("keras20210105_1.h5")
*=================*
translator_05_01_2021.log [2021-01-05 11:10:21,895 INFO network_decoder_tensorflow.py:138 - generate_network() ] The keras model from 'C:\Users\sengi\Desktop\Machine Learning\ADLCatch\TensorFlow\e2\ShinkoShouji\keras' is being converted to protobuf format. [2021-01-05 11:10:21,942 INFO network_decoder_tensorflow.py:204 - generate_network() ] Version: Keras (Keras API with TF backend) : 2.2.4 [2021-01-05 11:10:22,074 ERROR requirements.py:179 - log_exception() ] eAI-501 : Uncaught Exception An unhandled exception has caused this script to terminate prematurely. Here are the details : C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint8 = np.dtype([("qint8", np.int8, 1)]) C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint8 = np.dtype([("quint8", np.uint8, 1)]) C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint16 = np.dtype([("qint16", np.int16, 1)]) C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint16 = np.dtype([("quint16", np.uint16, 1)]) C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint32 = np.dtype([("qint32", np.int32, 1)]) C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. np_resource = np.dtype([("resource", np.ubyte, 1)]) Using TensorFlow backend. Traceback (most recent call last): File ".\bin\network_decoder.py", line 130, in <module> File ".\bin\network_decoder.py", line 102, in generate_network File ".\bin\error_code.py", line 37, in reraise File ".\bin\network_decoder.py", line 100, in generate_network File ".\bin\tensorflow_dep\network_decoder_tensorflow.py", line 208, in generate_network File "C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\engine\saving.py", line 419, in load_model model = _deserialize_model(f, custom_objects, compile) File "C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\engine\saving.py", line 251, in _deserialize_model if weight_names: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() [2021-01-05 11:10:22,074 INFO requirements.py:180 - log_exception() ] Translation FAILED!! [2021-01-05 11:10:22,075 INFO requirements.py:151 - remove_object() ] Uninitializing and cleaning up the translator object..
[2021-01-05 11:10:21,895 INFO network_decoder_tensorflow.py:138 - generate_network() ] The keras model from 'C:\Users\sengi\Desktop\Machine Learning\ADLCatch\TensorFlow\e2\ShinkoShouji\keras' is being converted to protobuf format. [2021-01-05 11:10:21,942 INFO network_decoder_tensorflow.py:204 - generate_network() ] Version: Keras (Keras API with TF backend) : 2.2.4 [2021-01-05 11:10:22,074 ERROR requirements.py:179 - log_exception() ] eAI-501 : Uncaught Exception An unhandled exception has caused this script to terminate prematurely. Here are the details : C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint8 = np.dtype([("qint8", np.int8, 1)]) C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint8 = np.dtype([("quint8", np.uint8, 1)]) C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint16 = np.dtype([("qint16", np.int16, 1)]) C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint16 = np.dtype([("quint16", np.uint16, 1)]) C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint32 = np.dtype([("qint32", np.int32, 1)]) C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. np_resource = np.dtype([("resource", np.ubyte, 1)]) Using TensorFlow backend. Traceback (most recent call last): File ".\bin\network_decoder.py", line 130, in <module> File ".\bin\network_decoder.py", line 102, in generate_network File ".\bin\error_code.py", line 37, in reraise File ".\bin\network_decoder.py", line 100, in generate_network File ".\bin\tensorflow_dep\network_decoder_tensorflow.py", line 208, in generate_network File "C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\engine\saving.py", line 419, in load_model model = _deserialize_model(f, custom_objects, compile) File "C:\Users\sengi\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\engine\saving.py", line 251, in _deserialize_model if weight_names: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() [2021-01-05 11:10:22,074 INFO requirements.py:180 - log_exception() ] Translation FAILED!! [2021-01-05 11:10:22,075 INFO requirements.py:151 - remove_object() ] Uninitializing and cleaning up the translator object..
panpanpandaさん、こんにちは。スタッフのDartsmanです。
今回追記いただいたコードでこちらで再度モデルを作成し、e-AIトランスレータ V1.6.0で変換してみたところ、エラー無く変換出来ました。
また、いただいたエラーログの内容としては例外エラーとなっているので、直接的なエラー要因がログに出力されていませんでした。
ひとまず、こちらで作成したモデルを共有します。
panpanpandaさんの環境でこのモデルファイルを変換可能かどうか試してみていただけないでしょうか?
以下のURLからダウンロードしてください:<https://upload.hdedrive.com/ui/renesas.com/dl/SB1610156864-c58afa23-a523-4f61-9d97-434bfef2c3c6>
* ダウンロードには、ダウンロードパスワードのほかに受け取り認証が必要です。なお、過去に認証済みのブラウザで行う場合は、最大 30 日間認証を省略することができます。
ダウンロードパスワード: nTyy/T/4v+JH
URLの有効期限: 2021年1月23日 10:47 (UTC+09:00)
dartsman様
ご対応いただきありがとうございます。
頂いたファイルで変換したところ、問題なく変換することができました。
しかし、当方の環境で作成した上記の.h5ファイルは変わらずエラーが出てしまいます。
コードが同じにも関わらず変換可否が出るということは、どのような原因が考えられるでしょうか。
model.saveの部分でTRに影響が出る設定というものは存在するでしょうか。
ご連絡ありがとうございます。こちらで作成したモデルファイルが変換できたということなので、
モデルファイルを作成した環境に差分があるのではないかと思います。
こちらでモデル作成時に使用したKerasのバージョンは2.2.4です。
・モデルを作成したPCとe-AIトランスレータを使用したPCが異なる場合、
モデルを作成したPCでもKeras2.2.4を使用するようにしてみていただけますでしょうか?
・モデルを作成したPCとe-AIトランスレータを使用したPCが同じでも、PCに複数のPythonが
インストールされている場合、PythonのバージョンごとにKerasがインストールできるので
注意が必要です。
例として、以下のようなケースであるとします。
- 学習用のスクリプトファイル名:test.py
- Python3.7とPython3.5の両方をインストール
- Python3.7環境にKeras 2.3.1をインストール
- Python3.5環境にKeras 2.2.4をインストール
このケースで「py test.py」とスクリプトを実行するとPython3.7環境のKeras2.3.1で
モデルが作成される可能性がありますので、「py -3.5 test.py」とPythonのバージョンを指定して
学習するようにしてみてください。
Dartsmanさん
ご丁寧にご指導いただきありがとうございます。
ご教授いただいた内容を元にバージョンに気をつけて学習を行いましたが、同様のエラーが出てしまいます。
他に可能性がある原因は何かあるでしょうか。
以下、環境やバージョン等の情報を記載させていただきます。
:-----------------
学習環境:Anaconda環境でJupyter Notebookを使用
Pythonバージョン:3.7.3
Kerasバージョン:2.2.4
バージョン確認方法:
学習コード内で以下のコードを実行。
sys.version
keras.__version__
-----------------:
お手数おかけして申し訳ありませんが、以上よろしくお願いいたします。
ご連絡ありがとうございます。何度もお手数をおかけしてすいません。
Kerasを使用する場合、pythonコンソール上で「import keras」と単独でコマンドを実行すると
「Using TensorFlow backend」とメッセージが返ってくるので、TensorFlowのバージョンも
合わせてみていただけますでしょうか?
こちらではTensorFlow:1.12.0を使用しています。
もし、これでも改善しない場合はご使用の学習環境にインストールされている
ソフトウェアとバージョンの一覧を教えていただけないでしょうか?
Anaconda環境では「conda list」コマンドで一覧が取得できると思います。
以上、よろしくお願いいたします。