Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ExampleApps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Follow these steps to get the examples up and running:
#### Obtaining YOLO Core ML Models

You have two primary ways to get Ultralytics YOLO models in [Core ML format](https://docs.ultralytics.com/integrations/coreml/):
- **Download Pre-Exported Models:** Download optimized Core ML [INT8](https://www.ultralytics.com/glossary/model-quantization) models directly from the [Ultralytics YOLOv8 GitHub releases](https://github.com/ultralytics/ultralytics/releases). Place the downloaded model file into your Xcode project.
- **Download Pre-Exported Models:** Download optimized Core ML [INT8](https://www.ultralytics.com/glossary/model-quantization) models directly from the [Ultralytics YOLO GitHub releases](https://github.com/ultralytics/ultralytics/releases). Place the downloaded model file into your Xcode project.
- **Export Your Own Models:** Use the [`ultralytics` Python package](https://docs.ultralytics.com/quickstart/) to export models tailored to your needs. This offers flexibility in choosing model types and configurations.

- Install the package using [pip](https://pip.pypa.io/en/stable/installation/):
Expand All @@ -62,12 +62,12 @@ Follow these steps to get the examples up and running:
model_types=("", "-seg", "-cls", "-pose", "-obb"),
model_sizes=("n", "s", "m", "l", "x"),
):
"""Exports YOLO11 models to CoreML format and optionally zips the output packages."""
"""Exports YOLO26 models to CoreML format and optionally zips the output packages."""
for model_type in model_types:
imgsz = [224, 224] if "cls" in model_type else [640, 384] # default input image sizes
nms = True if model_type == "" else False # only apply NMS to Detect models
nms = False # YOLO26 is NMS-free for detect; non-detect tasks also use nms=False
for size in model_sizes:
model_name = f"yolo11{size}{model_type}"
model_name = f"yolo26{size}{model_type}"
model = YOLO(f"{model_name}.pt")
model.export(format="coreml", int8=True, imgsz=imgsz, nms=nms)
zip_directory(f"{model_name}.mlpackage").rename(f"{model_name}.mlpackage.zip")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import YOLO
struct ContentView: View {
var body: some View {
YOLOCamera(
modelPathOrName: "yolo11n",
modelPathOrName: "yolo26n",
task: .detect,
cameraPosition: .back
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This directory contains [unit tests](https://en.wikipedia.org/wiki/Unit_testing)

To execute the complete test suite, including tests involving model [inference](https://www.ultralytics.com/glossary/real-time-inference), you need the following [Core ML](https://developer.apple.com/documentation/coreml) model file:

- `yolo11n-obb.mlpackage` - An [Ultralytics YOLO11](https://docs.ultralytics.com/models/yolo11/) model optimized for Oriented Bounding Box ([OBB](https://docs.ultralytics.com/tasks/obb/)) detection. Learn more about OBB in our [documentation](https://docs.ultralytics.com/tasks/obb/).
- `yolo26n-obb.mlpackage` - An [Ultralytics YOLO26](https://platform.ultralytics.com/ultralytics/yolo26) model optimized for Oriented Bounding Box ([OBB](https://docs.ultralytics.com/tasks/obb/)) detection. Learn more about OBB in our [documentation](https://docs.ultralytics.com/tasks/obb/).

**Note**: This model file is not included in the repository due to its size.

Expand All @@ -22,11 +22,11 @@ To execute the complete test suite, including tests involving model [inference](
```python
from ultralytics import YOLO

# Load a pretrained OBB model (e.g., yolo11n-obb.pt)
model = YOLO("yolo11n-obb.pt")
# Load a pretrained OBB model (e.g., yolo26n-obb.pt)
model = YOLO("yolo26n-obb.pt")

# Export the model to Core ML format
model.export(format="coreml") # Creates yolo11n-obb.mlpackage
model.export(format="coreml") # Creates yolo26n-obb.mlpackage
```

### Adding Model Files to the Project
Expand All @@ -35,7 +35,7 @@ model.export(format="coreml") # Creates yolo11n-obb.mlpackage

Follow these steps to add the model file correctly within Xcode:

1. Drag and drop the `yolo11n-obb.mlpackage` file into your Xcode project navigator.
1. Drag and drop the `yolo26n-obb.mlpackage` file into your Xcode project navigator.
2. In the "Choose options for adding these files" dialog:
- Ensure the **"YOLO-RealTime-SwiftUI"** target checkbox is **checked**.
- Optionally, check the "YOLO-RealTime-SwiftUITests" target, but the main target is essential.
Expand All @@ -60,13 +60,13 @@ These tests aim to verify several aspects of the application:

#### Running Tests Without Models (Default)

By default, the `SKIP_MODEL_TESTS` flag in the test file is set to `true`. This configuration allows you to run the tests **without** needing the `yolo11n-obb.mlpackage` file. Tests that depend on actual model inference will be skipped, but basic application functionality (UI, camera setup) will still be verified. This is useful for quick checks or in [Continuous Integration (CI)](https://en.wikipedia.org/wiki/Continuous_integration) environments where managing large model files might be complex. Check our [Quickstart guide](https://docs.ultralytics.com/quickstart/) for setting up your environment.
By default, the `SKIP_MODEL_TESTS` flag in the test file is set to `true`. This configuration allows you to run the tests **without** needing the `yolo26n-obb.mlpackage` file. Tests that depend on actual model inference will be skipped, but basic application functionality (UI, camera setup) will still be verified. This is useful for quick checks or in [Continuous Integration (CI)](https://en.wikipedia.org/wiki/Continuous_integration) environments where managing large model files might be complex. Check our [Quickstart guide](https://docs.ultralytics.com/quickstart/) for setting up your environment.

#### Running Tests With Models

To run the full test suite, including tests that perform inference:

1. Ensure you have obtained `yolo11n-obb.mlpackage` and added it to the **main application target** as described above.
1. Ensure you have obtained `yolo26n-obb.mlpackage` and added it to the **main application target** as described above.
2. Open the relevant test file (e.g., `YOLO_RealTime_SwiftUITests.swift`).
3. Change the flag `SKIP_MODEL_TESTS` to `false`.
4. Run the tests using Xcode (Product > Test or `Cmd+U`).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import XCTest
/// of the app, including model initialization, camera preview functionality, and UI interactions.
///
/// - Note: These tests require the application to be built with testing enabled.
/// - Important: Some tests require the YOLO11 OBB model to be available in the project.
/// - Important: Some tests require the YOLO26 OBB model to be available in the project.
struct YOLORealTimeSwiftUITests {

// Flag to skip model-dependent tests if model is not available
Expand All @@ -40,7 +40,7 @@ struct YOLORealTimeSwiftUITests {
}

let yoloCamera = YOLOCamera(
modelPathOrName: "yolo11n-obb",
modelPathOrName: "yolo26n-obb",
task: .obb,
cameraPosition: .back
)
Expand Down Expand Up @@ -79,7 +79,7 @@ struct YOLORealTimeSwiftUITests {

// Test initialization with front camera
let frontCamera = YOLOCamera(
modelPathOrName: "yolo11n-obb",
modelPathOrName: "yolo26n-obb",
task: .obb,
cameraPosition: .front
)
Expand All @@ -88,7 +88,7 @@ struct YOLORealTimeSwiftUITests {

// Test initialization with back camera
let backCamera = YOLOCamera(
modelPathOrName: "yolo11n-obb",
modelPathOrName: "yolo26n-obb",
task: .obb,
cameraPosition: .back
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ViewController: UIViewController {
super.viewDidLoad()
// Initialize YOLOView with a segmentation model
// You can change the model or task type to use detection, classification, etc.
yoloView = YOLOView(frame: view.bounds, modelPathOrName: "yolo11n", task: .detect)
yoloView = YOLOView(frame: view.bounds, modelPathOrName: "yolo26n", task: .detect)
view.addSubview(yoloView)
}
}
20 changes: 10 additions & 10 deletions ExampleApps/YOLORealTimeUIKit/YOLORealTimeUIKitTests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@ Follow these instructions to set up and run the tests for the application.

To execute the full test suite effectively, you will need the following [Apple Core ML](https://developer.apple.com/documentation/coreml) model file:

- `yolo11n.mlpackage`: An [Ultralytics YOLO11](https://docs.ultralytics.com/models/yolo11/) model optimized for [object detection](https://docs.ultralytics.com/tasks/detect/) tasks.
- `yolo26n.mlpackage`: An [Ultralytics YOLO26](https://platform.ultralytics.com/ultralytics/yolo26) model optimized for [object detection](https://docs.ultralytics.com/tasks/detect/) tasks.

**Note**: This model file is not included directly in the repository. Due to its potentially [large size](https://git-lfs.com/), including it could complicate version control management with Git.

### Obtaining the Model File

1. Download pretrained [Ultralytics YOLO](https://docs.ultralytics.com/models/) models from the official [Ultralytics GitHub repository](https://github.com/ultralytics/ultralytics).
2. Convert the downloaded model (e.g., `yolo11n.pt`) to the Core ML format using the [Ultralytics `export` mode](https://docs.ultralytics.com/modes/export/). See our [Core ML integration guide](https://docs.ultralytics.com/integrations/coreml/) for detailed instructions.
2. Convert the downloaded model (e.g., `yolo26n.pt`) to the Core ML format using the [Ultralytics `export` mode](https://docs.ultralytics.com/modes/export/). See our [Core ML integration guide](https://docs.ultralytics.com/integrations/coreml/) for detailed instructions.

```python
from ultralytics import YOLO

# Load the YOLO11 nano detection model
model = YOLO("yolo11n.pt")
# Load the YOLO26 nano detection model
model = YOLO("yolo26n.pt")

# Export the model to Core ML format
# Export the model to Core ML format (YOLO26 detect is NMS-free)
# See https://docs.ultralytics.com/integrations/coreml/ for more details
model.export(format="coreml")
model.export(format="coreml", nms=False)
```

### Adding Model Files to the Project

**IMPORTANT**: The model file (`yolo11n.mlpackage`) **must** be added to the **main application target** (`YOLO-RealTime-UIKit`) within your [Xcode project](https://developer.apple.com/xcode/), not just the test target. This ensures the model is correctly bundled and accessible by the main application.
**IMPORTANT**: The model file (`yolo26n.mlpackage`) **must** be added to the **main application target** (`YOLO-RealTime-UIKit`) within your [Xcode project](https://developer.apple.com/xcode/), not just the test target. This ensures the model is correctly bundled and accessible by the main application.

Follow these steps to add the model file correctly:

1. Drag and drop `yolo11n.mlpackage` into your Xcode project navigator.
1. Drag and drop `yolo26n.mlpackage` into your Xcode project navigator.
2. In the "Choose options for adding these files" dialog:
- Ensure the checkbox for the **"YOLO-RealTime-UIKit" target** (the main app target) is **checked**.
- Optionally, check the "YOLO-RealTime-UIKitTests" target, but remember the main target is crucial for the tests to access the model.
Expand Down Expand Up @@ -68,12 +68,12 @@ By default, the `SKIP_MODEL_TESTS` flag within the test files is set to `true`.

To execute the **complete** test suite, including tests that require the model to perform actual inference:

1. Ensure you have added the required `yolo11n.mlpackage` file to the **main application target** as detailed in the "Adding Model Files to the Project" section above.
1. Ensure you have added the required `yolo26n.mlpackage` file to the **main application target** as detailed in the "Adding Model Files to the Project" section above.
2. Locate the primary test file (e.g., `YOLORealTimeUIKitTests.swift`) and change the `SKIP_MODEL_TESTS` flag to `false`.
3. Run the tests again using Xcode's testing tools (Shortcut: Cmd+U).

This tiered testing approach provides flexibility, ensuring that both fundamental application logic and the critical model integration can be thoroughly validated, depending on the availability of the model files.

## Contributing
## 🤝 Contributing

Contributions to enhance the YOLO RealTime UIKit example application and its tests are highly encouraged! If you have suggestions, identify bugs, or want to propose improvements, please feel free to open an issue or submit a pull request in the main [Ultralytics repository](https://github.com/ultralytics/ultralytics). For more detailed guidance on contributing, please see our [Contributing Guide](https://docs.ultralytics.com/help/contributing/). Thank you for helping make Ultralytics better!
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import XCTest
/// of the app, including model initialization, camera configuration, and UI interactions.
///
/// - Note: These tests require the application to be built with testing enabled.
/// - Important: Some tests may require the YOLO11 detection model to be available.
/// - Important: Some tests may require the YOLO26 detection model to be available.
struct YOLORealTimeUIKitTests {

// Flag to skip model-dependent tests if model is not available
Expand All @@ -43,7 +43,7 @@ struct YOLORealTimeUIKitTests {
}

let frame = CGRect(x: 0, y: 0, width: 640, height: 480)
let yoloView = await YOLOView(frame: frame, modelPathOrName: "yolo11n", task: .detect)
let yoloView = await YOLOView(frame: frame, modelPathOrName: "yolo26n", task: .detect)

// Allow some time for initialization to complete
try await Task.sleep(for: .seconds(0.5))
Expand All @@ -69,7 +69,7 @@ struct YOLORealTimeUIKitTests {
}

let frame = CGRect(x: 0, y: 0, width: 640, height: 480)
let yoloView = await YOLOView(frame: frame, modelPathOrName: "yolo11n", task: .detect)
let yoloView = await YOLOView(frame: frame, modelPathOrName: "yolo26n", task: .detect)

// Allow some time for initialization to complete
try await Task.sleep(for: .seconds(0.5))
Expand Down Expand Up @@ -113,7 +113,7 @@ struct YOLORealTimeUIKitTests {
}

let frame = CGRect(x: 0, y: 0, width: 640, height: 480)
let yoloView = await YOLOView(frame: frame, modelPathOrName: "yolo11n", task: .detect)
let yoloView = await YOLOView(frame: frame, modelPathOrName: "yolo26n", task: .detect)

// Allow some time for initialization to complete
try await Task.sleep(for: .seconds(0.5))
Expand Down Expand Up @@ -173,7 +173,7 @@ struct YOLORealTimeUIKitTests {

// Create YOLOView with valid model
let frame = CGRect(x: 0, y: 0, width: 640, height: 480)
let yoloView = await YOLOView(frame: frame, modelPathOrName: "yolo11n", task: .detect)
let yoloView = await YOLOView(frame: frame, modelPathOrName: "yolo26n", task: .detect)

// Allow initialization to complete
try await Task.sleep(for: .seconds(0.5))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct ContentView: View {
@State private var inputImage: UIImage?
@State private var yoloResult: YOLOResult?

let yolo = YOLO("yolo11n", task: .detect)
let yolo = YOLO("yolo26n", task: .detect)

var body: some View {
VStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@ Follow these instructions to set up and run the unit tests for the application.

To execute these tests, you will need the following [Core ML](https://developer.apple.com/documentation/coreml) model file:

- `yolo11n-seg.mlpackage` - An [Ultralytics YOLO11](../models/yolo11.md) [segmentation model](../tasks/segment.md).
- `yolo26n-seg.mlpackage` - An [Ultralytics YOLO26](https://platform.ultralytics.com/ultralytics/yolo26) [segmentation model](https://docs.ultralytics.com/tasks/segment/).

**Note**: This model file is **not included** in the repository due to its large size. You must obtain and add it manually.

### Obtaining the Model File

1. Download pretrained [Ultralytics YOLO11 models](https://docs.ultralytics.com/models/yolo11/) from the [Ultralytics GitHub repository](https://github.com/ultralytics/ultralytics).
1. Download pretrained [Ultralytics YOLO26 models](https://platform.ultralytics.com/ultralytics/yolo26) from the [Ultralytics GitHub repository](https://github.com/ultralytics/ultralytics).
2. Convert the [PyTorch](https://pytorch.org/) model (`.pt`) to Core ML format (`.mlpackage`) using the Ultralytics `export` functionality:

```python
from ultralytics import YOLO

# Load the YOLO11 nano segmentation model
model = YOLO("yolo11n-seg.pt")
# Load the YOLO26 nano segmentation model
model = YOLO("yolo26n-seg.pt")

# Export the model to Core ML format
model.export(format="coreml") # Creates yolo11n-seg.mlpackage
model.export(format="coreml") # Creates yolo26n-seg.mlpackage
```

For more details on exporting models, refer to the [Ultralytics Export documentation](../modes/export.md).
For more details on exporting models, refer to the [Ultralytics Export documentation](https://docs.ultralytics.com/modes/export/).

### Adding Model Files to the Project

**IMPORTANT**: The `.mlpackage` model file must be added to the **main application target** (`YOLO-Single-Image-SwiftUI`) in [Xcode](https://developer.apple.com/xcode/), not just the test target. The testing framework relies on accessing the model through the main application bundle (`Bundle.main`).

Follow these steps to add the model file correctly using Xcode:

1. Drag and drop the `yolo11n-seg.mlpackage` file into your Xcode project navigator.
1. Drag and drop the `yolo26n-seg.mlpackage` file into your Xcode project navigator.
2. In the "Choose options for adding these files" dialog:
- Ensure the checkbox for the **`YOLO-Single-Image-SwiftUI`** target (the main app) is selected.
- You may optionally select the `YOLO-Single-Image-SwiftUITests` target, but the main target is essential.
Expand All @@ -50,7 +50,7 @@ For better project organization, consider placing the model file within a "Model

![Adding model to target in Xcode](https://docs-assets.developer.apple.com/published/abd9789384/ff4127a0-80a6-4716-b1cd-fc1facce5d8e.png)

## 📊 Testing Strategy
### Testing Strategy

These unit tests verify several key aspects of the application:

Expand All @@ -67,7 +67,7 @@ By default, the `SKIP_MODEL_TESTS` flag in the test files is set to `true`. This

To run the complete test suite, including tests that perform actual model inference:

1. Ensure you have added the required `yolo11n-seg.mlpackage` file to the **main application target** as described in the "Adding Model Files" section.
1. Ensure you have added the required `yolo26n-seg.mlpackage` file to the **main application target** as described in the "Adding Model Files" section.
2. Locate the `SKIP_MODEL_TESTS` flag within the test source file (e.g., `YOLO_Single_Image_SwiftUITests.swift`) and set it to `false`.
3. Run the tests again using Xcode's Test navigator (Cmd+U).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import XCTest
/// of the app, including model initialization, image processing, and UI interactions.
///
/// - Note: These tests require the application to be built with testing enabled.
/// - Important: Some tests may require the YOLO11 segmentation model to be available.
/// - Important: Some tests may require the YOLO26 segmentation model to be available.
struct YOLOSingleImageSwiftUITests {

// Flag to skip model-dependent tests if model is not available
Expand Down Expand Up @@ -82,7 +82,7 @@ struct YOLOSingleImageSwiftUITests {

// Since this is a model-dependent test, we'll focus on checking
// that the model can be initialized without waiting for completion
let yolo = YOLO("yolo11n-seg", task: .segment)
let yolo = YOLO("yolo26n-seg", task: .segment)

// Basic check that the model exists
#expect(yolo != nil, "YOLO model should initialize")
Expand Down Expand Up @@ -120,7 +120,7 @@ struct YOLOSingleImageSwiftUITests {
// without relying on the model being fully loaded

// Initialize the model
let yolo = YOLO("yolo11n-seg", task: .segment)
let yolo = YOLO("yolo26n-seg", task: .segment)

// Create a test image that would be used for inference
let size = CGSize(width: 640, height: 640)
Expand Down
Loading