https://rockyshikoku.medium.com/convert-yolov5-to-coreml-also-add-a-decode-layer-113408b7a848
Convert Yolov5 to CoreML. Also add a decode layer.
How to use Yolov5 on iOS
rockyshikoku.medium.com
이 블로그 글에 따르면 Custom Dataset으로 학습된 Yolov5 모델도 대화형식 코드로 CoreML 모델로 변환가능하다고 한다. 가장 최근에 나온(한달정도 된) Yolov8 버전을 사용하여 쓰고싶지만, 아직 많은 레퍼런스가 없어서 우선 v5모델로 테스트 해본 뒤에 방법을 찾아보면 될듯. 추가적인 정보를 얻게 되면 계속 이어 수정하겠다.
https://colab.research.google.com/drive/1uR738UTlzI7apqeN0qr6mQ5ke_a5SKa8?usp=sharing
YoloV5ToCoreML.ipynb
Colaboratory notebook
colab.research.google.com
Colab에 그대로 있다. 커스텀 모델 학습 후에 구글 드라이브에 옮겨 온 뒤 적혀있는 주석 참고하여 변환하면 될듯! 간단해 보인다.
To convert a custom-trained YOLOv5 model to CoreML, you can follow these steps:
- Export your trained YOLOv5 model to an ONNX format. You can do this by running the following command in the terminal:
python export.py --weights /path/to/weights --img 640 --batch 1 --cfg models/yolov5s.yaml --export onnx/yolov5s.onnx
- Install the CoreMLTools library. You can do this by running the following command in the terminal:
pip install coremltools
- Convert the ONNX model to CoreML format using the CoreMLTools library. You can do this by running the following command in the terminal:
import coremltools as ct
# Convert the ONNX model to CoreML format
model = ct.converters.onnx.convert(
'/path/to/onnx/model',
minimum_ios_deployment_target='13')
# Save the CoreML model to a file
model.save('/path/to/coreml/model')
Note: In the convert
method above, the minimum_ios_deployment_target
argument specifies the minimum iOS version that the CoreML model will be compatible with. You can adjust this value as needed.
That's it! Your custom-trained YOLOv5 model should now be converted to CoreML format and ready to use in your iOS app.
ChatGPT에게도 물어봤는데 두가지 방법 다 사용해보고 검증해보면 될듯! 주요 골자는 표준 포맷인 ONNX 형식으로 변환후 coreml로 바꾸는게 주요 내용이다. 생각보다 간단함!
위 방식을 모두 시도해 봤는데 결국 해결방법은 아래와 같았다. Export.py 파일을 조금 수정하여 NMS(Non-Max Suppression) 적용과 Class 라벨을 전부 직접 추가해주는 식으로. 사용 방법은 그냥 코드 복붙해서 Export_수정.py 로 실행하면 끝임! 매우 간단했지만 이 Git을 찾기 위해 이틀을 썼다.
SOLUTION : https://github.com/junmcenroe/YOLOv5-CoreML-Export-with-NMS
GitHub - junmcenroe/YOLOv5-CoreML-Export-with-NMS
Contribute to junmcenroe/YOLOv5-CoreML-Export-with-NMS development by creating an account on GitHub.
github.com
질의 응답 : https://github.com/ultralytics/yolov5/issues/11207
How to extract bounding box coordinates from a YolovV5 object detection model that has been converted to a CoreML model for use
Search before asking I have searched the YOLOv5 issues and discussions and found no similar questions. Question I have tried it for export !python export.py --weights /content/drive/MyDrive/best.pt...
github.com
https://github.com/ultralytics/yolov5/issues/10483
How to export to CoreML with proper model metadata? · Issue #10483 · ultralytics/yolov5
Search before asking I have searched the YOLOv5 issues and discussions and found no similar questions. Question Hi! I'm trying to export the custom-trained model with just two classes to use with C...
github.com
https://github.com/tucan9389/ObjectDetection-CoreML/issues/6#issuecomment-1235192089