ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
49.37k stars 16.05k forks source link

Onnx conversion wrong bounding boxes #1000

Closed JonathanLehner closed 3 years ago

JonathanLehner commented 3 years ago

Basically I just used the simple training of the Yolov5, using the Google colab notebook that was provided on the Roboflow.AI website. I then added the conversion to ONNX which seems to be successful. I then tried to use the non_max_suppression script from this repo, which did not work, so I copied the modified non_max_suppression function from an issue here (https://github.com/ultralytics/yolov5/issues/343). It seems to predict the boxes correctly. However, the result in addition has strange bounding boxes inside the predicted bounding boxes. You can replicate it with the modified Google colab https://colab.research.google.com/drive/1RoxIaslU3QDmb9zNc0xrAmcnCK5vMN_7?usp=sharing (you can copy it to run and edit). If the issue gets resolved I would suggest to add the colab to this repo as an example how to do ONNX conversion.

Prediction with original trained model download

Prediction of ONNX model with non_max_suppression from Github issue download (2)

github-actions[bot] commented 3 years ago

Hello @JonathanLehner, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook Open In Colab, Docker Image, and Google Cloud Quickstart Guide for example environments.

If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom model or data training question, please note Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:

For more information please visit https://www.ultralytics.com.

JonathanLehner commented 3 years ago

I changed the order of the anchors (which was hinted in the other issue, but not very clear).

anchors = [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]]

Results: download (5)

download (3)

Feel free to use my notebook to see how it works!

Rajesh-mandal commented 2 years ago

Basically I just used the simple training of the Yolov5, using the Google colab notebook that was provided on the Roboflow.AI website. I then added the conversion to ONNX which seems to be successful. I then tried to use the non_max_suppression script from this repo, which did not work, so I copied the modified non_max_suppression function from an issue here (#343). It seems to predict the boxes correctly. However, the result in addition has strange bounding boxes inside the predicted bounding boxes. You can replicate it with the modified Google colab https://colab.research.google.com/drive/1RoxIaslU3QDmb9zNc0xrAmcnCK5vMN_7?usp=sharing (you can copy it to run and edit). If the issue gets resolved I would suggest to add the colab to this repo as an example how to do ONNX conversion.

Prediction with original trained model download

Prediction of ONNX model with non_max_suppression from Github issue download (2)

i am getting correct result when i am inferencing with bes.pt but when i inferencing with converted best.onnx i am getting very bad result.. can you what could be the reason.. is my model didn't converted well ?? or i am doing something wrong while inferencing. best.onnx inferening result. image

best.pt inferencing result image

code i used for conversion from best.pt to best.onnx import torch import onnx

from models.common import *

weights = "/content/drive/MyDrive/New folder/best.pt" img_size = [640, 640] batch_size = 1 f = weights.replace('.pt', '.onnx') img = torch.zeros((batch_size, 3, *img_size)) google_utils.attempt_download(weights) model = torch.load(weights, maplocation=torch.device('cpu'))['model'] model.eval() model.fuse() print('=============') model.model[-1].export = True # set Detect() layer export=True = model(img) # dry run torch.onnx.export(model, img, f, verbose=False, opset_version=11, input_names=['images'], output_names=['output'])

can you please help to get out of this problem

Rajesh-mandal commented 2 years ago

message i got during model conversion.. is model converted correctly?? graph torch-jit-export ( %images[FLOAT, 1x3x640x640] ) initializers ( %model.0.conv.conv.weight[FLOAT, 32x12x3x3] %model.0.conv.conv.bias[FLOAT, 32] %model.1.conv.weight[FLOAT, 64x32x3x3] %model.1.conv.bias[FLOAT, 64] %model.2.cv1.conv.weight[FLOAT, 32x64x1x1] %model.2.cv1.conv.bias[FLOAT, 32] %model.2.cv2.conv.weight[FLOAT, 64x32x3x3] %model.2.cv2.conv.bias[FLOAT, 64] %model.3.conv.weight[FLOAT, 128x64x3x3] %model.3.conv.bias[FLOAT, 128] %model.4.cv1.conv.weight[FLOAT, 64x128x1x1] %model.4.cv1.conv.bias[FLOAT, 64] %model.4.cv2.weight[FLOAT, 64x128x1x1] %model.4.cv3.weight[FLOAT, 64x64x1x1] %model.4.cv4.conv.weight[FLOAT, 128x128x1x1] %model.4.cv4.conv.bias[FLOAT, 128] %model.4.bn.weight[FLOAT, 128] %model.4.bn.bias[FLOAT, 128] %model.4.bn.running_mean[FLOAT, 128] %model.4.bn.running_var[FLOAT, 128] %model.4.m.0.cv1.conv.weight[FLOAT, 64x64x1x1] %model.4.m.0.cv1.conv.bias[FLOAT, 64] %model.4.m.0.cv2.conv.weight[FLOAT, 64x64x3x3] %model.4.m.0.cv2.conv.bias[FLOAT, 64] %model.4.m.1.cv1.conv.weight[FLOAT, 64x64x1x1] %model.4.m.1.cv1.conv.bias[FLOAT, 64] %model.4.m.1.cv2.conv.weight[FLOAT, 64x64x3x3] %model.4.m.1.cv2.conv.bias[FLOAT, 64] %model.4.m.2.cv1.conv.weight[FLOAT, 64x64x1x1] %model.4.m.2.cv1.conv.bias[FLOAT, 64] %model.4.m.2.cv2.conv.weight[FLOAT, 64x64x3x3] %model.4.m.2.cv2.conv.bias[FLOAT, 64] %model.5.conv.weight[FLOAT, 256x128x3x3] %model.5.conv.bias[FLOAT, 256] %model.6.cv1.conv.weight[FLOAT, 128x256x1x1] %model.6.cv1.conv.bias[FLOAT, 128] %model.6.cv2.weight[FLOAT, 128x256x1x1] %model.6.cv3.weight[FLOAT, 128x128x1x1] %model.6.cv4.conv.weight[FLOAT, 256x256x1x1] %model.6.cv4.conv.bias[FLOAT, 256] %model.6.bn.weight[FLOAT, 256] %model.6.bn.bias[FLOAT, 256] %model.6.bn.running_mean[FLOAT, 256] %model.6.bn.running_var[FLOAT, 256] %model.6.m.0.cv1.conv.weight[FLOAT, 128x128x1x1] %model.6.m.0.cv1.conv.bias[FLOAT, 128] %model.6.m.0.cv2.conv.weight[FLOAT, 128x128x3x3] %model.6.m.0.cv2.conv.bias[FLOAT, 128] %model.6.m.1.cv1.conv.weight[FLOAT, 128x128x1x1] %model.6.m.1.cv1.conv.bias[FLOAT, 128] %model.6.m.1.cv2.conv.weight[FLOAT, 128x128x3x3] %model.6.m.1.cv2.conv.bias[FLOAT, 128] %model.6.m.2.cv1.conv.weight[FLOAT, 128x128x1x1] %model.6.m.2.cv1.conv.bias[FLOAT, 128] %model.6.m.2.cv2.conv.weight[FLOAT, 128x128x3x3] %model.6.m.2.cv2.conv.bias[FLOAT, 128] %model.7.conv.weight[FLOAT, 512x256x3x3] %model.7.conv.bias[FLOAT, 512] %model.8.cv1.conv.weight[FLOAT, 256x512x1x1] %model.8.cv1.conv.bias[FLOAT, 256] %model.8.cv2.conv.weight[FLOAT, 512x1024x1x1] %model.8.cv2.conv.bias[FLOAT, 512] %model.9.cv1.conv.weight[FLOAT, 256x512x1x1] %model.9.cv1.conv.bias[FLOAT, 256] %model.9.cv2.weight[FLOAT, 256x512x1x1] %model.9.cv3.weight[FLOAT, 256x256x1x1] %model.9.cv4.conv.weight[FLOAT, 512x512x1x1] %model.9.cv4.conv.bias[FLOAT, 512] %model.9.bn.weight[FLOAT, 512] %model.9.bn.bias[FLOAT, 512] %model.9.bn.running_mean[FLOAT, 512] %model.9.bn.running_var[FLOAT, 512] %model.9.m.0.cv1.conv.weight[FLOAT, 256x256x1x1] %model.9.m.0.cv1.conv.bias[FLOAT, 256] %model.9.m.0.cv2.conv.weight[FLOAT, 256x256x3x3] %model.9.m.0.cv2.conv.bias[FLOAT, 256] %model.9.m.1.cv1.conv.weight[FLOAT, 256x256x1x1] %model.9.m.1.cv1.conv.bias[FLOAT, 256] %model.9.m.1.cv2.conv.weight[FLOAT, 256x256x3x3] %model.9.m.1.cv2.conv.bias[FLOAT, 256] %model.10.cv1.conv.weight[FLOAT, 256x512x1x1] %model.10.cv1.conv.bias[FLOAT, 256] %model.10.cv2.weight[FLOAT, 256x512x1x1] %model.10.cv3.weight[FLOAT, 256x256x1x1] %model.10.cv4.conv.weight[FLOAT, 512x512x1x1] %model.10.cv4.conv.bias[FLOAT, 512] %model.10.bn.weight[FLOAT, 512] %model.10.bn.bias[FLOAT, 512] %model.10.bn.running_mean[FLOAT, 512] %model.10.bn.running_var[FLOAT, 512] %model.10.m.0.cv1.conv.weight[FLOAT, 256x256x1x1] %model.10.m.0.cv1.conv.bias[FLOAT, 256] %model.10.m.0.cv2.conv.weight[FLOAT, 256x256x3x3] %model.10.m.0.cv2.conv.bias[FLOAT, 256] %model.11.weight[FLOAT, 33x512x1x1] %model.11.bias[FLOAT, 33] %model.14.conv.weight[FLOAT, 256x768x1x1] %model.14.conv.bias[FLOAT, 256] %model.15.cv1.conv.weight[FLOAT, 128x256x1x1] %model.15.cv1.conv.bias[FLOAT, 128] %model.15.cv2.weight[FLOAT, 128x256x1x1] %model.15.cv3.weight[FLOAT, 128x128x1x1] %model.15.cv4.conv.weight[FLOAT, 256x256x1x1] %model.15.cv4.conv.bias[FLOAT, 256] %model.15.bn.weight[FLOAT, 256] %model.15.bn.bias[FLOAT, 256] %model.15.bn.running_mean[FLOAT, 256] %model.15.bn.running_var[FLOAT, 256] %model.15.m.0.cv1.conv.weight[FLOAT, 128x128x1x1] %model.15.m.0.cv1.conv.bias[FLOAT, 128] %model.15.m.0.cv2.conv.weight[FLOAT, 128x128x3x3] %model.15.m.0.cv2.conv.bias[FLOAT, 128] %model.16.weight[FLOAT, 33x256x1x1] %model.16.bias[FLOAT, 33] %model.19.conv.weight[FLOAT, 128x384x1x1] %model.19.conv.bias[FLOAT, 128] %model.20.cv1.conv.weight[FLOAT, 64x128x1x1] %model.20.cv1.conv.bias[FLOAT, 64] %model.20.cv2.weight[FLOAT, 64x128x1x1] %model.20.cv3.weight[FLOAT, 64x64x1x1] %model.20.cv4.conv.weight[FLOAT, 128x128x1x1] %model.20.cv4.conv.bias[FLOAT, 128] %model.20.bn.weight[FLOAT, 128] %model.20.bn.bias[FLOAT, 128] %model.20.bn.running_mean[FLOAT, 128] %model.20.bn.running_var[FLOAT, 128] %model.20.m.0.cv1.conv.weight[FLOAT, 64x64x1x1] %model.20.m.0.cv1.conv.bias[FLOAT, 64] %model.20.m.0.cv2.conv.weight[FLOAT, 64x64x3x3] %model.20.m.0.cv2.conv.bias[FLOAT, 64] %model.21.weight[FLOAT, 33x128x1x1] %model.21.bias[FLOAT, 33] %387[FLOAT, 4] %388[FLOAT, 4] %389[INT64, 1] %390[INT64, 1] %391[INT64, 1] %392[INT64, 1] %393[INT64, 1] %394[INT64, 1] ) { %141 = Constant[value = ]() %142 = Constant[value = ]() %143 = Constant[value = ]() %144 = Constant[value = ]() %145 = Slice(%images, %142, %143, %141, %144) %146 = Constant[value = ]() %147 = Constant[value = ]() %148 = Constant[value = ]() %149 = Constant[value = ]() %150 = Slice(%145, %147, %148, %146, %149) %151 = Constant[value = ]() %152 = Constant[value = ]() %153 = Constant[value = ]() %154 = Constant[value = ]() %155 = Slice(%images, %152, %153, %151, %154) %156 = Constant[value = ]() %157 = Constant[value = ]() %158 = Constant[value = ]() %159 = Constant[value = ]() %160 = Slice(%155, %157, %158, %156, %159) %161 = Constant[value = ]() %162 = Constant[value = ]() %163 = Constant[value = ]() %164 = Constant[value = ]() %165 = Slice(%images, %162, %163, %161, %164) %166 = Constant[value = ]() %167 = Constant[value = ]() %168 = Constant[value = ]() %169 = Constant[value = ]() %170 = Slice(%165, %167, %168, %166, %169) %171 = Constant[value = ]() %172 = Constant[value = ]() %173 = Constant[value = ]() %174 = Constant[value = ]() %175 = Slice(%images, %172, %173, %171, %174) %176 = Constant[value = ]() %177 = Constant[value = ]() %178 = Constant[value = ]() %179 = Constant[value = ]() %180 = Slice(%175, %177, %178, %176, %179) %181 = Concat[axis = 1](%150, %160, %170, %180) %182 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [1, 1]](%181, %model.0.conv.conv.weight, %model.0.conv.conv.bias) %183 = LeakyRelualpha = 0.100000001490116 %184 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [2, 2]](%183, %model.1.conv.weight, %model.1.conv.bias) %185 = LeakyRelualpha = 0.100000001490116 %186 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%185, %model.2.cv1.conv.weight, %model.2.cv1.conv.bias) %187 = LeakyRelualpha = 0.100000001490116 %188 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [1, 1]](%187, %model.2.cv2.conv.weight, %model.2.cv2.conv.bias) %189 = LeakyRelualpha = 0.100000001490116 %190 = Add(%185, %189) %191 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [2, 2]](%190, %model.3.conv.weight, %model.3.conv.bias) %192 = LeakyRelualpha = 0.100000001490116 %193 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%192, %model.4.cv1.conv.weight, %model.4.cv1.conv.bias) %194 = LeakyRelualpha = 0.100000001490116 %195 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%194, %model.4.m.0.cv1.conv.weight, %model.4.m.0.cv1.conv.bias) %196 = LeakyRelualpha = 0.100000001490116 %197 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [1, 1]](%196, %model.4.m.0.cv2.conv.weight, %model.4.m.0.cv2.conv.bias) %198 = LeakyRelualpha = 0.100000001490116 %199 = Add(%194, %198) %200 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%199, %model.4.m.1.cv1.conv.weight, %model.4.m.1.cv1.conv.bias) %201 = LeakyRelualpha = 0.100000001490116 %202 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [1, 1]](%201, %model.4.m.1.cv2.conv.weight, %model.4.m.1.cv2.conv.bias) %203 = LeakyRelualpha = 0.100000001490116 %204 = Add(%199, %203) %205 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%204, %model.4.m.2.cv1.conv.weight, %model.4.m.2.cv1.conv.bias) %206 = LeakyRelualpha = 0.100000001490116 %207 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [1, 1]](%206, %model.4.m.2.cv2.conv.weight, %model.4.m.2.cv2.conv.bias) %208 = LeakyRelualpha = 0.100000001490116 %209 = Add(%204, %208) %210 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%209, %model.4.cv3.weight) %211 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%192, %model.4.cv2.weight) %212 = Concat[axis = 1](%210, %211) %213 = BatchNormalization[epsilon = 9.99999974737875e-05, momentum = 0.970000028610229](%212, %model.4.bn.weight, %model.4.bn.bias, %model.4.bn.running_mean, %model.4.bn.running_var) %214 = LeakyRelualpha = 0.100000001490116 %215 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%214, %model.4.cv4.conv.weight, %model.4.cv4.conv.bias) %216 = LeakyRelualpha = 0.100000001490116 %217 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [2, 2]](%216, %model.5.conv.weight, %model.5.conv.bias) %218 = LeakyRelualpha = 0.100000001490116 %219 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%218, %model.6.cv1.conv.weight, %model.6.cv1.conv.bias) %220 = LeakyRelualpha = 0.100000001490116 %221 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%220, %model.6.m.0.cv1.conv.weight, %model.6.m.0.cv1.conv.bias) %222 = LeakyRelualpha = 0.100000001490116 %223 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [1, 1]](%222, %model.6.m.0.cv2.conv.weight, %model.6.m.0.cv2.conv.bias) %224 = LeakyRelualpha = 0.100000001490116 %225 = Add(%220, %224) %226 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%225, %model.6.m.1.cv1.conv.weight, %model.6.m.1.cv1.conv.bias) %227 = LeakyRelualpha = 0.100000001490116 %228 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [1, 1]](%227, %model.6.m.1.cv2.conv.weight, %model.6.m.1.cv2.conv.bias) %229 = LeakyRelualpha = 0.100000001490116 %230 = Add(%225, %229) %231 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%230, %model.6.m.2.cv1.conv.weight, %model.6.m.2.cv1.conv.bias) %232 = LeakyRelualpha = 0.100000001490116 %233 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [1, 1]](%232, %model.6.m.2.cv2.conv.weight, %model.6.m.2.cv2.conv.bias) %234 = LeakyRelualpha = 0.100000001490116 %235 = Add(%230, %234) %236 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%235, %model.6.cv3.weight) %237 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%218, %model.6.cv2.weight) %238 = Concat[axis = 1](%236, %237) %239 = BatchNormalization[epsilon = 9.99999974737875e-05, momentum = 0.970000028610229](%238, %model.6.bn.weight, %model.6.bn.bias, %model.6.bn.running_mean, %model.6.bn.running_var) %240 = LeakyRelualpha = 0.100000001490116 %241 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%240, %model.6.cv4.conv.weight, %model.6.cv4.conv.bias) %242 = LeakyRelualpha = 0.100000001490116 %243 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [2, 2]](%242, %model.7.conv.weight, %model.7.conv.bias) %244 = LeakyRelualpha = 0.100000001490116 %245 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%244, %model.8.cv1.conv.weight, %model.8.cv1.conv.bias) %246 = LeakyRelualpha = 0.100000001490116 %247 = MaxPoolceil_mode = 0, kernel_shape = [5, 5], pads = [2, 2, 2, 2], strides = [1, 1] %248 = MaxPoolceil_mode = 0, kernel_shape = [9, 9], pads = [4, 4, 4, 4], strides = [1, 1] %249 = MaxPoolceil_mode = 0, kernel_shape = [13, 13], pads = [6, 6, 6, 6], strides = [1, 1] %250 = Concat[axis = 1](%246, %247, %248, %249) %251 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%250, %model.8.cv2.conv.weight, %model.8.cv2.conv.bias) %252 = LeakyRelualpha = 0.100000001490116 %253 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%252, %model.9.cv1.conv.weight, %model.9.cv1.conv.bias) %254 = LeakyRelualpha = 0.100000001490116 %255 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%254, %model.9.m.0.cv1.conv.weight, %model.9.m.0.cv1.conv.bias) %256 = LeakyRelualpha = 0.100000001490116 %257 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [1, 1]](%256, %model.9.m.0.cv2.conv.weight, %model.9.m.0.cv2.conv.bias) %258 = LeakyRelualpha = 0.100000001490116 %259 = Add(%254, %258) %260 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%259, %model.9.m.1.cv1.conv.weight, %model.9.m.1.cv1.conv.bias) %261 = LeakyRelualpha = 0.100000001490116 %262 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [1, 1]](%261, %model.9.m.1.cv2.conv.weight, %model.9.m.1.cv2.conv.bias) %263 = LeakyRelualpha = 0.100000001490116 %264 = Add(%259, %263) %265 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%264, %model.9.cv3.weight) %266 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%252, %model.9.cv2.weight) %267 = Concat[axis = 1](%265, %266) %268 = BatchNormalization[epsilon = 9.99999974737875e-05, momentum = 0.970000028610229](%267, %model.9.bn.weight, %model.9.bn.bias, %model.9.bn.running_mean, %model.9.bn.running_var) %269 = LeakyRelualpha = 0.100000001490116 %270 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%269, %model.9.cv4.conv.weight, %model.9.cv4.conv.bias) %271 = LeakyRelualpha = 0.100000001490116 %272 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%271, %model.10.cv1.conv.weight, %model.10.cv1.conv.bias) %273 = LeakyRelualpha = 0.100000001490116 %274 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%273, %model.10.m.0.cv1.conv.weight, %model.10.m.0.cv1.conv.bias) %275 = LeakyRelualpha = 0.100000001490116 %276 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [1, 1]](%275, %model.10.m.0.cv2.conv.weight, %model.10.m.0.cv2.conv.bias) %277 = LeakyRelualpha = 0.100000001490116 %278 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%277, %model.10.cv3.weight) %279 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%271, %model.10.cv2.weight) %280 = Concat[axis = 1](%278, %279) %281 = BatchNormalization[epsilon = 9.99999974737875e-05, momentum = 0.970000028610229](%280, %model.10.bn.weight, %model.10.bn.bias, %model.10.bn.running_mean, %model.10.bn.running_var) %282 = LeakyRelualpha = 0.100000001490116 %283 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%282, %model.10.cv4.conv.weight, %model.10.cv4.conv.bias) %284 = LeakyRelualpha = 0.100000001490116 %285 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%284, %model.11.weight, %model.11.bias) %289 = Constant[value = ]() %290 = Resize[coordinate_transformation_mode = 'asymmetric', cubic_coeff_a = -0.75, mode = 'nearest', nearest_mode = 'floor'](%284, %289, %387) %291 = Concat[axis = 1](%290, %242) %292 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%291, %model.14.conv.weight, %model.14.conv.bias) %293 = LeakyRelualpha = 0.100000001490116 %294 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%293, %model.15.cv1.conv.weight, %model.15.cv1.conv.bias) %295 = LeakyRelualpha = 0.100000001490116 %296 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%295, %model.15.m.0.cv1.conv.weight, %model.15.m.0.cv1.conv.bias) %297 = LeakyRelualpha = 0.100000001490116 %298 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [1, 1]](%297, %model.15.m.0.cv2.conv.weight, %model.15.m.0.cv2.conv.bias) %299 = LeakyRelualpha = 0.100000001490116 %300 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%299, %model.15.cv3.weight) %301 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%293, %model.15.cv2.weight) %302 = Concat[axis = 1](%300, %301) %303 = BatchNormalization[epsilon = 9.99999974737875e-05, momentum = 0.970000028610229](%302, %model.15.bn.weight, %model.15.bn.bias, %model.15.bn.running_mean, %model.15.bn.running_var) %304 = LeakyRelualpha = 0.100000001490116 %305 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%304, %model.15.cv4.conv.weight, %model.15.cv4.conv.bias) %306 = LeakyRelualpha = 0.100000001490116 %307 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%306, %model.16.weight, %model.16.bias) %311 = Constant[value = ]() %312 = Resize[coordinate_transformation_mode = 'asymmetric', cubic_coeff_a = -0.75, mode = 'nearest', nearest_mode = 'floor'](%306, %311, %388) %313 = Concat[axis = 1](%312, %216) %314 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%313, %model.19.conv.weight, %model.19.conv.bias) %315 = LeakyRelualpha = 0.100000001490116 %316 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%315, %model.20.cv1.conv.weight, %model.20.cv1.conv.bias) %317 = LeakyRelualpha = 0.100000001490116 %318 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%317, %model.20.m.0.cv1.conv.weight, %model.20.m.0.cv1.conv.bias) %319 = LeakyRelualpha = 0.100000001490116 %320 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [1, 1, 1, 1], strides = [1, 1]](%319, %model.20.m.0.cv2.conv.weight, %model.20.m.0.cv2.conv.bias) %321 = LeakyRelualpha = 0.100000001490116 %322 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%321, %model.20.cv3.weight) %323 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%315, %model.20.cv2.weight) %324 = Concat[axis = 1](%322, %323) %325 = BatchNormalization[epsilon = 9.99999974737875e-05, momentum = 0.970000028610229](%324, %model.20.bn.weight, %model.20.bn.bias, %model.20.bn.running_mean, %model.20.bn.running_var) %326 = LeakyRelualpha = 0.100000001490116 %327 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%326, %model.20.cv4.conv.weight, %model.20.cv4.conv.bias) %328 = LeakyRelualpha = 0.100000001490116 %329 = Conv[dilations = [1, 1], group = 1, kernel_shape = [1, 1], pads = [0, 0, 0, 0], strides = [1, 1]](%328, %model.21.weight, %model.21.bias) %330 = Shape(%329) %331 = Constant[value = <Scalar Tensor []>]() %332 = Gather[axis = 0](%330, %331) %333 = Shape(%329) %334 = Constant[value = <Scalar Tensor []>]() %335 = Gather[axis = 0](%333, %334) %336 = Shape(%329) %337 = Constant[value = <Scalar Tensor []>]() %338 = Gather[axis = 0](%336, %337) %341 = Unsqueezeaxes = [0] %344 = Unsqueezeaxes = [0] %345 = Unsqueezeaxes = [0] %346 = Concat[axis = 0](%341, %389, %390, %344, %345) %347 = Reshape(%329, %346) %output = Transposeperm = [0, 1, 3, 4, 2] %349 = Shape(%307) %350 = Constant[value = <Scalar Tensor []>]() %351 = Gather[axis = 0](%349, %350) %352 = Shape(%307) %353 = Constant[value = <Scalar Tensor []>]() %354 = Gather[axis = 0](%352, %353) %355 = Shape(%307) %356 = Constant[value = <Scalar Tensor []>]() %357 = Gather[axis = 0](%355, %356) %360 = Unsqueezeaxes = [0] %363 = Unsqueezeaxes = [0] %364 = Unsqueezeaxes = [0] %365 = Concat[axis = 0](%360, %391, %392, %363, %364) %366 = Reshape(%307, %365) %367 = Transposeperm = [0, 1, 3, 4, 2] %368 = Shape(%285) %369 = Constant[value = <Scalar Tensor []>]() %370 = Gather[axis = 0](%368, %369) %371 = Shape(%285) %372 = Constant[value = <Scalar Tensor []>]() %373 = Gather[axis = 0](%371, %372) %374 = Shape(%285) %375 = Constant[value = <Scalar Tensor []>]() %376 = Gather[axis = 0](%374, %375) %379 = Unsqueezeaxes = [0] %382 = Unsqueezeaxes = [0] %383 = Unsqueezeaxes = [0] %384 = Concat[axis = 0](%379, %393, %394, %382, %383) %385 = Reshape(%285, %384) %386 = Transposeperm = [0, 1, 3, 4, 2] return %output, %367, %386 } Export complete. ONNX model saved to /content/drive/MyDrive/modelselection/Detector/ocr_runs/best.onnx View with https://github.com/lutzroeder/netron

glenn-jocher commented 2 years ago

@JonathanLehner @Rajesh-mandal ONNX export and inference run correctly with export.py and detect.py. You can use this verified workflow as a starting point for your own custom workflows.

python export.py --weights yolov5s.pt --include onnx
python detect.py --weights yolov5s.onnx