leafqycc / rknn-cpp-Multithreading

A simple demo of yolov5s running on rk3588/3588s using c++ (about 142 frames). / 一个使用c++在rk3588/3588s上运行的yolov5s简单demo(142帧/s)。
Apache License 2.0
446 stars 82 forks source link

Running on a custom trained model for yolov5s #46

Open programmeddeath1 opened 4 months ago

programmeddeath1 commented 4 months ago

I tried your demo and it works as is on my opi5. Will the same run for all custom trained models?

I am following the steps in this repo to convert my custom trained model.

The model is converted with the 1.6.0 rknn-toolkit and the conversion code has below changes in models/yolo.py and export.py

  def forward(self, x):
      z = []  # inference output
      for i in range(self.nl):
          if os.getenv('RKNN_model_hack', '0') != '0':
              x[i] = torch.sigmoid(self.m[i](x[i]))  # conv
      return x

====
 import os
  os.environ['RKNN_model_hack'] = 'npu_2'
# shape = tuple((y[0] if isinstance(y, tuple) else y).shape)  # model output shape
 shape = tuple(y[0].shape)

If i run this same conversion on my model with rknn-toolkit 1.5.2 will that custom model run properly with your current multithreading code?

Thanks for your help in advance!

leafqycc commented 4 months ago

I tried your demo and it works as is on my opi5. Will the same run for all custom trained models?

I am following the steps in this repo to convert my custom trained model.

The model is converted with the 1.6.0 rknn-toolkit and the conversion code has below changes in models/yolo.py and export.py

  def forward(self, x):
      z = []  # inference output
      for i in range(self.nl):
          if os.getenv('RKNN_model_hack', '0') != '0':
              x[i] = torch.sigmoid(self.m[i](x[i]))  # conv
      return x

====
 import os
  os.environ['RKNN_model_hack'] = 'npu_2'
# shape = tuple((y[0] if isinstance(y, tuple) else y).shape)  # model output shape
 shape = tuple(y[0].shape)

If i run this same conversion on my model with rknn-toolkit 1.5.2 will that custom model run properly with your current multithreading code?

Thanks for your help in advance!

I tried your demo and it works as is on my opi5. Will the same run for all custom trained models?

I am following the steps in this repo to convert my custom trained model.

The model is converted with the 1.6.0 rknn-toolkit and the conversion code has below changes in models/yolo.py and export.py

  def forward(self, x):
      z = []  # inference output
      for i in range(self.nl):
          if os.getenv('RKNN_model_hack', '0') != '0':
              x[i] = torch.sigmoid(self.m[i](x[i]))  # conv
      return x

====
 import os
  os.environ['RKNN_model_hack'] = 'npu_2'
# shape = tuple((y[0] if isinstance(y, tuple) else y).shape)  # model output shape
 shape = tuple(y[0].shape)

If i run this same conversion on my model with rknn-toolkit 1.5.2 will that custom model run properly with your current multithreading code?

Thanks for your help in advance!

I'm not sure if it can run successfully. You can check the onnx/rknn model network structure at https://netron.app/. It seems that there are some differences between the yolov5s.onnx model in version 1.5.2 and version 1.6.0, which is reflected in whether the model output layer Contains sigmoid layer. If you can run my demo but the prediction results are wrong, you can try to modify lines 184 - 186 of the src/postprocess.cc file to

static float sigmoid(float x) { return x; }

static float unsigmoid(float y) { return y; }