mlboydaisuke's picture
Add README.md
b6f23d1 verified
|
Raw
History Blame Contribute Delete
3.8 kB
metadata
license: mit
library_name: coreml
pipeline_tag: image-text-to-text
base_model: microsoft/Florence-2-base
base_model_relation: quantized
tags:
  - 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.

Florence-2 demo Florence-2 demo

Core ML conversion of microsoft/Florence-2 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
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

hf download mlboydaisuke/coreml-zoo --include "florence2/*" --local-dir ./florence2
unzip './florence2/florence2/*.zip' -d ./florence2

Use in Swift

import 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

Conversion

License

The conversion inherits the upstream license: MIT.

Credits