Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Training] Custom trained YOLOv7 network using ONNXRuntime in Java #15107

Closed
meeeee12 opened this issue Mar 18, 2023 · 3 comments
Closed

[Training] Custom trained YOLOv7 network using ONNXRuntime in Java #15107

meeeee12 opened this issue Mar 18, 2023 · 3 comments
Labels
api:Java issues related to the Java API training issues related to ONNX Runtime training; typically submitted using template

Comments

@meeeee12
Copy link

meeeee12 commented Mar 18, 2023

Describe the issue

I am trying to use YOLOv7 to train a custom network and run it with ONNXRuntime in Java but I receive the following error:
ai.onnxruntime.OrtException: This tensor is not representable in Java, it's too big - shape = [0, 7].

When I convert https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt to onnx using the suggested method from the YOLOv7 github page python export.py --weights yolov7-tiny.pt --grid --end2end --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640 --max-wh 640 it works fine. I can also use re-parameterization on https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7_training.pt convert that to onnx and that also works. But when I try using transfer learning on yolov7_training.pt then re-parameterize and convert I receive the error. I have noticed that the working non custom trained versions have a shape of [3, 7]

I have found another issue with the same problem https://github.com/microsoft/onnxruntime/issues/7270 but that appears to be related to not using a square training/inference shape, however I am using a square. Another comment suggested simply changing the '0' value in the shape but I don't know how to do that.

To reproduce

  1. Use the roboflow tutorial to train a custom YOLOv7 network: https://www.youtube.com/watch?v=5nsmXLyDaU4&t=865s&ab_channel=Roboflow (using a public training data set, such as the hard hat one)
  2. Convert custom trained network to onnx using YOLOv7 github page suggested method: python export.py --weights yolov7.pt --grid --end2end --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640 --max-wh 640
  3. Attempt to perform inference using custom trained network with Java version of ONNXRuntime

Urgency

No response

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.13.1

PyTorch Version

Execution Provider

Default CPU

Execution Provider Library Version

No response

@meeeee12 meeeee12 added the training issues related to ONNX Runtime training; typically submitted using template label Mar 18, 2023
@github-actions github-actions bot added the api:Java issues related to the Java API label Mar 18, 2023
@meeeee12 meeeee12 changed the title [Training] Custom trained YOLOv7 network uisng ONNXRuntime in Java [Training] Custom trained YOLOv7 network using ONNXRuntime in Java Mar 18, 2023
@Craigacp
Copy link
Contributor

Craigacp commented Mar 19, 2023

I must have forgot to fix that error message. Python returns an empty array, but Java computes the size value, sees that it is zero, gets confused and throws an exception. Either way there's no actual output, but the exception is rather unfriendly so I'll deal with it.

@Craigacp
Copy link
Contributor

For the time being you can catch that exception as it's only emitted when no objects are detected.

@meeeee12
Copy link
Author

ok, thanks.

yuslepukhin pushed a commit that referenced this issue Apr 5, 2023
)

### Description
Allows the creation of zero length tensors via the buffer path (the
array path with zero length arrays still throws as the validation logic
to check it's not ragged would require more intrusive revision), and
allows the `tensor.getValue()` method to return a Java multidimensional
array with a zero dimension. Also added a test for the creation and
extraction behaviour.

### Motivation and Context
The Python interface can return zero length tensors (e.g. if object
detection doesn't find any objects), and before this PR in Java calling
`tensor.getValue()` throws an exception with a confusing error message.
Fixes #7270 & #15107.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:Java issues related to the Java API training issues related to ONNX Runtime training; typically submitted using template
Projects
None yet
Development

No branches or pull requests

2 participants