Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get values from type "jetson.inference.detectNet.Detection" #2214

Closed
Totemi1324 opened this issue Feb 25, 2020 · 14 comments
Closed

How to get values from type "jetson.inference.detectNet.Detection" #2214

Totemi1324 opened this issue Feb 25, 2020 · 14 comments

Comments

@Totemi1324
Copy link

I use DetectNet on my Jetson Nano which works well. The net.Detect() funcion gives back a list where each object is from type "jetson.inference.detectNet.Detection". When I print it:

<detectNet.Detection object>
   -- ClassID: 1
   -- Confidence: 0.808974
   -- Left:    416.31
   -- Top:     218.694
   -- Right:   593.188
   -- Bottom:  703.127
   -- Width:   176.878
   -- Height:  484.433
   -- Area:    85685.7
   -- Center:  (504.749, 460.91)

Now my question is: How can I access these values separately (e.g. only the ClassID which, in this case, would be 1)? Lines like detection[0][0] don't work, since it is not an array. I want to count how many objects of each class were detected. Thanks!

@leandrovrabelo
Copy link

I have the same problem and I still didn't find how to get these values, I want to use these information to create a map.

@leandrovrabelo
Copy link

leandrovrabelo commented Mar 15, 2020

Hi, I jus found out how to capture these values, after creating an object, you access the values on the list calling [0]` and then you grab the variable that you want, see bellow the example:

detections[0].ClassID

the options that you have are: ClassID, Confidence, Left, Right, Width, Height, Bottom, Area and Center.

Leandro.

@Totemi1324
Copy link
Author

Thank you so much for sharing! It's working for me 👍

@OussamaBATOUCHE
Copy link

Hi, I jus found out how to capture these values, after creating an object, you access the values on the list calling [0]` and then you grab the variable that you want, see bellow the example:

detections[0].ClassID

the options that you have are: ClassID, Confidence, Left, Right, Width, Height, Bottom, Area and Center.

Leandro.

please can you help me to find this classId lable ?

@leandrovrabelo
Copy link

After creating an object like detection = net.Detect() you can use a for loop to extract these information:

ids = []
for info in detection:
ids.append(detection[info].ClassID)

If you have many detections in the same images it will show a list of the IDs

@MaahirG
Copy link

MaahirG commented Sep 7, 2020

The coco dataset classIDs are here: [https://tech.amikelive.com/node-718/what-object-categories-labels-are-in-coco-dataset/]

1 = person, 3 = car etc.

This directly corresponds to the ClassID you get in detection[0].ClassID
Hope this helps!

@Jason-xy
Copy link

After creating an object like detection = net.Detect() you can use a for loop to extract these information:

ids = []
for info in detection:
ids.append(detection[info].ClassID)

If you have many detections in the same images it will show a list of the IDs

First, thanks for your answer, but when I tried this it told me ' list indices must be integers or slices, not jetson.inference.detectNet.Detection'. Did you solve this problem?

@leandrovrabelo
Copy link

@Jason-xy could you put all the steps of your code?

@Jason-xy
Copy link

@Jason-xy could you put all the steps of your code?

Thanks for your reply, the following is my code:

net = jetson.inference.detectNet("ssd-mobilenet-v2", threshold=0.5)
camera = jetson.utils.videoSource("csi://0")
display = jetson.utils.videoOutput("display://0") 
info = jetson.utils.cudaFont()
speed=0.0
while display.IsStreaming():
	img = camera.Capture()
	detections = net.Detect(img)
	for i in detections:
		info.OverlayText(img, 5, 5,"speed:{:.2f}".format(speed), detections[i].Bottom, detections[i].Right, info.White, info.Gray40)
	display.Render(img)
	display.SetStatus("Object Detection | Network {:.0f} FPS".format(net.GetNetworkFPS()))

@Jason-xy
Copy link

@Jason-xy could you put all the steps of your code?

Thanks for your reply, I have successfully solved this problem. Because I am not familiar with the syntax of python and made this stupid mistake, the modified code is as follows:

net = jetson.inference.detectNet("ssd-mobilenet-v2", threshold=0.5)
camera = jetson.utils.videoSource("csi://0")
display = jetson.utils.videoOutput("display://0") 
info = jetson.utils.cudaFont()
speed=0.0
while display.IsStreaming():
	img = camera.Capture()
	detections = net.Detect(img)
	for detection in detections:
		info.OverlayText(img, 5, 5,"speed:{:.2f}".format(speed),int(detection.Left)+5, int(detection.Top)+35, info.White, info.Gray40)
	display.Render(img)
	display.SetStatus("Object Detection | Network {:.0f} FPS".format(net.GetNetworkFPS()))

@Ncnguyen-max
Copy link

hi,
how can i print out like this value?
<detectNet.Detection object>
-- ClassID: 1
-- Confidence: 0.808974
-- Left: 416.31
-- Top: 218.694
-- Right: 593.188
-- Bottom: 703.127
-- Width: 176.878
-- Height: 484.433
-- Area: 85685.7
-- Center: (504.749, 460.91)

@Totemi1324
Copy link
Author

hi,
how can i print out like this value?
<detectNet.Detection object>
-- ClassID: 1
-- Confidence: 0.808974
-- Left: 416.31
-- Top: 218.694
-- Right: 593.188
-- Bottom: 703.127
-- Width: 176.878
-- Height: 484.433
-- Area: 85685.7
-- Center: (504.749, 460.91)

Hi, you can print out the individual items of the list returned by net.Detect() if this is what you're looking for.

detections = net.Detect(img)
for detection in detections:
	print(detection)

@Ncnguyen-max
Copy link

hi,
how can i print out like this value?
<detectNet.Detection object>
-- ClassID: 1
-- Confidence: 0.808974
-- Left: 416.31
-- Top: 218.694
-- Right: 593.188
-- Bottom: 703.127
-- Width: 176.878
-- Height: 484.433
-- Area: 85685.7
-- Center: (504.749, 460.91)

Hi, you can print out the individual items of the list returned by net.Detect() if this is what you're looking for.

detections = net.Detect(img)
for detection in detections:
	print(detection)

thanks you so much

@indramal
Copy link

indramal commented Jul 24, 2022

This is code for get Class ID and Class Lable from Jetson Infecrence detectNet.

This will show class label - print(net.GetClassDesc(detection.ClassID))
This will show class ID - print(detection.ClassID)

import jetson.inference
import jetson.utils

net = jetson.inference.detectNet("ssd-mobilenet-v2", threshold=0.5)
camera = jetson.utils.videoSource("v4l2:///dev/video0")
display = jetson.utils.videoOutput("display://0") 
info = jetson.utils.cudaFont()
speed=0.0
while display.IsStreaming():
	img = camera.Capture()
	detections = net.Detect(img)
	for detection in detections:
		print(net.GetClassDesc(detection.ClassID))
		print(detection.ClassID)
		info.OverlayText(img, 5, 5,"speed:{:.2f}".format(speed),int(detection.Left)+5, int(detection.Top)+35, info.White, info.Gray40)
	display.Render(img)
	display.SetStatus("Object Detection | Network {:.0f} FPS".format(net.GetNetworkFPS()))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants