Editing detectnet.py from hello ai world to run a custom model

Hi,

I am currently trying to edit the detectnet.py code given in the tutorial:

My aim is to have it run my own custom trained model instead of ssd-mobilenet

I have made the changes i think neccesary but get the following error:

$ /usr/bin/python3 /home/james/findingfauna_pythonfiles/inference/detectinf_file_file_experimental.py
jetson.inference – detectNet loading build-in network ‘/home/james/jetson-inference/python/training/detection/ssd/models/whale_openimages/1/ssd-mobilenet.onnx’
jetson.inference – detectNet invalid built-in network was requested (’/home/james/jetson-inference/python/training/detection/ssd/models/whale_openimages/1/ssd-mobilenet.onnx’)
Traceback (most recent call last):
File “/home/james/findingfauna_pythonfiles/inference/detectinf_file_file_experimental.py”, line 36, in
net = jetson.inference.detectNet(opt.model, opt.labels, opt.threshold)
Exception: jetson.inference – detectNet invalid built-in network was requested

I dont understand this error as i am not trying to request a built in network im specifying to utilise my own custom model.

My full code is below, the changes made are on lines 20, 21 and 36.

Any advice would be appreciated.

Thanks

import jetson.inference
import jetson.utils
import numpy as np
import argparse
import sys
import os, os.path

image_in = “/home/james/test_input/”
image_out = “/home/james/test_output/anomaly_%i*.jpg”
model_path = “ssd-mobilenet-v2”
custom_model_path = “/home/james/jetson-inference/python/training/detection/ssd/models/whale_openimages/1/ssd-mobilenet.onnx”
custom_labels_path = “/home/james/jetson-inference/python/training/detection/ssd/models/whale_openimages/1/labels.txt”

parse the command line

parser = argparse.ArgumentParser(description=“Locate objects in a live camera stream using an object detection DNN.”)

parser.add_argument(“input_URI”, type=str, default=image_in, nargs=’?’, help=“URI of the input stream”)
parser.add_argument(“output_URI”, type=str, default=image_out, nargs=’?’, help=“URI of the output stream”)
parser.add_argument("–model", type=str, default=custom_model_path, help=“path to your model” )
parser.add_argument("–labels", type=str, default=custom_labels_path, help=“path to your labels” )
parser.add_argument("–network", type=str, default=model_path, help=“pre-trained model to load (see below for options)”)
parser.add_argument("–overlay", type=str, default=“box,labels,conf”, help=“detection overlay flags (e.g. --overlay=box,labels,conf)\nvalid combinations are: ‘box’, ‘labels’, ‘conf’, ‘none’”)
parser.add_argument("–threshold", type=float, default=0.5, help=“minimum detection threshold to use”)

try:
opt = parser.parse_known_args()[0]
except:
print("")
parser.print_help()
sys.exit(0)

load the object detection network

#net = jetson.inference.detectNet(opt.network, sys.argv, opt.threshold)
#net = jetson.inference.detectNet(custom_model_path, custom_labels_path, threshold=0.5)
net = jetson.inference.detectNet(opt.model, opt.labels, opt.threshold)

create video sources & outputs

input = jetson.utils.videoSource(opt.input_URI, argv=sys.argv)
output = jetson.utils.videoOutput(opt.output_URI, argv=sys.argv)

process frames until the user exits

while True:
# capture the next image
img = input.Capture()
print(“this is the image”, img)
# detect objects in the image (with overlay)
detections = net.Detect(img, overlay=opt.overlay)

# print the detections
print("detected {:d} objects in image".format(len(detections)))

for detection in detections:

	print(detection)

# render the image
output.Render(img)

# update the title bar
output.SetStatus("{:s} | Network {:.0f} FPS".format(opt.network, net.GetNetworkFPS()))

# print out performance info
net.PrintProfilerTimes()

# exit on input/output EOS
if not input.IsStreaming() or not output.IsStreaming():
	break

Hi @jeheesom, try changing your code to be like this instead:

net = jetson.inference.detectNet(argv=['--model=/home/james/jetson-inference/python/training/detection/ssd/models/whale_openimages/1/ssd-mobilenet.onnx', '--labels=/home/james/jetson-inference/python/training/detection/ssd/models/whale_openimages/1/labels.txt', '--input-blob=input_0', '--output-cvg=scores', '--output-bbox=boxes'])

worked perfectly thank you