How train jetson-inference ssd512 model

Hi there!

I have followed the step by step wrote by @dusty_nv for training and inference of SSD300 model with Jetson Nano. Now I need do the same but with at least 512 resolution. I saw in the config file that there is a variable input_size = 300 but when i set it to 512 or more the program crash startting training phase.

I tryed modifying the specs from

specs = [
SSDSpec(38, 8, SSDBoxSizes(30, 60), [2]),
SSDSpec(19, 16, SSDBoxSizes(60, 111), [2, 3]),
SSDSpec(10, 32, SSDBoxSizes(111, 162), [2, 3]),
SSDSpec(5, 64, SSDBoxSizes(162, 213), [2, 3]),
SSDSpec(3, 100, SSDBoxSizes(213, 264), [2]),
SSDSpec(1, 300, SSDBoxSizes(264, 315), [2])
]

to

specs = [
SSDSpec(32, 16, SSDBoxSizes(20, 35), [2, 3]),
SSDSpec(16, 32, SSDBoxSizes(35, 50), [2, 3]),
SSDSpec(8, 64, SSDBoxSizes(50, 65), [2, 3]),
SSDSpec(4, 100, SSDBoxSizes(195, 240), [2, 3]),
SSDSpec(2, 150, SSDBoxSizes(240, 285), [2, 3]),
SSDSpec(1, 300, SSDBoxSizes(285, 512), [2, 3])
]

following this:

I would like fix it in a correct way. Could we train the ssd with a biggest resolution? i need it for my client, is really important get it because i have little object to detect in a real time video (HD resolution). Thanks!

Hi @camposromeromiguel, what is the exception that you get, or is it a segfault?

I haven’t tried changing the resolution so I’m not sure myself, sorry about that. I may recommend cloning the upstream repo and to try getting it working there first on the training examples they provide, to see if there is any difference.

From that GitHub Issue you linked to, it appears an alternative to increasing the resolution is to just decrease the size of the SSDBoxes to have it detect smaller objects.

This what i get if i modidy the input size of pytorch-ssd/vision/ssd/config/mobilenetv1_ssd_config.py to 512

Hmm that appears to be the same exception as this post. Is that error from before or after you also changed the SSDSpec definitions like here?

Hello @dusty_nv , I have the default values, I share

You need to change those specs to the ones from that post. I gave it a try and confirmed that it trains at 512x512 resolution. I also had to make a slight modification to the ONNX exporter script to pick up the correct resolution to export at.

I pushed the changes to the res-512 branch of pytorch-ssd here:

https://github.com/dusty-nv/pytorch-ssd/tree/res-512
https://github.com/dusty-nv/pytorch-ssd/commit/4ac1cfc18ac9856d247ed6a8f16a7a7de05d5364

Thanks you dusty, i hope improve the result with that. Because i need count the oranges in a farm of oranges. Right now this is the result (640x480 original imagen), really poor accuracy.

left9149

Just a little more question. I readed from the original authors that the ssd 512 has a new conv block. Could be this a possible improve in your code?

I believe something like that was alluded to in the GitHub Issue from above, however I don’t know enough about the internals to add it myself.

After all the help you gave me, I trained perfectly the ssd512 on host with really good acc. About 83% (and increasing). Here a sample:

20200929_112643_left0063

After export the model to ssd512-mb1.onnx, it was moved with the labels.txt in the jetson nano, in the directory

/jetson-inference/python/training/detection/ssd/models

this is the content of labels.txt

BRACKGROUND
orange

And when i try the next command (in the same directory on jetson)

detectnet --model=models/ssd512-mb1.onnx --labels=models/labels.txt
–input-blob=input_0 --output-cvg=scores --output-bbox=boxes
/dev/video2

The model is correctly loaded and my webcam is working, but the program end if catch something and show

Segmentation fault (core dumped)

After this, I tryed the steps by steps of “retrain SSD” and it seems work fine except for this ssd512 model. At the moment I am reinstalling jetson-inference again from source.

Glad you got the model training well! Are you able to run it on a static test image first with detectnet, or it only crashes with camera input?

OK just for sanity, I just tested detectnet inference on a trained ssd512, and was able to run it on a bunch of images without crashing.

Hello @dusty_nv , sorry for late in answer i haven been working in others projects. I tried again to run the model SSD 512 and is running OK!. I suspect that the reason of the error was my USB pendrive. Thanks you for the support

Hi
For the existing ssd-mobilenet 18, does it use 300 x 300? Can I increase the size to 512 x 512.
I don’t need to retrain the model, I just need to detect “person” who is far far away?
Thanks,

Correct, by default it uses 300x300

Even if you increase the size of the camera image, it will always be downscaled to the size that the network was trained on (by default 300x300). So you need to retrain the model if you want it to use 512x512.

1 Like