Tell someone a solution to the problem of launching a YOLOv3 model through a TensorRT. I converted weights to tensorrt:

[i]import cv2

import time

import numpy as np

import tensorflow as tf

import tensorflow.contrib.tensorrt as trt

from tensorflow.python.platform import gfile

from PIL import Image

from YOLOv3 import utils

print(‘Done. All lib loaded’)

# function to read a “.pb” model

# (can be used to read frozen model or TensorRT model)

def read_pb_return_tensors(graph, pb_file, return_elements):

```
with tf.gfile.FastGFile(pb_file, 'rb') as f:
frozen_graph_def = tf.GraphDef()
frozen_graph_def.ParseFromString(f.read())
with graph.as_default():
return_elements = tf.import_graph_def(frozen_graph_def,
return_elements=return_elements)
input_tensor, output_tensors = return_elements[0], return_elements[1:]
return input_tensor, output_tensors
```

def read_pb_graph(model):

with gfile.FastGFile(model,‘rb’) as f:

graph_def = tf.GraphDef()

graph_def.ParseFromString(f.read())

return graph_def

# config

SIZE = [416, 416] #input image dimension

video_path = ‘/home/nvidia/Загрузки/Rewind - Pedestrians.mp4’

classes = utils.read_coco_names(’./YOLOv3/coco.names’)

num_classes = len(classes)

TENSORRT_YOLOv3_MODEL = “./model/TensorRT_YOLOv3_2.pb” # to use the TensorRT optimized model

print(‘Model is load’)

# get input-output tensor

input_tensor, output_tensors = read_pb_return_tensors(tf.get_default_graph(), TENSORRT_YOLOv3_MODEL, [“Placeholder:0”, “concat_9:0”, “mul_9:0”])

[/i]

Then I try to run the model in a tensorflow session:

with tf.Session (config = tf.ConfigProto (gpu_options = tf.GPUOptions (per_process_gpu_memory_fraction = 0.5))) as sess:

print (‘Read from video’)

vid = cv2.VideoCapture (video_path)

while true:

return_value, frame = vid.read ()

But the process is killed - the memory is full.

What can I do wrong?

P.S. I took the startup examples in this repository https://github.com/ardianumam/Tensorflow-TensorRT