Nag*_*S N 5 python python-3.x tensorflow tf.keras
我已经将一个预训练模型保存为ckpt文件(元,索引...),并且正在使用tf.train.import_meta_graph()和加载图形tf.train.Saver.restore()。我也有来自的resnet50模型tf.keras.applications。我需要将resnet模型的输出提供给从磁盘加载的模型。我该如何实现?
码:
resnet_model = ResNet50(include_top=False, pooling='avg')
preprocessed_video = preprocess_input(tf.cast(video, tf.float32))
features = self.resnet_model([preprocessed_video])
sess1 = tf.Session()
saver = tf.train.import_meta_graph(model_path.as_posix() + '.meta')
graph = tf.get_default_graph()
saver.restore(sess1, model_path.as_posix())
input_x = graph.get_tensor_by_name('input/Identity:0')
result = graph.get_tensor_by_name('output/Identity:0')
Run Code Online (Sandbox Code Playgroud)
我需要给features到input_x和得到result。请注意,这必须在构建图形时发生,而不是在运行时发生sess.run。我的意思是,不是全部video,features而是全部。所以我不能用tensorsnumpy.ndarraysess.run
编辑1:
在此答案中,我可以解决如下问题:
preprocessed_video = preprocess_input(tf.cast(video, tf.float32))
features = self.resnet_model([preprocessed_video])
sess1 = tf.Session()
saver = tf.train.import_meta_graph(model_path.as_posix() + '.meta', input_map={'input/Identity:0': features})
graph = tf.get_default_graph()
saver.restore(sess1, model_path.as_posix())
quality_score = graph.get_tensor_by_name('output/Identity:0')
Run Code Online (Sandbox Code Playgroud)
谢谢jdehesa
| 归档时间: |
|
| 查看次数: |
34 次 |
| 最近记录: |