YOLO26モデルのCoreMLエクスポート
Appleは、Neural Engineという専用のAIシリコンを最新のiPhone、iPad、Macすべてに搭載しており、CoreMLは現在、モデルをNeural Engineにデプロイするために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 Neural Engine (ANE)(すべてのAppleシリコンチップに搭載された専用のNPU)に処理を割り当てます。すべての処理がローカルで実行されるため、推論はオフラインで動作し、ネットワーク遅延が発生せず、ユーザーデータもデバイス内に保持されます。
CoreMLはAppleのVisionフレームワークと直接連携し、モデルに入力する際の画像のスケーリングと向きを処理します。これにより、Ultralytics iOS SDKは実質的に前処理コストをかけずに、カメラフレームをYOLOに渡せます。
YOLO26をCoreMLにエクスポートする理由#
- Neural Engineの速度:CoreMLは、対応する演算をAppleのNeural Engineに割り当て、低レイテンシのオンデバイス推論を実現します。以下の実機表を確認し、対象ハードウェアで実際のエクスポートをベンチマークしてください。
- 出力を選択: デフォルトのエクスポートでは、NMSはアプリ側で処理します。NMSを組み込むには
nms=Trueを、YOLO26のNMSフリーヘッドを使用するにはnms=Falseを指定します。 - プライベートかつオフライン:すべての計算はデバイス上で完結するため、クラウドとの通信もAPIキーも不要で、データプライバシーを完全に確保できます。
- 1回のエクスポートでエコシステム全体に対応:同じ
.mlpackageはiOS、iPadOS、macOS、watchOS、tvOS、visionOSで動作し、公式UltralyticsのiOS SDKとFlutterプラグインを支えます。
実測パフォーマンス#
標準化された v8.3.0 YOLO26n INT8 CoreML アセットを、メモリ 12 GB、iOS 27.0.1 搭載の iPhone 17 Pro で実行した、単一画像のエンドツーエンド推論です。A19 Proは、6コアCPU(Performanceコア2基、Efficiencyコア4基)、Neural Accelerators搭載の6コアGPU、16コアNeural Engineを備えています。各セルには合計時間(アノテーションを除く、前処理+推論+後処理)を示し、その下に各ステージの内訳を表示しています。iOSでは、Visionが推論リクエスト内で入力画像のスケーリングを行うため、前処理時間は0として報告され、そのコストは推論時間に含まれます。
| モデル | タスク | サイズ (ピクセル) | CPU Core ML .cpuOnly(ms) | CPU + ANE優先 Core ML .cpuAndNeuralEngine(ms) |
|---|---|---|---|---|
| YOLO26n | Detect | 640 | 8.8 0.0 / 8.8 / 0.0 | 3.7 0.0 / 3.7 / 0.0 |
| YOLO26n-seg | Segment | 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とアクセラレーターの順序は、1回の逐次スイープ内でタスクごとに交互に切り替えました。CPUの行ではCore ML.cpuOnlyを要求し、CPU + ANE優先の行では.cpuAndNeuralEngineを要求します。最終的な演算の割り当てはCore MLが制御します。持続的なリアルタイムカメラ動作では、キャプチャとスケーリングのパイプラインおよび熱状態の安定化が含まれるため、時間が長くなります。標準化前の過去のカメラ測定では、同じデバイスでYOLO26n検出が11.3 ms/フレーム、YOLO26n Depthが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"(同一の設定で、FP16演算を使用する8ビットk-meansパレット化重み)、または 32 もしくは未指定(FP32)。NMS ML ProgramsではFP16が使用されます(Xcodeプレビュー用であり、セグメンテーションと姿勢推定では必須です)。検出では 32 を渡すと上書きできます。非推奨の half/int8 フラグを置き換えるものです。 |
nms | bool、省略可 | None | 生出力(None、デフォルト)、NMS組み込み(True)、NMSフリーヘッド(False)のいずれかを選択します。NMS組み込みは、dynamic=Falseを使用するdetect、segment、poseに対応しています。 |
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は、.allではなく、iOS 16以降でデフォルトの.cpuAndNeuralEngineを使用します。リアルタイムカメラアプリでは、GPUはプレビューとオーバーレイの合成ですでに負荷がかかっているため、GPUを除外すると競合やフレーム時間の揺らぎを避けられ、重い処理はANEが担います。互換性テストでのみ.cpuOnlyを固定してください。上の表でそのコストを確認できます。
Macホスト上でPythonからCoreMLモデルを実行する場合(Ultralyticsまたは coremltools 経由)も、同じルールが適用されます。Ultralyticsは ComputeUnit.CPU_AND_NE(macOS 13以降。古いmacOSでは CPU_ONLY にフォールバック)で読み込み、推論をNeural Engine上で実行します(CPUより約3倍高速です)。これにより、デフォルトの ComputeUnit.ALL / CPU_AND_GPU(GPU/MPSGraphのコンパイルパスを追加)が、macOS 9.xの coremltools 上で Error: MLIR pass manager failed アサーションによりプロセスを異常終了させるという、現在のmacOSホストの制限も回避できます。例外はRT-DETRモデルです。FP16の精度がNeural Engine単独では低下するため、RT-DETRモデルは ComputeUnit.ALL で読み込まれます。
エクスポート済みYOLO26 CoreMLモデルをデプロイする#
最も簡単なのは、公式のUltralytics YOLO iOS SDKです。これはUltralytics iOSアプリとFlutterプラグインを支えるSwiftパッケージと同じものです。公式モデル名を自動的に解決し、.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パフォーマンスレポート:対象モデルとデバイスで、レイヤーごとのデバイス割り当てとレイテンシをプロファイリングできます。
モデルはアプリバンドルに埋め込む(すぐに利用でき、小型モデルに最適)か、初回起動時にダウンロードしてキャッシュする(バイナリを小さくでき、モデルを簡単に更新可能)方法で配布できます。公式アプリでは両方の方法を組み合わせています。デフォルトのnanoモデルはすぐに使えるよう同梱し、大型モデルは必要に応じてダウンロードしてローカルにキャッシュします。
推奨ワークフロー#
- 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向けに量子化して、1桁ミリ秒のレイテンシでデプロイする方法を説明しました。デプロイには、公式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は、アプリ側で処理する生のone-to-many出力をエクスポートします。nms=FalseはYOLO26のNMSフリーヘッドを選択します。組み込みNMSは固定形状のdetect、segment、poseに対応し、その他のタスクではネイティブ出力が維持されます。Ultralyticsの公式アプリモデルはINT8で提供され、ダウンロードサイズを最小限に抑えつつ、上の表に示す速度で動作します。
quantize=16(FP16)は、精度の損失が実質的にない保守的な選択肢です。リリース前にMac上でmodel.val()を使用して、実際のエクスポートを検証してください。MLModelConfiguration.computeUnits = .cpuAndNeuralEngineを設定します(iOS 16以降のiOS SDKのデフォルトです)。カメラアプリでは.allを避けてください。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! 😊
