Tensorflow to TensorRT [help]

Hi everyone!

New in using Jetson Nano. I’m trying to run a tensorflow model in Jetson Nano real time using this code

import cv2
import numpy as np
import time
import tensorflow as tf
np.set_printoptions(suppress=True)
model = tf.keras.models.load_model(‘effnetv2_model’)
class_names = [‘safe driving’, ‘texting-right’, ‘calling-right’, ‘texting-left’, ‘calling-left’, ‘operating radio’, ‘drinking’, ‘reaching behind’]
size = (224, 224)
pipeline = " ! “.join([“v4l2src device=/dev/video0”,
“video/x-raw, width=640, height=480, framerate=30/1”,
“videoconvert”,
“video/x-raw, format=(string)BGR”,
“appsink”
])
cap = cv2.VideoCapture(pipeline, cv2.CAP_GSTREAMER)
while cap.isOpened():
start = time.time()
ret, img = cap.read()
imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_resized = cv2.resize(imgRGB, size)
img_array = np.asarray(img_resized)
data = tf.expand_dims(img_array, 0)
prediction = model.predict(data)
prediction_score = tf.nn.softmax(prediction[0])
index = np.argmax(prediction_score)
class_name = class_names[index]
confidence_score = prediction[0][index]
end = time.time()
totalTime = end - start
fps = 1 / totalTime
cv2.putText(img, f’FPS: {int(fps)}', (20,450), cv2.FONT_HERSHEY_SIMPLEX, 1.5, (255,0,0), 2)
cv2.putText(img, class_name, (20,50), cv2.FONT_HERSHEY_SIMPLEX, 1.5, (255,0,0), 2)
cv2.putText(img, str(float(”{:.2f}".format(confidence_score*100))) + “%”, (20,100),
cv2.FONT_HERSHEY_SIMPLEX, 1.5, (255,0,0), 2)
cv2.imshow(‘Classification Original’, img)
if cv2.waitKey(5) & 0xFF == 27:
break
cv2.destroyAllWindows()
cap.release()

I was able to run it but in low FPS. I converted my model to tensorrt, how can I run it the same way my tensorflow model does real time? Thank you.

Hi,

Do you use EfficientNet?
If yes, below is an example for your reference:

Thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.