This API generates precise, localized, and contextually relevant captions that enhance situational awareness for BVIPs during outdoor navigation using LLaVA-Next (Mistral-7B) model.
The API processes:
- An RGB image (scene)
- A segmentation mask (grayscale)
The output is a caption describing sidewalks, crossings, signals, obstacles, and directional cues from the pedestrian’s perspective.
├── src/app.py # FastAPI application
├── llava-v1.6-mistral-7b-hf/ # base LLaVA-Next model
├── image_mask_model/ # PEFT/LoRA checkpoint folder
llava-v1.6-mistral-7b-hf/→ put the base model here (Download).image_mask_model/→ put the fine-tuned PEFT checkpoint here (Download).- If these folders are missing, the app will raise an error at startup.
First of all, install dependencies and check for the required folders and its contents.
-
Install dependencies:
pip install -r requirements.txt
-
Check that model folders and its contents exist:
llava-v1.6-mistral-7b-hf/image_mask_model/
-
Running the API:
Start the server with:
uvicorn api.app:app --host 0.0.0.0 --port 8000 --reload &
input-api-key(required) — API key.rgb(required) — RGB scene image (JPEG/PNG).mask(required) — grayscale segmentation mask (same scene).question(optional) — defaults to"What do you see in the image?".
curl -X POST \
"http://localhost:8000/generate-caption/" \
-H "input-api-key: LLaVA_Next_API" \
-F "rgb=@/path/to/scene.jpg" \
-F "mask=@/path/to/mask.png" \
-F "question=What do you see in the image?""The sidewalk is centered in the view, bordered by a hedge on the left and a road on the right. A large yellow utility box is positioned on the right side of the sidewalk, partially obstructing the path."
- The corresponding
maskinput must be grayscale (NOT RGB segmentation mask). - GPU is strongly recommended. 4-bit quantization will not work well on CPU.
- Every request must include an API key header:
input_api_key: LLaVA_Next_API. (Default key is set inapp.py→ changeAPI_KEYif you want your own.)