Instructions to use microsoft/Florence-2-large with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/Florence-2-large with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="microsoft/Florence-2-large", trust_remote_code=True)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large", trust_remote_code=True) model = AutoModelForMultimodalLM.from_pretrained("microsoft/Florence-2-large", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use microsoft/Florence-2-large with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/Florence-2-large" # 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-large", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/microsoft/Florence-2-large
- SGLang
How to use microsoft/Florence-2-large 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-large" \ --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-large", "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-large" \ --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-large", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use microsoft/Florence-2-large with Docker Model Runner:
docker model run hf.co/microsoft/Florence-2-large
Segmentation Issue with identifying multiples, or contiguous objects
Hi, great work on this!
The captioning works well.
When it comes to segmentation, I believe there's a potential issue with identifying multiples of things, or objectsthat are contiguous but interrupted in the photo by feet/legs/etc.
I am using in ComfyUI but the base model is direct from this huggingface repo.
For a test, you can see I selected wings and then dogs, but I got only 1 of those objects returned:
And here we have it compared to groundingdino segmentation, and you can see the floor is only half-identified in top masking (Florence) vs the bottom masking (groundingdino):
Just wanted to raise this as a potential improvement point. Thank you for your help and time.
hi @TardyTurtle , thanks for raising the point. One workaround to get segmentation results for multiple objects is to use two step approach. First, you could get the boxes of the objects. then for each box, region to segmentation could be utilized to get the mask results.
@haipingwu Hi, I am wondering if it is possible to fine tune the model to get segmentation results for multiple objects? Thank you!
@eternalaudrey ,Were you able to generate masks for multiple objects?
If yes, could you tell me how you did it?
@eternalaudrey ,Were you able to generate masks for multiple objects?
If yes, could you tell me how you did it?
Hi, unfortunately not. For the moment I can just do object detection task and generate a series of bounding boxes. Then run a loop to generate the masks using the regions (bbox) iteratively, which is much inefficient.

