ultralytics / hub

Ultralytics HUB tutorials and support
https://hub.ultralytics.com
GNU Affero General Public License v3.0
138 stars 14 forks source link

export coreml format from hub like yolov8n.coreml? #907

Open hanrw opened 2 weeks ago

hanrw commented 2 weeks ago

Search before asking

Question

according to the doc https://docs.ultralytics.com/hub/integrations/#exports export CoreML from hub should be with mlpackage format but actually yolov8n.coreml image

and if so how to use yolov8n.coreml from like a ios app?

CoreML coreml yolo11n.mlpackage imgsz, half, int8, nms, batch

CoreML coreml yolo11n.mlpackage ✅ imgsz, half, int8, nms, batch

Additional

No response

UltralyticsAssistant commented 2 weeks ago

👋 Hello @hanrw, thank you for raising your issue about the Ultralytics HUB 🚀! We appreciate your feedback and will make sure an Ultralytics engineer looks into this soon.

In the meantime, you might find the following resources helpful for better understanding and utilizing CoreML exports:

If this is a 🐛 Bug Report regarding the export format, please provide screenshots and steps to reproduce the problem to assist us in diagnosing the issue more efficiently.

If you have a ❓ Question about using yolov8n.coreml in iOS apps, please include more details about your environment and use-case so we can provide more specific guidance.

We aim to address all concerns promptly. Thank you for your patience and understanding!

saserbest commented 2 weeks ago

+1 downloaded models only work after renaming them to .mlmodel

pderrenger commented 2 weeks ago

Hello @saserbest! Thank you for your input and for sharing your experience with the CoreML model exports. 😊

It seems like you've encountered a situation where the exported models need to be renamed to .mlmodel to work correctly. This might be due to a discrepancy in the expected file format for CoreML models.

To address this, please ensure you're using the latest version of the Ultralytics HUB and related packages, as updates often include important fixes and improvements. If the issue persists, renaming the file as you've done is a practical workaround.

For using these models in iOS apps, once renamed to .mlmodel, you can integrate them using Xcode. Here's a brief guide:

  1. Add the Model to Your Xcode Project: Drag the .mlmodel file into your Xcode project navigator.
  2. Compile the Model: Xcode will automatically compile the .mlmodel file into a .mlmodelc directory, which is optimized for use in your app.
  3. Use the Model in Your Code: You can then use the model in your Swift or Objective-C code. Here's a simple Swift example:

    import CoreML
    
    guard let model = try? YOLOv8n(configuration: MLModelConfiguration()) else {
       fatalError("Failed to load model")
    }
    
    // Use the model for predictions

If you continue to experience issues or have further questions, feel free to reach out. We're here to help! 🚀

hanrw commented 2 weeks ago

Hi @pderrenger, thanks for your response. I had a custom model trained from the YOLOv11s model, but it encountered an error after I renamed it to .mlmodel.

image

and compared with the official YOLO11 model

image

looks custom corelml model small than the official one.

it's works when use CLI to convert it from pytorch model which is downloaded from hub and size around 37.8 mb yolo export model=model_2_november_2024_17_18.pt format=mlmodel nms=true optimize=true

but format=coreml with same size(around 17.5 mb) as it's download from hub and got same error yolo export model=model_2_november_2024_17_18.pt format=coreml nms=true optimize=true

pderrenger commented 2 weeks ago

Hello @hanrw! Thank you for reaching out and sharing the details of your experience with exporting your custom YOLOv11s model. 😊

It seems like you're encountering an issue with the CoreML model size and functionality after exporting from the Ultralytics HUB. Let's address this step-by-step:

  1. Model Size Discrepancy: The difference in size between the official YOLO model and your custom model could be due to various factors, including the model architecture, layers, and optimizations applied during export. The official models might include additional metadata or configurations that aren't present in custom models.

  2. Export Process: When using the CLI to export your model, ensure that all necessary parameters are correctly set. The nms=true and optimize=true flags are useful for optimizing the model for performance, but they might also affect the model size and compatibility.

  3. Error Handling: If you're encountering errors after renaming the model to .mlmodel, it might be related to the export process or the model's compatibility with CoreML. Double-check that the export command is correctly configured and that you're using the latest version of the Ultralytics packages. This ensures any known issues are addressed in the latest updates.

  4. CLI Export Example: Here's a refined example of the export command you can use:

    yolo export model=model_2_november_2024_17_18.pt format=coreml nms=true optimize=true

    Ensure that the model file path and export parameters are correct.

  5. Reproducibility: If the issue persists, please verify that it is reproducible with the latest versions of the Ultralytics packages. This helps us identify if it's a bug that needs addressing.

If you continue to face challenges, feel free to provide more details or screenshots of the error messages. We're here to help you get your model running smoothly! 🚀

Thank you for your patience and for being part of the YOLO community. Your feedback is invaluable in helping us improve our tools and services.

hanrw commented 2 weeks ago

Hi @pderrenger , i had already tried yolo export model=model_2_november_2024_17_18.pt format=coreml nms=true optimize=true but format=coreml with same size(around 17.5 mb) as it's download from hub and got same error

pderrenger commented 2 weeks ago

Hello @hanrw! Thank you for your patience and for providing more details about the issue you're facing. 😊

It sounds like you're encountering a persistent issue with the CoreML export, even after using the CLI command. Let's try a few more steps to troubleshoot and resolve this:

  1. Verify Latest Versions: First, please ensure that you are using the latest version of the Ultralytics package. You can update it using pip:

    pip install ultralytics --upgrade

    This ensures that any recent fixes or improvements are applied.

  2. Check Export Parameters: Double-check the parameters used during export. Sometimes, specific configurations might affect the export process. Ensure that the nms and optimize flags are set correctly.

  3. Model Compatibility: If the issue persists, it might be related to the model architecture or specific layers that are not fully compatible with CoreML. Consider simplifying the model architecture or checking for any unsupported layers.

  4. Debugging: If possible, try exporting a smaller or simpler model to see if the issue is specific to your custom model. This can help isolate the problem.

  5. Community Support: Feel free to engage with the Ultralytics community on our Discord server. Other users might have faced similar issues and could offer insights or solutions.

If the problem continues, please let us know if there are any specific error messages or logs that could provide more context. We're here to help, and your feedback is invaluable in improving our tools. Thank you for being part of the YOLO community! 🚀