Need Help Running YOLOv8n-OBB Model on Vim3 (Converted .nb and .so Files)

Which system do you use? Android, Ubuntu, OOWOW or others?

Ubuntu

Which version of system do you use? Please provide the version of the system here:

Ubuntu 22.04

Please describe your issue below:

I have converted the YOLOv8n-OBB model to .nb and .so formats using the AML SDK. Now, I want to run this model on the Vim3 and perform inference, but I am unsure about the process. Could you provide any guidance, demo, or reference project that uses YOLOv8n-OBB on Vim3? A step-by-step tutorial or project link would be greatly appreciated to help me get started.

Hello @Gyanesh ,

I am very sorry that we do not have YOLOv8 OBB demo now. We only have YOLOv8 detect demo.

YOLOv8 OBB model has a new output for box angle. Box part output is the same as YOLOv8 detect model.

Our demo use ultralytics==8.0.86. This version has not OBB model. And now we know a problem that our convert tool covnerting the model by latest ultralytics will report error. So i am not sure that YOLOv8 OBB model can convert.

I have already converted the yolov8n-obb.pt model to .nb and .so. I have used latest ultralytics and while converting the model to onnx it raised me an error. So, I set the opset version to 11 and it worked. I want to take inference of this model on vim3 and need guidance on it.

I can also provide you the versions i am using if your require.

Hello @Gyanesh ,

Could you provide your ultralytics version and your model?

I have added the model and version list in my drive folder. You can check the same.
Drive Link: YOLOv8n-obb - Google Drive

Hello @Gyanesh ,

Your ONNX model miss angle output. Modify class OBB in ultralytics/nn/modules/head.py as follow to add angle output.

     def forward(self, x):
         """Concatenates and returns predicted bounding boxes and class probabilities."""
         bs = x[0].shape[0]  # batch size
-        angle = torch.cat([self.cv4[i](x[i]).view(bs, self.ne, -1) for i in range(self.nl)], 2)  # OBB theta logits
+        if torch.onnx.is_in_onnx_export():
+            angle = [self.cv4[i](x[i]).sigmoid() - 0.25 for i in range(self.nl)]  # OBB theta logits
+            angle = [(angle[i].sigmoid() - 0.25) * math.pi for i in range(self.nl)]  # [-pi/4, 3pi/4]
+        else:
+            angle = torch.cat([self.cv4[i](x[i]).view(bs, self.ne, -1) for i in range(self.nl)], 2)  # OBB theta logits
+            angle = (angle.sigmoid() - 0.25) * math.pi  # [-pi/4, 3pi/4]
         # NOTE: set `angle` as an attribute so that `decode_bboxes` could use it.
-        angle = (angle.sigmoid() - 0.25) * math.pi  # [-pi/4, 3pi/4]
         # angle = angle.sigmoid() * math.pi / 2  # [0, pi/2]
         if not self.training:
             self.angle = angle
         x = Detect.forward(self, x)
         if self.training:
             return x, angle
+        
+        if torch.onnx.is_in_onnx_export():
+            return x, angle
         return torch.cat([x, angle], 1) if self.export else (torch.cat([x[0], angle], 1), (x[1], angle))

Use Netron to open the ONNX model check the output like this.

The box output you can refer YOLOv8 detect model or our YOLOv8n Demo code. They are the same.
YOLOv8n KSNN Demo - 2 [Khadas Docs]

For the angle output, it is the box rotation angle. You need to do rotation transformation for box then do mns for box after rotating.

Your model have trained? I use your model and infer official picture by official codes. But nothing is detected.

Thank you @Louis-Cheng-Liu for your response. I will try the suggested solution and share the results.

For reference, I am using the official YOLOv8n-OBB model provided by Ultralytics.