我想在SSD Keras-TF
中运行TensorRT
模型。
我已经从https://github.com/mashyko/ssd_keras_ver2_1.git下载了SSD源 及其相关的重量文件。
我加载了这些重量文件并运行其测试示例,它运行正常。
我在主机PC中的环境是
Keras 2.2.4
Keras-Applications 1.0.8
Keras-Preprocessing 1.1.0
tensorflow 1.14.0
opencv-python 4.1.1.26
protobuf 3.10.0
我已使用以下代码将重量文件转换为.pb
。
我的代码:
from keras import backend as K
import tensorflow as tf
def freeze_session(session,keep_var_names=None,output_names=None,clear_devices=True):
from tensorflow.python.framework.graph_util import convert_variables_to_constants
graph = session.graph
with graph.as_default():
freeze_var_names = list(set(v.op.name for v in tf.global_variables()).difference(keep_var_names or []))
output_names = output_names or []
output_names += [v.op.name for v in tf.global_variables()]
# Graph -> GraphDef ProtoBuf
input_graph_def = graph.as_graph_def()
if clear_devices:
for node in input_graph_def.node:
node.device = ""
frozen_graph = tf.graph_util.remove_training_nodes(convert_variables_to_constants(session,input_graph_def,output_names,freeze_var_names))
return frozen_graph
frozen_graph = freeze_session(K.get_session(),output_names=[out.op.name for out in model.outputs])
现在,我将该文件复制到TensorRT
示例文件夹(samplesUffSSD
)中,并使用示例配置文件将其转换为UFF
文件,并按照以下链接中提供的步骤进行操作。
https://github.com/NVIDIA/TensorRT/tree/release/6.0/samples/opensource/sampleUffSSD
Nvidia TensorRT
提供的示例应用程序运行正常。
当我尝试使用.pb
文件运行它时,出现以下错误
错误:
[libprotobuf FATAL /externals/protobuf/x86_64/10.0/include/google/protobuf/repeated_field.h:1408] CHECK failed: (index) < (current_size_):
我对TensorRT
还是陌生的,有人可以帮助我解决这个错误。