Add model card
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394---license: mitlibrary_name: coremlpipeline_tag: image-text-to-textbase_model: microsoft/Florence-2-basebase_model_relation: quantizedtags: - coreml - core-ml - ios - macos - apple - on-device - vision-language - captioning - ocr - grounding - arxiv:2311.06242---
# Florence-2 — Core ML
*Microsoft, 2024*
Vision-language captioning, OCR, and VQA. Three-stage encoder-decoder. 768×768 input.
Core ML conversion of [microsoft/Florence-2](https://huggingface.co/microsoft/Florence-2-base) for on-device inference on iPhone, iPad and Mac. Converted with `coremltools`; the packages are stateless, so all sequencing and buffering lives in your Swift code.
| | ||---|---|| Task | image text to text || Upstream | [microsoft/Florence-2](https://huggingface.co/microsoft/Florence-2-base) || Packages | 3 || Download size | 229 MB || Minimum iOS | 17.0 || Peak RAM | ~1200 MB |
## Files
| File | Size | Compute units | SHA-256 ||---|---:|---|---|| `Florence2VisionEncoder.mlpackage.zip` | 77 MB | `cpuOnly` | `9422f189c21220a0…` || `Florence2TextEncoder.mlpackage.zip` | 69 MB | `cpuOnly` | `f985deeef0408ea8…` || `Florence2Decoder.mlpackage.zip` | 81 MB | `cpuOnly` | `fe85a6faab528127…` || `florence2_vocab.json` | 976 KB | `-` | `861fee9af5520403…` || **Total** | **229 MB** | | |
`compute_units` is not a suggestion -- it is the configuration the conversion was verified against. Moving a package to a different compute unit can silently change the numerics (FP16 attention overflow) or crash on the GPU.
## Download
```bashhf download mlboydaisuke/coreml-zoo --include "florence2/*" --local-dir ./florence2unzip './florence2/florence2/*.zip' -d ./florence2```
## Use in Swift
```swiftimport CoreML
let config = MLModelConfiguration()config.computeUnits = .cpuOnly // as converted — see the table above
// Unzip the .mlpackage, drop it into your Xcode target and Xcode compiles it// at build time:let model = try Florence2VisionEncoder(configuration: config)
// ...or compile a downloaded .mlpackage at runtime:let compiled = try await MLModel.compileModel(at: mlpackageURL)let model = try MLModel(contentsOf: compiled, configuration: config)```
> This model is split into 3 Core ML packages that are driven in sequence from Swift. Load them one at a time, copy the outputs out of the `MLMultiArray` buffers and release each model before loading the next — two large Core ML models resident at once will OOM on an iPhone.
## Demo
- **Sample app** — [`sample_apps/Florence2Demo`](https://github.com/john-rocky/CoreML-Models/tree/master/sample_apps/Florence2Demo), a standalone SwiftUI project.- **Models Zoo** — this model is downloadable and runnable inside the [Models Zoo app](https://apps.apple.com/app/id6762083207) on the App Store, no build required.
## Conversion
- Script: [`convert_florence2.py`](https://github.com/john-rocky/CoreML-Models/blob/master/conversion_scripts/convert_florence2.py)- Pitfalls hit during conversion (FP16 overflow, ANE buffer limits, stride handling): [`docs/coreml_conversion_notes.md`](https://github.com/john-rocky/CoreML-Models/blob/master/docs/coreml_conversion_notes.md)- Model index: [CoreML-Models](https://github.com/john-rocky/CoreML-Models)
## License
The conversion inherits the upstream license: **MIT**.
## Credits
- Upstream authors: [microsoft/Florence-2](https://huggingface.co/microsoft/Florence-2-base), 2024- Core ML conversion: john-rocky (Daisuke Majima)README.mdAdded+94