# Tensorflow to TensorRT \[help\]

**URL:** <https://forums.developer.nvidia.com/t/tensorflow-to-tensorrt-help/233490>\
**Category:** Jetson Nano\
**Tags:** tensorflow\
**Created:** [November 11, 2022, 7:40am UTC](https://forums.developer.nvidia.com/t/tensorflow-to-tensorrt-help/233490 "2022-11-11T07:40:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![karldeguzmanai](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@karldeguzmanai](https://forums.developer.nvidia.com/u/karldeguzmanai)\
**Post date:** [November 11, 2022, 7:40am UTC](https://forums.developer.nvidia.com/t/tensorflow-to-tensorrt-help/233490/1 "2022-11-11T07:40:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [November 14, 2022, 3:18am UTC](https://forums.developer.nvidia.com/t/tensorflow-to-tensorrt-help/233490/3 "2022-11-14T03:18:46Z")

</div>

Hi,

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

> **[TensorRT/samples/python/efficientnet at main · NVIDIA/TensorRT](https://github.com/NVIDIA/TensorRT/tree/main/samples/python/efficientnet)**
>
> main/samples/python/efficientnet

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [December 7, 2022, 3:48am UTC](https://forums.developer.nvidia.com/t/tensorflow-to-tensorrt-help/233490/5 "2022-12-07T03:48:51Z")

</div>

Closed on December 7, 2022, 3:48am UTC

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