Object Detection with Pytorch

Jimmy_2times: <p>Hello<br>
I’m a beginner in DNN. I’m using Jetson Nano.<br>
I managed to do transfer learning on a ResNet-18 model with my custom dataset for object detection. It seems quite straight forward with Pytorch.</p>
<p>What I’m struggling with is the deployment of my model.</p>
<p>My question is simple: Is it possible to deploy the model that I trained in Pytorch and run object detection inference on it? Or do I absolutely need to export it to some other format such as Caffe?</p>
<p>It it is possible to do it in Pytorch, and if so, is there a sample code in Python?</p>
<p>Thanks!</p>

smth: <p>if you are using Jetson Nano, you can directly run the model trained in PyTorch on the Nano.</p>
<p>If you want to speed the model up on Nano, you can use something like <a href="https://github.com/NVIDIA-AI-IOT/torch2trt">https://github.com/NVIDIA-AI-IOT/torch2trt</a> to offload part of the model to TensorRT</p>

smth: <p>here are links to pytorch binaries on Jetson platforms: <a href="https://github.com/pytorch/pytorch#nvidia-jetson-platforms">https://github.com/pytorch/pytorch#nvidia-jetson-platforms</a></p>

Jimmy_2times: <p>hey thanks for a quick reply smth.<br>
When you say “if you are using Jetson Nano, you can directly run the model trained in PyTorch on the Nano.” what libraries/modules shall I use?<br>
Do you mean I have to use the .pth file without converting it to ONNX? Could you be a bit more specific?</p>

smth: <p>just use pytorch directly, without converting to ONNX. it runs on jetson nano.</p>

Jimmy_2times: <p>That’s great to know that it’s possible!!<br>
Could you direct me to a specific snippet, piece of code or something written in Python so I can take it from there?</p>

smth: <aside class="quote no-group" data-username="Jimmy_2times" data-post="1" data-topic="81405">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/jimmy_2times/48/24286_2.png" class="avatar"> Jimmy_2times:</div>
<blockquote>
<p>I managed to do transfer learning on a ResNet-18 model with my custom dataset for object detection. It seems quite straight forward with Pytorch.</p>
</blockquote>
</aside>
<p>seems like you already have some code?</p>
<p>either ways, feel free to use something like <a href="https://pytorch.org/hub/pytorch_vision_deeplabv3_resnet101/" class="inline-onebox">Deeplabv3 | PyTorch</a></p>
<p>there might be some samples at <a href="https://github.com/NVIDIA-AI-IOT" class="inline-onebox">NVIDIA AI IOT · GitHub</a></p>

Jimmy_2times: <p>I took the code from Jetson Inference examples, which was meant for transfer learning and used it to train on my dataset.<br>
But I didn’t have any code to run the inference.<br>
I will look into the code you sent me. I really appreciate it!!</p>

Jimmy_2times: <p>Hi Smth. I tried DEEPLABV3-RESNET101. It works very well!<br>
Except this is segmentation, and I don’t know how to build a bounding box around the drawn mask over the detected object.</p>
<p>Could you please show me an example that actually draws the bounding boxes around the detected object?</p>
<p>Thanks again!!</p>

Jimmy_2times: <p>I just realized that Resnet18 is not for object detection but for image classification.<br>
Since I need Object Detection, I will have to write a new script to train for instance Faster RCNN.</p>