1
私はGPUマシンで訓練されたTensorFLowモデルを持っています。次に、それをエクスポートし、CPUのみのプロダクションマシンにデプロイする必要があります。TensorFlowでエクスポートされたモデルをロード
MNIST export exampleに記載されているようにエクスポートを使用しました。 Saverオブジェクトは上記で初期化されました。
with graph.as_default():
saver = tf.train.Saver(tf.all_variables(), sharded=True)
...
export_path = 'resnet34_rmsprop_wd1e-1/saves/'
print('Exporting trained model to %s' % export_path)
init_op = tf.group(tf.initialize_all_tables(), name='init_op')
model_exporter = exporter.Exporter(saver)
model_exporter.init(sess.graph.as_graph_def(),
init_op=init_op,
default_graph_signature=exporter.classification_signature(input_tensor=inference_images,
classes_tensor=inference_class,
scores_tensor=inference_predictions),
named_graph_signatures={'inputs': exporter.generic_signature({'images': inference_images}),
'outputs': exporter.generic_signature({'class': inference_class, 'predictions': inference_predictions})})
model_exporter.export(export_path, tf.constant(1), sess)
print('Done exporting!')
次に、私が一緒に保存モデルをロードしようとしています:
new_saver = tf.train.import_meta_graph('assets/saved_model/export.meta')
new_saver.restore(sess, 'assets/saved_model/export')
そして、何私が取得していますと、次のとおりです。
エラーの理由は何Traceback (most recent call last):
File "script_test_classifier.py", line 4, in <module>
...
line 33, in __initialize_session__
new_saver = tf.train.import_meta_graph('assets/saved_model/export.meta')
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1711, in import_meta_graph
read_meta_graph_file(meta_graph_or_file), clear_devices)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1598, in _import_meta_graph_def
input_graph_def, name="", producer_op_list=producer_op_list)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/importer.py", line 258, in import_graph_def
op_def = op_dict[node.op]
KeyError: u'SaveV2'
とどのようにそれができました修正される?
さらに、TensorFlowモデルをPythonにインポートする他の方法がありますか?
TFを最新バージョンに更新しようとしました。それはまだ助けにはならなかった、 "KeyError:u'SaveV2" –