Привет, все довольно плохо знакомы с Tensorflow и TensorRT, у меня возникли проблемы с преобразованием существующего замороженного графа в граф tenorRT. Я не думаю, что мой код успешно конвертирует мой график. Запуск этого на Nvidia Jetson Nano.
Я пытался следовать рекомендациям, показанным здесь: https://docs.nvidia.com/deeplearning/frameworks/tf-trt-user-guide/index.html#using-frozengraph
def load_object_detection_model(self):
# Load TensorFlow object detection model
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=.5)
EXPORTED_OBJECT_DETECTION_MODEL = 'frozen_model_x.pb'
self.graph_obj = tf.Graph()
with self.graph_obj.as_default():
od_graph_def = tf.GraphDef()
with tf.gfile.GFile(EXPORTED_OBJECT_DETECTION_MODEL, 'rb') as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')
# Optimize Graph with TensorRT
trt_graph = trt.create_inference_graph(
input_graph_def=od_graph_def,
outputs=['num_detections', 'detection_boxes', 'detection_scores', 'detection_classes'],
max_batch_size=1,
max_workspace_size_bytes=4000000000,
precision_mode='FP16')
print('reading graph')
output_node = tf.import_graph_def(
trt_graph,
return_elements=['num_detections', 'detection_boxes', 'detection_scores', 'detection_classes'])
self.graph_obj = output_node # Replace frozen graph with optimized graph
print('converted graph')
Вывод ошибки, которую я получаю: "в load_object_detection_model
ops = self.graph_obj.get_operations ()
AttributeError: у объекта 'list' нет атрибута 'get_operations' ", который соответствует коду ниже:
# get handles to objects in object detection graph
ops = self.graph_obj.get_operations()
all_tensor_names = {output.name for op in ops for output in op.outputs}
self.tensor_dict = {}
for key in [
'num_detections', 'detection_boxes', 'detection_scores',
'detection_classes', 'detection_masks'
]:
tensor_name = key + ':0'
if tensor_name in all_tensor_names:
self.tensor_dict[key] = self.graph_obj.get_tensor_by_name(tensor_name)
self.obj_image_tensor = self.graph_obj.get_tensor_by_name('image_tensor:0')
self.logger.debug('created object detection model graph from {}'.format(EXPORTED_OBJECT_DETECTION_MODEL))
# create session for object detection
self.sess_obj = tf.Session(graph=self.graph_obj)
self.logger.debug('created object detection model session')
(Этот код приведен сразу после предыдущего фрагмента кода).
Запуск Ubuntu 18.04, Python 3.6.8, TensorFlow 1.13.1. Подробности TensorRT ниже:
ii graphsurgeon-tf 5.0.6-1+cuda10.0 arm64 GraphSurgeon for TensorRT package
ii libnvinfer-dev 5.0.6-1+cuda10.0 arm64 TensorRT development libraries and headers
ii libnvinfer-samples 5.0.6-1+cuda10.0 all TensorRT samples and documentation
ii libnvinfer5 5.0.6-1+cuda10.0 arm64 TensorRT runtime libraries
ii python-libnvinfer 5.0.6-1+cuda10.0 arm64 Python bindings for TensorRT
ii python-libnvinfer-dev 5.0.6-1+cuda10.0 arm64 Python development package for TensorRT
ii python3-libnvinfer 5.0.6-1+cuda10.0 arm64 Python 3 bindings for TensorRT
ii python3-libnvinfer-dev 5.0.6-1+cuda10.0 arm64 Python 3 development package for TensorRT
ii tensorrt 5.0.6.3-1+cuda10.0 arm64 Meta package of TensorRT
ii uff-converter-tf 5.0.6-1+cuda10.0 arm64 UFF converter for TensorRT package