LLaVA-Med Documentation

repository·main·Indexed 24 days ago

https://github.com/microsoft/llava-med

LLaVA-Med is a Large Language and Vision Assistant tuned for the biomedicine domain, designed for medical visual instruction tuning. Version 1.5.0 supports models such as microsoft/llava-med-v1.5-mistral-7b. The repository provides tools for medical visual chat, GPT-assisted evaluation, and a Gradio-based Web UI. It is intended for research purposes only and is not for clinical use.

Tokens
1.9K
Snippets
4
Records
11
Agent score
81%

What's inside LLaVA-Med

  1. Understand the intended use and limitations of LLaVA-Med

    main

    LLaVA-Med is a large language and vision model designed for biomedical research.

    Intended Use

    • Research Only: The model, code, and data are intended solely for future research on visual-language processing and for reproducing experimental results from the reference paper.
    • Not for Clinical Use: The model is not intended for clinical care, clinical decision-making, or any deployed use cases (commercial or otherwise).

    Limitations

    • Language: Developed using English corpora and may be considered English-only.
    • Domain Scope: Evaluated on a narrow set of biomedical benchmark tasks.
    • Accuracy: May make inaccurate predictions and inherits limitations from the base LLaVA model.
    • Data Bias: Built using the PMC-15M dataset, which may contain biases reflecting academic publication practices (e.g., enrichment for positive findings or extreme cases).
  2. Understand LLaVA-Med-1.5 Performance Metrics

    main
    LLaVA-Med-1.5 performance is measured by its multimodal chat instruction-following abilities. Evaluation is conducted using relative scores derived from GPT-4 language evaluation, comparing the model's ability to follow instructions based on visual and textual inputs.
  3. Understand LLaVA-Med-1.0 Performance and Benchmarks

    main

    LLaVA-Med-1.0 performance is evaluated across several dimensions:

    1. Medical Visual Chat: Compared against a language-only GPT-4 baseline. In this baseline, GPT-4 is provided with golden captions and inline mentions as context, representing the performance upper bound because it does not need to process the raw image.
    2. Medical VQA: Performance is measured by fine-tuning LLaVA-Med on established Medical Question Answering (QVA) datasets.

    Note that standard LLaVA models tend to hallucinate or refuse to provide domain-specific knowledgeable responses in medical contexts, which LLaVA-Med is designed to address.

  4. Serve LLaVA-Med via Web UI

    main

    To use the LLaVA-Med Web UI, you must launch three components in order: a controller, a model worker, and finally the Gradio web server.

    If your GPU VRAM is $\le$ 24GB (e.g., RTX 3090, RTX 4090), you can use the --num-gpus flag to distribute the model across multiple GPUs.

  5. Perform Medical Visual Chat (GPT-assisted Evaluation)

    main

    The GPT-assisted evaluation pipeline assesses multimodal modeling capabilities using GPT-4. This process involves four main steps: configuring Azure OpenAI credentials, downloading images, running multimodal chat inference, and using GPT-4 to score and summarize the results.

    # 1. Configure Azure OpenAI in llava/eval/llm.py (See documentation for details)
    
    # 2. Download Images
    python llava/data/download_images.py \
        --input_path data/llava_med_test_image_urls.jsonl \
        --pmc_output_path data/pmc \
        --images_output_path data/images
    
    # 3. Multimodal Chat Inference
    PYTHONPATH=. python llava/eval/model_vqa.py \
        --conv-mode mistral_instruct \
        --model-path microsoft/llava-med-v1.5-mistral-7b \
        --question-file data/eval/llava_med_eval_qa50_qa.jsonl \
        --image-folder data/images \
        --answers-file /path/to/answer-file.jsonl \
        --temperature 0.0
    
    # 4. GPT-4 Evaluation of the Generated Answers
    python llava/eval/eval_multimodal_chat_gpt_score.py \
        --answers-file /path/to/answer-file.jsonl \
        --question-file data/eval/llava_med_eval_qa50_qa.jsonl \
        --scores-file /path/to/scores-file.jsonl
    
    # 5. Summarize the Evaluation Results
    python llava/eval/summarize_gpt_review.py \
        --scores-file /path/to/scores-file.jsonl
  6. Install LLaVA-Med

    main

    To install LLaVA-Med, clone the repository, navigate to the folder, and set up a Conda environment with Python 3.10. Ensure you upgrade pip to enable PEP 660 support before installing the package in editable mode.

    https://github.com/microsoft/LLaVA-Med.git
    cd LLaVA-Med
    
    conda create -n llava-med python=3.10 -y
    conda activate llava-med
    pip install --upgrade pip  # enable PEP 660 support
    pip install -e .
  7. Download LLaVA-Med Datasets

    main

    To download the language-image multimodal instruction-following dataset, run the provided shell script. You can also manually download specific files such as alignment data, instruction-tuning data, or evaluation files from the repository.

    sh download_data.sh
  8. Run the LLaVA-Med CLI for interactive visual chat

    main
    The llava/serve/cli.py script provides a command-line interface for interactive visual chat with a LLaVA-Med model. It allows you to load a pretrained model, provide an initial image, and engage in a multi-turn conversation. The script supports quantization (4-bit and 8-bit) and configurable generation parameters like temperature and token limits.
  9. Cite LLaVA-Med in research

    main

    If you use LLaVA-Med in your research, please cite the following BibTeX entry:

    @article{li2023llavamed,
      title={Llava-med: Training a large language-and-vision assistant for biomedicine in one day},
      author={Li, Chunyuan and Wong, Cliff and Zhang, Sheng and Usuyama, Naoto and Liu, Haotian and Yang, Jianwei and Naumann, Tristan and Poon, Hoifung and Gao, Jianfeng},
      journal={arXiv preprint arXiv:2306.00890},
      year={2023}
    }
  10. Reference the LLaVA-Med CLI arguments

    main

    The following command-line arguments are available when running the LLaVA-Med CLI:

    ArgumentTypeDefaultDescription
    --model-pathstrfacebook/opt-350mPath to the pretrained model weights.
    --model-basestrNoneBase model path (used for certain fine-tuning/adapter setups).
    --image-filestrRequiredPath to the local image file or a URL (http/https) to an image.
    --devicestrcudaDevice to run the model on (e.g., cuda, cpu).
    --conv-modestrNoneConversation template mode (e.g., llava_v1, mistral_instruct). If None, it is auto-inferred from the model name.
    --temperaturefloat0.2Sampling temperature. Higher values make output more random.
    --max-new-tokensint512Maximum number of new tokens to generate.
    --load-8bitflagFalseLoad the model in 8-bit precision.
    --load-4bitflagFalseLoad the model in 4-bit precision.
    --debugflagFalsePrint the raw prompt and outputs for debugging.