Hi all,
I installed opencv on my jetson tx2 according to jetsonhacks. And I wanted to see the fps that I get on the jetson tx2.
I am making use of the opencv dnn module and a online course titled, object detection using deep learning. Below is the modified code
# USAGE
'''
python deep_learning_with_opencv.py --image images/camel.jpg --prototxt VGG16.prototxt --model VGG.caffemodel --labels synset_words.txt
'''
# import the necessary packages
import numpy as np
import argparse
import cv2
import imutils
import time
from imutils.video import VideoStream
from imutils.video import FPS
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to input image")
ap.add_argument("-p", "--prototxt", required=True,
help="path to Caffe 'deploy' prototxt file")
ap.add_argument("-m", "--model", required=True,
help="path to Caffe pre-trained model")
ap.add_argument("-l", "--labels", required=True,
help="path to ImageNet labels (i.e., syn-sets)")
args = vars(ap.parse_args())
# load the input image from disk
image = cv2.imread(args["image"])
# load the class labels from disk
rows = open(args["labels"]).read().strip().split("\n")
classes = [r[r.find(" ") + 1:].split(",")[0] for r in rows]
# our CNN requires fixed spatial dimensions for our input image(s)
# so we need to ensure it is resized to 224x224 pixels while
# performing mean subtraction (104, 117, 123) to normalize the input;
# after executing this command our "blob" now has the shape:
# (1, 3, 224, 224)
blob = cv2.dnn.blobFromImage(image, 3, (224, 224), (104, 117, 123))
# load our serialized model from disk
print("[INFO] loading model...")
net = cv2.dnn.readNetFromCaffe(args["prototxt"], args["model"])
# set the blob as input to the network and perform a forward-pass to
# obtain our output classification
tic = time.time()
tic1 = time.time()
net.setInput(blob)
preds = net.forward()
toc = time.time()
# sort the indexes of the probabilities in descending order (higher
# probabilitiy first) and grab the top-5 predictions
idxs = np.argsort(preds[0])[::-1][:5]
# loop over the top-5 predictions and display them
for (i, idx) in enumerate(idxs):
# draw the top prediction on the input image
if i == 0:
text = "Label: {}, {:.2f}%".format(classes[idx], preds[0][idx] * 100)
cv2.putText(image, text, (5, 25), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)
# display the predicted label + associated probability to the
# console
print("[INFO] {}. label: {}, probability: {:.5}".format(i + 1, classes[idx], preds[0][idx]))
toc1 = time.time()
print("Inference time %.3f\n" %((toc - tic)))
print("Inference time %.3f\n" %((toc1 - tic1)))
t11= 1/(toc-tic)
print(t11)
# display the output image
cv2.imshow("Image", image)
cv2.waitKey(0)
Now when I tested this on my pc(i7) no dedticated graphic card, I got around 6fps, 0.15 inference time. But when I use the jetson TX2 , I get a pathetic 0.8 fps. Then I checked with the help of sudo ./tegrastats, and I saw that during me running the code, the gpu utilization is constant at GR3D_FREQ 21%@140(try to share screenshot)
Is there something I am doing wrong. How to get the opencv to use gpu. Or is it not even possible.
Any help will be greatly appreciated.
Regards,
Hari.