前提
2019/6/20 追記
tensorflowを使って画像判別マシンを作成しました。
元のコードは以下より
https://github.com/tensorflow/models
/models-master/tutorials/image/imagenet を引用・参考にしながら作成しています。
この学習済のプログラムをweb上で使用できるようにしたく、方法を探っていました。
最終的な完成イメージは以下のようなものです
https://github.com/octocatz/tensorflow4cat
環境
- 使用OS: Mac
- Python 3.6.4
- Tensorflow 1.13.1
問題
webでこのTensorflowを使用するにはtensorflow.jsを使えばできる、
それを使えるようにするにはこのpythonデータをKerasモデルという形式にて保存しなければいけない、とわかり、
なんとか今まで書いてきたプログラムを変換する手段を探っていましたが、うまくできません。
もともとKerasを使って書いたものではないため、
おそらく何かが欠けているのだと思われるのですが…。
試したこと
Kerasモデルへの変換
こちらとTFの公式ページを参考にしつつ、モデルの書き出しを行うべく、
retrain.py
の最終行に以下を追記して実行してみました
import tensorflowjs as tfjs tfjs.converters.save_keras_model(model, tfjs_target_dir)
が、
from tensorflow.python.eager import monitoring
ImportError: cannot import name 'monitoring'
from tensorflow import estimator
ImportError: cannot import name 'estimator'
の2つのエラーが返ってきました…。
それ以前の問題として考えられること
- tensorflowjsがうまくインストールできていない?
途中まではうまくいっているようですが、最後に以下のエラーが現れます。
```
Installing collected packages: numpy, wrapt, tf-nightly-2.0-preview, tensorflowjs
Found existing installation: numpy 1.16.4
Uninstalling numpy-1.16.4:
Successfully uninstalled numpy-1.16.4
Found existing installation: wrapt 1.10.11
ERROR: Cannot uninstall 'wrapt'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
実際、`pip list`に出てきません - **そもそも変換しようとしているプログラムファイルを作り直すべき?** お恥ずかしながら「モデル」という概念についてよく理解できていません。 しかし、いま変換しようとしているのはKerasモデルではないのは確かだと思うので… --- **追記** →pipで入れていたTensorflowを一旦アンインストールし、condaで再インストールしました。 condaでtfjsに入り、そこでtensorflowjsをインストールすると、エラー内容が変わりました
Could not find a version that satisfies the requirement tf-nightly-2.0-preview==2.0.0.dev20190605 (from tensorflowjs) (from versions: )
No matching distribution found for tf-nightly-2.0-preview==2.0.0.dev20190605 (from tensorflowjs)
この`tf-nightly`をインストしようとしていますが、以下の有様です。
Could not find a version that satisfies the requirement tf-nightly-2.0-preview==2.0.0.dev20190605 (from versions: )
No matching distribution found for tf-nightly-2.0-preview==2.0.0.dev20190605
ちなみに最新版pip install tf-nightly-2.0-previewもトライしましたが同様でした。 どうかお知恵をお貸しください。
あなたの回答
tips
プレビュー