YOLO26 모델용 CoreML 내보내기
Apple은 최신 iPhone, iPad 및 Mac에 전용 AI 실리콘인 Neural Engine을 탑재하며, CoreML은 현재 Ultralytics에서 해당 장치에 모델을 배포하기 위해 지원하는 경로입니다. Ultralytics YOLO26 모델을 CoreML로 내보내면 학습된 .pt 체크포인트가 네이티브 .mlpackage으로 변환됩니다. 이 형식은 네트워크 연결이나 기기 외부로의 데이터 전송 없이, 낮은 지연 시간으로 7가지 YOLO 작업을 모두 기기에서 실행합니다.
공식 Ultralytics YOLO iOS SDK와 Flutter 플러그인은 CoreML 내보내기 모델을 Apple Neural Engine에서 바로 실행합니다. 실시간 카메라 추론, 단일 이미지 예측 및 Depth를 포함한 7가지 YOLO26 작업 모두에 대한 자동 모델 다운로드를 지원합니다. Android NPU 배포는 Qualcomm QNN 통합을 참조하세요.
분류 모델은 imgsz=224에서 내보냅니다. 탐지, 세그멘테이션, 시맨틱, 깊이 추정, 포즈 및 OBB 모델은 imgsz=640에서 내보냅니다. 이 224/640 표준은 공식 CoreML, LiteRT 및 QNN 모바일 에셋에서 공통으로 사용됩니다.
Apple은 iOS 27 및 macOS 27 세대에 사용할 새로운 Core AI 프레임워크 및 .aimodel 형식을 도입했으며, Ultralytics는 format="coreai"를 사용해 이 형식으로 내보냅니다. CoreML은 Ultralytics iOS 및 Flutter SDK의 기본 형식으로 유지되며, iOS 27 기기에서는 선택적으로 Core AI를 로드하고, 더 폭넓은 Apple 기기 호환성을 위한 형식으로도 사용됩니다.
시청: INT8 양자화를 적용해 Ultralytics YOLO26을 CoreML로 내보내는 방법 | Apple 배포 | iOS/MacOS 🍎
CoreML이란 무엇인가요?#
CoreML(Apple의 표기법은 "Core ML")은 Apple의 온디바이스 머신러닝 프레임워크입니다. 최신 ML Program 형식, 즉 Ultralytics 내보내기 도구가 생성하는 .mlpackage 번들로 모델을 로드하고, 기기의 CPU, GPU, 그리고 모든 Apple 실리콘 칩에 탑재된 전용 NPU인 Apple Neural Engine(ANE)에 작업을 배분합니다. 모든 처리가 로컬에서 이루어지므로 오프라인 추론이 가능하고 네트워크 지연이 발생하지 않으며 사용자 데이터가 기기 내에 유지됩니다.
CoreML은 Apple의 Vision 프레임워크와 직접 통합되며, 이 프레임워크는 모델에 입력하기 전 이미지 크기 조정과 방향 처리를 담당합니다. 이 덕분에 Ultralytics iOS SDK는 사실상 전처리 비용 없이 카메라 프레임을 YOLO에 전달합니다.
YOLO26을 CoreML로 내보내는 이유#
- Neural Engine 속도: CoreML은 지원되는 연산을 Apple Neural Engine에서 실행하도록 예약해 온디바이스 추론 지연 시간을 줄입니다. 아래의 실제 기기 표를 확인하고 대상 하드웨어에서 정확한 내보내기 결과를 벤치마크하세요.
- 출력 선택: 기본 내보내기에서는 NMS를 앱에서 처리합니다. NMS를 포함하려면
nms=True을, YOLO26의 NMS 프리 헤드를 사용하려면nms=False를 사용합니다. - 비공개 및 오프라인: 모든 계산이 기기 내에서 이루어지므로 클라우드 왕복이나 API 키가 필요 없으며, 완전한 데이터 개인정보 보호가 보장됩니다.
- 한 번 내보내 여러 생태계에서 사용: 동일한
.mlpackage이 iOS, iPadOS, macOS, watchOS, tvOS 및 visionOS에서 실행되며, 공식 Ultralytics iOS SDK와 Flutter 플러그인을 지원합니다.
측정 성능#
12 GB 메모리와 iOS 27.0.1을 탑재한 iPhone 17 Pro에서 표준화된 v8.3.0 YOLO26n INT8 CoreML 에셋을 사용한 종단 간 단일 이미지 추론입니다. A19 Pro는 6코어 CPU(성능 코어 2개 및 효율 코어 4개), Neural Accelerators를 탑재한 6코어 GPU, 16코어 Neural Engine으로 구성됩니다. 각 셀에는 총 시간(전처리 + 추론 + 후처리, 주석 제외)이 표시되며, 그 아래에는 단계별 시간이 나옵니다. iOS에서는 Vision이 추론 요청 내에서 입력 크기 조정을 수행하므로 전처리 시간은 0으로 표시되며, 해당 비용은 추론 시간에 포함됩니다.
| 모델 | 작업 | 크기 (픽셀) | CPU Core ML .cpuOnly(ms) | CPU + ANE 우선 Core ML .cpuAndNeuralEngine(ms) |
|---|---|---|---|---|
| YOLO26n | 감지 | 640 | 8.8 0.0 / 8.8 / 0.0 | 3.7 0.0 / 3.7 / 0.0 |
| YOLO26n-seg | 분할 | 640 | 12.3 0.0 / 11.7 / 0.6 | 4.9 0.0 / 4.3 / 0.6 |
| YOLO26n-sem | 의미론적 | 640 | 9.3 0.0 / 9.0 / 0.3 | 4.4 0.0 / 4.1 / 0.3 |
| YOLO26n-depth | 깊이 | 640 | 26.0 0.0 / 25.1 / 1.0 | 5.5 0.0 / 4.7 / 0.9 |
| YOLO26n-cls | 분류 | 224 | 4.1 0.0 / 4.1 / 0.0 | 2.0 0.0 / 1.9 / 0.0 |
| YOLO26n-pose | 포즈 | 640 | 12.0 0.0 / 12.0 / 0.0 | 4.0 0.0 / 4.0 / 0.0 |
| YOLO26n-obb | OBB | 640 | 10.7 0.0 / 10.7 / 0.0 | 3.9 0.0 / 3.9 / 0.0 |
- 정확한
v8.3.0릴리스 에셋은 분류 입력 크기를 224×224로, 그 외 모든 작업 입력 크기를 640×640으로 지정합니다. - iOS 27.0.1에서
.cpuOnly방식으로l및x깊이, 포즈, OBB 모델을 추론하면 Core ML의 CPU 커널 내부에서 충돌합니다(libBNNS의EXC_BAD_ACCESS). 동일한 모델은.cpuAndNeuralEngine로 실행되며, 다른 모든 작업과 크기는 CPU에서 실행됩니다. - 속도 값은 단일 이미지 버스트 지연 시간입니다.
bus.jpg에서 3회 워밍업 실행 후 15회 실행의 평균값을 측정했으며, 프로파일 모드(최적화된 네이티브 코드)에서 iOS SDK의 단계별 타이밍을 Flutter 플러그인의 벤치마크 하네스로 측정했습니다. CPU/가속기 순서는 하나의 순차 스윕에서 작업마다 번갈아 적용했습니다. CPU 행은 Core ML.cpuOnly을 요청하고 CPU + ANE 우선 행은.cpuAndNeuralEngine를 요청하며, 최종 연산 배치는 Core ML에서 제어합니다. 지속적인 실시간 카메라 작동에서는 캡처 및 크기 조정 파이프라인과 열 안정화 과정이 포함되므로 지연 시간이 더 길어집니다. 표준화 이전에 수행한 과거 카메라 스윕에서는 동일한 기기에서 YOLO26n 탐지의 프레임당 시간이 11.3 ms, YOLO26n 깊이 추정의 프레임당 시간이 16.5 ms로 측정되었습니다. 정상 상태 프로파일링은 iOS SDK 성능 문서를 참조하세요. - LiteRT 통합의 Android CPU/GPU 결과, MediaTek Dimensity 결과, Qualcomm QNN 통합의 Snapdragon NPU 결과를 비교하세요.
지원 작업#
CoreML 내보내기는 Ultralytics의 7가지 작업을 모두 지원합니다. 시맨틱 세그멘테이션과 깊이 추정은 해당 헤드를 제공하는 유일한 제품군인 YOLO26에서만 사용할 수 있습니다.
YOLO26 모델을 CoreML로 내보내기#
설치#
필수 패키지를 설치하려면 다음을 실행하세요:
# Install the required package for YOLO26
pip install ultralyticscoremltools 변환기는 첫 내보내기 시 자동으로 설치됩니다. 내보내기는 macOS 또는 x86 Linux에서 실행됩니다. 자세한 지침과 모범 사례는 설치 가이드와 일반적인 문제 가이드를 참조하세요.
사용법#
CoreML 형식은 내보내기, 예측 및 검증 모드를 지원합니다. CoreML을 사용한 추론 및 검증은 macOS에서만 실행됩니다. 모델을 내보낸 다음 내보낸 모델을 로드해 추론을 실행하거나 정확도를 검증하세요.
from ultralytics import YOLO
# YOLO26 모델 로드
model = YOLO("yolo26n.pt")
# 공식 앱 모델과 동일하게 INT8 가중치 양자화를 적용해 CoreML로 내보내기
model.export(format="coreml", quantize=8, imgsz=640) # 분류에는 imgsz=224 사용from ultralytics import YOLO
# 내보낸 CoreML 모델 로드(macOS)
model = YOLO("yolo26n.mlpackage")
# 추론 실행
results = model("https://ultralytics.com/images/bus.jpg")from ultralytics import YOLO
# 내보낸 CoreML 모델 로드(macOS)
model = YOLO("yolo26n.mlpackage")
# COCO8 데이터셋에서 정확도 검증
metrics = model.val(data="coco8.yaml")내보내기 인수#
| 인수 | 유형 | 기본값 | 설명 |
|---|---|---|---|
format | str | 'coreml' | 내보낸 모델의 대상 형식으로, 다양한 배포 환경과의 호환성을 정의합니다. |
imgsz | int 또는 tuple | 640 | 모델 입력에 사용할 이미지 크기입니다. 정사각형 이미지에는 정수를 사용하고, 특정 크기에는 튜플 (height, width)을 사용할 수 있습니다. |
quantize | int 또는 str | None | 양자화 정밀도: 16(FP16), 8 또는 "w8a16"(동일: 8비트 k-means 팔레트화 가중치와 FP16 연산), 또는 32 또는 미설정(FP32)입니다. NMS ML Programs는 FP16을 사용합니다(Xcode 미리보기 및 segment와 pose에 필요). detect에서는 32를 전달해 재정의할 수 있습니다. 더 이상 사용되지 않는 half/int8 플래그를 대체합니다. |
nms | bool, 선택 사항 | None | 원시 출력(None, 기본값), 포함된 NMS(True) 또는 NMS가 없는 헤드(False)를 선택합니다. 포함된 NMS는 dynamic=False을 사용해 탐지, 세그멘테이션 및 포즈를 지원합니다. |
dynamic | bool | False | 동적 입력 크기를 허용합니다. 분류 또는 RT-DETR 모델에서는 지원되지 않으며 nms=True과 함께 사용할 수 없습니다. |
batch | int | 1 | 내보낸 모델의 배치 추론 크기 또는 predict 모드에서 내보낸 모델이 동시에 처리할 최대 이미지 수를 지정합니다. 1을 초과하는 값에는 dynamic=True가 필요합니다. |
device | str | None | 내보내기에 사용할 장치를 지정합니다. GPU(device=0), CPU(device=cpu), Apple 실리콘용 MPS(device=mps)를 사용할 수 있습니다. |
내보내기 프로세스에 관한 자세한 내용은 내보내기에 관한 Ultralytics 문서 페이지를 참조하세요.
Neural Engine 대상 설정#
CoreML은 MLModelConfiguration.computeUnits을 통해 하드웨어를 선택합니다. Ultralytics iOS SDK는 iOS 16 이상에서 .all 대신 .cpuAndNeuralEngine을 기본값으로 사용합니다. 실시간 카메라 앱에서는 GPU가 이미 미리 보기와 오버레이 합성에 사용 중이므로 GPU를 제외하면 경합과 프레임 시간 변동을 방지하고 ANE가 주요 연산을 처리할 수 있습니다. 호환성 테스트에만 .cpuOnly을 고정하세요. 위 표에서 그 비용을 확인할 수 있습니다.
Ultralytics 또는 coremltools을 통해 Mac 호스트에서 Python으로 CoreML 모델을 실행할 때도 같은 규칙이 적용됩니다. Ultralytics는 ComputeUnit.CPU_AND_NE로 로드하고(macOS 13 이상, 이전 macOS에서는 CPU_ONLY로 대체), 추론을 Neural Engine에서 실행합니다(CPU보다 약 3배 빠름). 또한 GPU/MPSGraph 컴파일 경로를 추가하는 기본 ComputeUnit.ALL / CPU_AND_GPU가 coremltools 9.x에서 Error: MLIR pass manager failed 어설션을 발생시키며 프로세스를 중단하는 현재 macOS 호스트의 제한도 피할 수 있습니다. RT-DETR 모델은 Neural Engine만 사용할 경우 FP16 정확도가 저하되므로 예외적으로 ComputeUnit.ALL로 로드됩니다.
내보낸 YOLO26 CoreML 모델 배포#
가장 빠른 방법은 공식 Ultralytics YOLO iOS SDK입니다. 이 Swift 패키지는 Ultralytics iOS 앱과 Flutter 플러그인을 구동합니다. 공식 모델 이름을 자동으로 확인하고 .mlpackage를 다운로드 및 캐시한 뒤, 디코딩이 완료된 결과를 반환합니다:
import UltralyticsYOLO
// Loads the official INT8 model (downloaded and cached on first use), then runs inference
let yolo = YOLO("yolo26n", task: .detect) { result in
if case .success(let model) = result {
let results = model(uiImage) // boxes, labels, confidences, timing
}
}카메라 앱에서는 SDK의 YOLOView을 추가해 네이티브 오버레이를 포함한 실시간 추론을 실행하거나, Android와 코드베이스를 공유하는 크로스 플랫폼 앱에는 Flutter 플러그인을 사용하세요.
Apple 스택을 사용하면 원시 .mlpackage을 직접 통합하는 것도 간단합니다. MLModel로 로드하고 VNCoreMLRequest로 래핑한 다음 VNImageRequestHandler을 통해 이미지를 입력하면 됩니다. 자세한 내용은 다음 리소스를 참조하세요:
- Core ML 모델을 앱에 통합하기: CoreML 모델을 앱에 번들링하고 호출하는 방법에 관한 Apple 가이드입니다.
- CoreML Tools: 이 내보내기를 지원하는
coremltools툴체인의 변환, 양자화 및 최적화 참고 자료입니다. - Xcode Core ML 성능 보고서: 특정 모델 및 기기에 대한 레이어별 기기 배치와 지연 시간 프로파일링을 제공합니다.
모델은 앱 번들에 포함해 즉시 사용할 수 있도록 배포하거나(나노/소형 모델에 적합), 첫 실행 시 다운로드해 캐시할 수 있습니다(바이너리 크기 감소 및 간편한 모델 업데이트). 공식 앱은 두 방식을 함께 사용합니다. 기본 나노 모델은 즉시 사용할 수 있도록 번들에 포함하고, 더 큰 모델은 필요할 때 다운로드해 로컬에 캐시합니다.
권장 워크플로#
- Ultralytics Train 모드로 모델을 학습하거나 공식 YOLO26 가중치에서 시작합니다.
- macOS 또는 x86 Linux에서
model.export(format="coreml", quantize=8, imgsz=640)을 사용해 내보내기하세요(분류에는imgsz=224사용). - Mac에서
model.val()을 사용해 정확도를 검증하고, 대상 기기에서 Xcode Core ML 성능 보고서로 프로파일링하세요. - iOS SDK, Flutter 플러그인 또는 자체 Vision 통합을 사용해
.cpuAndNeuralEngine을 대상으로 배포하세요.
요약#
이 가이드에서는 Ultralytics YOLO26 모델을 CoreML의 .mlpackage 형식으로 내보내고, Apple Neural Engine에 맞게 양자화한 뒤, 공식 iOS SDK와 Flutter 플러그인 또는 자체 Vision 통합을 통해 한 자릿수 밀리초의 지연 시간으로 배포하는 방법을 알아보았습니다.
자주 묻는 질문#
macOS 또는 x86 Linux에서 Python으로
model.export(format="coreml", imgsz=640)을 실행하거나 CLI에서yolo export model=yolo26n.pt format=coreml imgsz=640을 실행하세요. 분류에는imgsz=224를 사용하고 공식 앱 모델과 동일한 결과를 얻으려면quantize=8을 추가하세요. 내보내기 결과는 Xcode, iOS SDK 또는 Flutter 플러그인에서 사용할 수 있는yolo26n.mlpackageML Program입니다.앱에 NMS가 포함된 탐지 결과가 필요하다면
nms=True을 사용하세요. 기본nms=None은 앱에서 처리할 원시 일대다 출력을 내보내며,nms=False는 YOLO26의 NMS 없는 헤드를 선택합니다. 포함된 NMS는 정적 셰이프에서 탐지, 세그멘테이션 및 포즈를 지원하며, 다른 작업은 네이티브 출력을 유지합니다.공식 Ultralytics 앱 모델은 다운로드 크기를 최소화하고 위 표에 표시된 속도로 실행되도록 INT8로 제공됩니다.
quantize=16(FP16)은 정확도 손실이 사실상 없는 보수적인 대안입니다. 배포 전에 Mac에서model.val()을 사용해 정확한 내보내기 결과를 검증하세요.MLModelConfiguration.computeUnits = .cpuAndNeuralEngine을 설정하세요(iOS 16 이상에서 iOS SDK의 기본값). 카메라 앱에서는.all을 사용하지 마세요. GPU가 미리 보기를 합성하느라 사용 중인 상태에서 추론을 GPU에 예약하면 프레임 시간 변동이 발생합니다. Xcode Core ML 성능 보고서에서 배치를 확인하세요.네, macOS에서 가능합니다.
yolo predict model=yolo26n.mlpackage source=image.jpg과yolo val model=yolo26n.mlpackage data=coco8.yaml은 다른 형식과 동일하게 작동합니다. CoreML 실행에는 Apple 하드웨어가 필요하므로 Linux 및 Windows에서는 이 모드를 사용할 수 없습니다.공식 Ultralytics YOLO iOS SDK(Swift Package) 또는 Flutter 플러그인을 사용하세요. 두 방식 모두 이름으로 공식 모델을 로드하고 자동 다운로드 및 캐싱을 지원하며, Neural Engine에서 실행됩니다. 완전한 실시간 카메라 UI도 포함되어 있습니다. 위의 성능 표는 바로 이 스택으로 측정한 결과입니다.
댓글13
질문을 하거나 결과를 공유하거나 다른 사람을 도와주세요.
Afool4U
Hello! I have trouble when I tried to export yolo11n.pt to coreml model with tracking. for example, the exist tracking method is like this:
# use YOLO tracking results = yolo_model.track(frame, persist=True, verbose=False)And I've export pt format and reloaded the new coreml format model like this:
model.export(format='coreml', nms=True, half=False) model = ct.models.MLModel('yolo11n.mlpackage')But when I tried to make a tracking on my camera stream, it seems that object 'model' have no attribute named 'track'. So how could I use tracking by a coreml format model? It's very important to me because the coreml model works well on my macbook.
Sebastianxhj
I used the example python code you guys gave. Why does output output confidence and coordination after converting my target detection model to mlpackage format. is it normal to not return processed images? Or is there something wrong with my export process.
Glenn JocherUltralytics@taeja7 the CoreML export returns raw detection outputs (confidence, coordinates) rather than processed images by design. This is normal behavior, as post-processing like bounding box rendering is typically handled within the application layer after inference. For implementation guidance, see the CoreML deployment documentation on handling model outputs in Apple apps.
smadsenjc
I have a trained model that is doing very well in Python, but once I convert it to CoreML
.mlpackageformat and run inference in Swift, the results are garbage on the same images.If I export with
nms=True, I get multiple overlapping bounding boxes back, similar-ish to when no NMS is done. The number of clusters matches the objects I expect, and they're kind of relatively positioned correctly, although the boxes themselves are too large and clustered in the wrong location. The predicted labels are right.If I export with
nms=False, I get a different result back fromVNCoreMLRequest: a singleVNCoreMLFeatureValueObservationinstead of an array ofVNRecognizedObjectObservation.I've used both coremltools 8.0 and 8.2. If I run inference in Python using the CoreML model, it's fine (with
nms=False;Truefails).This was working back in November, but I got side-tracked with other work. I haven't touched the model.
Glenn JocherUltralytics@smadsenjc for CoreML inference discrepancies between Python and Swift, ensure you're handling NMS parameters correctly in your Swift implementation. The CoreML export with
nms=Truerequires explicit IOU and confidence threshold inputs during inference - these must match your Python training parameters. We recommend verifying your Swift preprocessing matches Ultralytics' RGB channel ordering and normalization (scale=1/255, bias=[0,0,0]). For direct assistance with Apple's Vision framework implementation, refer to Apple's CoreML integration guide linked in our documentation.
CharanPrasadK
When I am Converting the Yolo .pt model to coreml model , mlpackage is creating and when I am checking it in the xcode the class labels are missing. For the core ml models in ultralytics github page class labels are there. If its solved i can test my custom yolo models. Thank you.
Glenn JocherUltralytics(수정됨)@CharanPrasadK it seems the class labels are not being included in your CoreML export. Ensure that your model is correctly labeled during training and export by checking the
namesattribute in the model. If the issue persists, please verify that you're using the latestultralyticspackage. For further details, refer to the CoreML export documentation. Let us know if you need additional assistance!
ChristalZhu
Still the same problem, this is the result of running in the terminal: PyTorch: starting from '/Users/doublepeng/Desktop/best.pt' with input shape (1, 3, 640, 640) BCHW and output shape(s) ((1, 37, 8400), (1, 32, 160, 160)) (6.5 MB)
CoreML: starting export with coremltools 7.2... CoreML: WARNING ⚠️ 'nms=True' is only available for Detect models like 'yolov8n.pt'. Tuple detected at graph output. This will be flattened in the converted model. Converting PyTorch Frontend ==> MIL Ops: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌| 679/681 [00:00<00:00, 8273.25 ops/s] Running MIL frontend_pytorch pipeline: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 157.94 passes/s] Running MIL default pipeline: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 78/78 [00:00<00:00, 82.56 passes/s] Running MIL backend_mlprogram pipeline: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 12/12 [00:00<00:00, 160.71 passes/s] CoreML: export success ✅ 7.7s, saved as '/Users/doublepeng/Desktop/best.mlpackage' (6.4 MB)
Export complete (8.1s) Results saved to /Users/doublepeng/Desktop Predict: yolo predict task=segment model=/Users/doublepeng/Desktop/best.mlpackage imgsz=640 Validate: yolo val task=segment model=/Users/doublepeng/Desktop/best.mlpackage imgsz=640 data=/home/yujialin/Documents/xiaotong/corn/data/corn.yaml Visualize: https://netron.app In the run mlpackage file, the class label is still missing in General, and there is no preview. Since I am only doing corn segmentation, if possible, can I send you my .pt file?
Glenn JocherUltralytics@ChristalZhu hello,
Thank you for providing the detailed output from your terminal. It looks like the CoreML export process completed successfully, but you're experiencing issues with missing class labels and preview in the
.mlpackagefile.To assist you better, could you please confirm the following:
- Are you using the latest versions of
torchandultralytics? If not, please upgrade and try the export process again. - Could you provide a minimum reproducible example of your code? This will help us understand the context and reproduce the issue on our end. You can refer to our minimum reproducible example guide for more details.
Regarding your
.ptfile, we cannot accept direct file submissions. However, you can share the relevant code snippets and configurations you used for training and exporting the model.Here's a quick example of how to export a YOLOv8 model to CoreML and run inference:
from ultralytics import YOLO # Load the YOLOv8 model model = YOLO("yolov8n.pt") # Export the model to CoreML format model.export(format="coreml") # creates 'yolov8n.mlpackage' # Load the exported CoreML model coreml_model = YOLO("yolov8n.mlpackage") # Run inference results = coreml_model("https://ultralytics.com/images/bus.jpg")For more detailed instructions, you can visit our CoreML integration guide.
Looking forward to your response so we can help resolve this issue.
- Are you using the latest versions of
ChristalZhu
我按照https://harshavardhanyellanki.github.io/YOLOV8_GUI/tasks/segmentation/的方法,将我自己训练的分割模型进行导出成mlpackage,但是出现了问题就是打开这个mlpackage之后,缺少class label文件和缺少了preview,请问这个有什么办法解决,如果可以的话,麻烦发送到我的email账号:wenpeng.zhu@foxmail.com万分感谢。 I followed the method at https://harshavardhanyellanki.github.io/YOLOV8_GUI/tasks/segmentation/ to export the segmentation model I trained myself into mlpackage, but the problem is that after opening this mlpackage, the class label file and the preview are missing. Is there any way to solve this problem? If possible, please send it to my email account: wenpeng.zhu@foxmail.com. Thank you very much.
Paula DerrengerUltralyticsHello @ChristalZhu,
Thank you for reaching out and providing details about the issue you're facing with exporting your YOLOv8 segmentation model to CoreML. Let's work together to resolve this.
Firstly, please ensure that you are using the latest versions of
torchandultralytics. You can update them using the following commands:pip install --upgrade torch ultralyticsIf the issue persists, could you please provide a minimum reproducible code example? This will help us better understand the problem and investigate a solution. You can refer to our guide on creating a minimum reproducible example here: Minimum Reproducible Example.
Regarding the missing class label file and preview in the
.mlpackage, this can sometimes occur if the export process does not include all necessary metadata. Here is a Python example to ensure the export includes all required components:from ultralytics import YOLO # Load your trained YOLOv8 model model = YOLO("path/to/your/custom_model.pt") # Export the model to CoreML format model.export(format="coreml", nms=True) # Ensure NMS is included for proper detectionAfter exporting, you can manually check the
.mlpackageto ensure it contains the necessary class labels and preview files. If they are still missing, please let us know, and we can further investigate.For more detailed instructions on exporting to CoreML, you can visit our documentation here: CoreML Export Guide.
Feel free to share any additional details or errors you encounter. We're here to help!
ChristalZhu
Still the same problem, this is the result of running in the terminal: PyTorch: starting from '/Users/doublepeng/Desktop/best.pt' with input shape (1, 3, 640, 640) BCHW and output shape(s) ((1, 37, 8400), (1, 32, 160, 160)) (6.5 MB)
CoreML: starting export with coremltools 7.2... CoreML: WARNING ⚠️ 'nms=True' is only available for Detect models like 'yolov8n.pt'. Tuple detected at graph output. This will be flattened in the converted model. Converting PyTorch Frontend ==> MIL Ops: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌| 679/681 [00:00<00:00, 8273.25 ops/s] Running MIL frontend_pytorch pipeline: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 157.94 passes/s] Running MIL default pipeline: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 78/78 [00:00<00:00, 82.56 passes/s] Running MIL backend_mlprogram pipeline: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 12/12 [00:00<00:00, 160.71 passes/s] CoreML: export success ✅ 7.7s, saved as '/Users/doublepeng/Desktop/best.mlpackage' (6.4 MB)
Export complete (8.1s) Results saved to /Users/doublepeng/Desktop Predict: yolo predict task=segment model=/Users/doublepeng/Desktop/best.mlpackage imgsz=640
Validate: yolo val task=segment model=/Users/doublepeng/Desktop/best.mlpackage imgsz=640 data=/home/yujialin/Documents/xiaotong/corn/data/corn.yaml
Visualize: https://netron.app In the run mlpackage file, the class label is still missing in General, and there is no preview. Since I am only doing corn segmentation, if possible, can I send you my .pt file?
Paula DerrengerUltralyticsHello @ChristalZhu,
Thank you for providing the detailed output from your terminal. It looks like the CoreML export process completed successfully, but you're encountering issues with missing class labels and preview in the
.mlpackage.To address this, please ensure you are using the latest versions of
torchandultralytics. You can update them using the following commands:pip install --upgrade torch ultralyticsIf the issue persists, could you please provide a minimum reproducible code example? This will help us better understand the problem and investigate a solution. You can refer to our guide on creating a minimum reproducible example here: Minimum Reproducible Example.
Regarding the missing class label file and preview in the
.mlpackage, this can sometimes occur if the export process does not include all necessary metadata. Here is a Python example to ensure the export includes all required components:from ultralytics import YOLO # Load your trained YOLOv8 model model = YOLO("path/to/your/custom_model.pt") # Export the model to CoreML format model.export(format="coreml", nms=True) # Ensure NMS is included for proper detectionAfter exporting, you can manually check the
.mlpackageto ensure it contains the necessary class labels and preview files. If they are still missing, please let us know, and we can further investigate.For more detailed instructions on exporting to CoreML, you can visit our documentation here: CoreML Export Guide.
Feel free to share any additional details or errors you encounter. We're here to help! 😊
