-
Notifications
You must be signed in to change notification settings - Fork 9
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
Export a different resolutions #1
Comments
As most of the models are not capable of running in real time on an iOS device with such large resolutions |
It would be great if you could pass in a desired import resolution also change the aspect ratio from scratch to something more like an 6:4 or 19:9 aspect ratio |
I haven't used other resolutions, but I believe the steps necessary would be: Change the input images for tracing & exporting Say 192 x 320, this would give you the three outputs <1, 3, 85, 40, 24>, <1, 3, 85, 20, 12>, <1, 3, 85, 10, 6>, which need to be processed in order to get confidence and coordinates. The last numbers are just the (width, height) / 8, (width/height) / 16, (width, height) / 32. So divided by the strides. The feature map changes accordingly and now needs two different values for width and height: And change the meta data to use the different width and height values: Pass in here then both width and height: Normalize Values here accordingly: The output changes then as well: Should be 25400 = 3 * (80² + 40² + 20²) and should now be 3 * (4024 + 2012 + 10*6) = 3780 I believe. Please let me know if that works. Also, Pull Requests are welcome! Would be great to make this more customizable by passing the width and height of the pytorch model to the conversion skript.
No problems so far :) The model is a few ms slower than the official from yolov5 in my tests, but with around 20ms per detection it's already reasonable fast I would say. I haven't tested quality differences (see ultralytics/yolov5#2526). |
Thanks for the guidance on how to change it I will have a look at it and will send a PR when I get it working. |
Which models were you testing which got such good performance at higher resolutions? s, m? |
I run the yolov5s models and the results have been quite similar for release 2.0, 3.0, 4.0. I think I also tested it with m, which was about 40ms, but I can't quite remember. I didn't put much effort in it though to optimize it. 700ms is extremly slow. Without optimization the yolov5s model runs slower than > 100ms, but not 600ms or 700ms. As I pointed out in the linked issue, the model doesn't run completly on the Neural Engine by default as it has problems with the pooling layer. You might wanna modify the kernel sizes. Here is some code to get you started: This is just for debugging purposes though. You should obviously fix this in your pytorch model and retrain with the changes. This issue is, as far as I can tell, relevant to the offcial coreml model from yolov5 as well (which uses a smaller resolution). Although it didn't lead to any (noticable) speed improvements, it decreased CPU usage a lot. |
Actually I recently modified the snippets code for some tests to work with the current full (pipeline) model. The current code is just for the "raw" converted model. Not pretty, but does the job.
|
ha ok I will give it a try modifying the kernel sizes, |
@Leon0402 I was wondering how can I add different scales to X and Y they don't see any easy way of achieving this with this method builder.add_scale Sorry for the dumb question I'm new to coreMl and the documentation is not great :/ |
You can specify a shape_scale according to the documentation. So specify the option that suits you and then pass a tuple or list as the scale. Have a look at https://github.com/apple/coremltools/blob/main/mlmodel/format/NeuralNetwork.proto#L27 for a mapping. I'm not quite sure as I haven't worked on my source code lately, but presumably [C,H,W] should be the desired shape. You're right the documentation is improveable and often these functions are not very flexible. In fact there seems to be a new method to actually write coreml neural layers, which is much easier at the first glance. On the other hand the beta of CoreML 4.0 was literally just released when I started working on this. So I didn't want to use too many experimental features, there were already enough bugs in the first version I had to deal with :-) |
Any luck finding the solution for non squared input size. I tried the above steps but it doesn't work.
|
I don't think shape_scale = [3] is valid, at least not according to https://github.com/apple/coremltools/blob/6ec26d282323a4aec33252731e31fdb26569bfb2/coremltools/models/neural_network/builder.py#L2070 What's the error message you get? It would be helpful if you fork the repo and do the changes, then provide here a model where I can test your repo with. This makes it easier to see where you might have done a mistake. |
What would need to be changed so that models can be exported at different resolutions for example 640 to 320
The text was updated successfully, but these errors were encountered: