Instructions to use microsoft/Florence-2-base-ft with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/Florence-2-base-ft with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="microsoft/Florence-2-base-ft", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("microsoft/Florence-2-base-ft", trust_remote_code=True) model = AutoModelForMultimodalLM.from_pretrained("microsoft/Florence-2-base-ft", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use microsoft/Florence-2-base-ft with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/Florence-2-base-ft" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Florence-2-base-ft", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/microsoft/Florence-2-base-ft
- SGLang
How to use microsoft/Florence-2-base-ft with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "microsoft/Florence-2-base-ft" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Florence-2-base-ft", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "microsoft/Florence-2-base-ft" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Florence-2-base-ft", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use microsoft/Florence-2-base-ft with Docker Model Runner:
docker model run hf.co/microsoft/Florence-2-base-ft
Update README.md
Browse files109 unmodified lines11011111211311411511611711811912012112212312412512612712812913 unmodified lines14314414514614714823 unmodified lines172173174175176177178179180181182183184185109 unmodified lines<details><summary> Click to expand </summary>### OCR```pythonprompt = "<OCR>"run_example(prompt)```### OCR with RegionOCR with region output format:{'\<OCR_WITH_REGION>': {'quad_boxes': [[x1, y1, x2, y2, x3, y3, x4, y4], ...], 'labels': ['text1', ...]}}```pythonprompt = "<OCR_WITH_REGION>"run_example(prompt)```### Caption```python13 unmodified linesrun_example(prompt)```### Object DetectionOD results format:23 unmodified linesrun_example(prompt)```### Caption to Phrase Groundingcaption to phrase grounding task requires additional text input, i.e. caption.Caption to phrase grounding results format:{'\<CAPTION_TO_PHRASE_GROUNDING>': {'bboxes': [[x1, y1, x2, y2], ...], 'labels': ['', '', ...]}}```pythontask_prompt = '<CAPTION_TO_PHRASE_GROUNDING>"results = run_example(task_prompt, text_input="A green car parked in front of a yellow building.")```for More detailed examples, please refer to [notebook](https://huggingface.co/microsoft/Florence-2-large/blob/main/sample_inference.ipynb)109 unmodified lines11011111211311411513 unmodified lines12913013113213313413513613713813914014114214314423 unmodified lines168169170171172173174175176177178179180181182183184185186187109 unmodified lines<details><summary> Click to expand </summary>### Caption```python13 unmodified linesrun_example(prompt)```### Caption to Phrase Groundingcaption to phrase grounding task requires additional text input, i.e. caption.Caption to phrase grounding results format:{'\<CAPTION_TO_PHRASE_GROUNDING>': {'bboxes': [[x1, y1, x2, y2], ...], 'labels': ['', '', ...]}}```pythontask_prompt = '<CAPTION_TO_PHRASE_GROUNDING>"results = run_example(task_prompt, text_input="A green car parked in front of a yellow building.")```### Object DetectionOD results format:23 unmodified linesrun_example(prompt)```### OCR```pythonprompt = "<OCR>"run_example(prompt)```### OCR with RegionOCR with region output format:{'\<OCR_WITH_REGION>': {'quad_boxes': [[x1, y1, x2, y2, x3, y3, x4, y4], ...], 'labels': ['text1', ...]}}```pythonprompt = "<OCR_WITH_REGION>"run_example(prompt)```for More detailed examples, please refer to [notebook](https://huggingface.co/microsoft/Florence-2-large/blob/main/sample_inference.ipynb)
README.md+22-20