cd Agri-LLaVA
conda create -n agrillava python=3.10 -y
conda activate agrillava
pip install --upgrade pip # enable PEP 660 support
pip install -e .
pip install -e ".[train]"
pip install flash-attn --no-build-isolation
All of our data can be found in Huggingface
Our Agri-400K consists of:
- Agricultural pests and diseases feature alignment data
- Agricultural pests and diseases instruction-tuning data
Agri-LLaVA is trained on 8 A800 GPUs, with the entire training process taking 11 hours and 20 minutes.
Hyperparameter | Global Batch Size | Learning rate | Epochs | Max length | Weight decay |
---|---|---|---|---|---|
Agri-LLaVA | 256 | 1e-3 | 1 | 2048 | 0 |
Please download the agricultural pests and diseases feature alignment data for pre-training from here
You can use the script to pre-train: pretrain.sh
.
Hyperparameter | Global Batch Size | Learning rate | Epochs | Max length | Weight decay |
---|---|---|---|---|---|
Agri-LLaVA | 128 | 2e-5 | 3 | 2048 | 0 |
Please download the agricultural pests and diseases instruction-tuning data for fine-tuning from here
You can use the following scripts to fine-tune:
- Full fine-tune:
finetune.sh
. - Lora fine-tune:
finetune_lora.sh
.
Please download the Agri-LLaVA-Chatbot-Bench data for evaluating from here
- Generate Agri-LLaVA responses on Agri-LLaVA-Chatbot-Bench.
python agri_llava/eval/model_vqa.py \
--model-path /path/to/model_checkpoint \
--question-file \
/path/to/agri_llava_chatbot_question.jsonl \
--image-folder \
/path/to/image_folder \
--answers-file \
/path/to/agri_llava_chatbot_answer_our.jsonl
- Evaluate the generated responses. In the command,
agri_llava_chatbot_answer.jsonl
refers to the reference answer generated by language-only GPT-4 based on knowledge.
python agri_llava/eval/eval_gpt_review_visual.py \
--question /path/to/agri_llava_chatbot_question.jsonl \
--answer-list \
/path/to/agri_llava_chatbot_answer.jsonl \
/path/to/agri_llava_chatbot_answer_our.jsonl \
--rule agri_llava/eval/eval_metrics/rule.json \
--output /path/to/review.jsonl
- Summarize the evaluation results
python agri_llava/eval/summarize_gpt_review.py
Please download the Agri-LLaVA-VQA-Bench data for evaluating from here.
We use the same scripts to adapt Agri-LLaVA to downstream tasks:
- Full fine-tune:
finetune.sh
. - Lora fine-tune:
finetune_lora.sh
.
- Generate Agri-LLaVA responses on Agri-LLaVA-VQA-Bench.
python agri_llava/eval/model_vqa.py \
--model-path /path/to/model_checkpoint \
--question-file \
/path/to/agri_llava_vqa_test_question.jsonl \
--image-folder \
/path/to/image_folder \
--answers-file \
/path/to/agri_llava_vqa_answer_our.jsonl
- Evaluate the generated responses.
python agri_llava/eval/run_eval.py \
--gt /path/to/agri_llava_vqa_test_answer.json \
--pred /path/to/agri_llava_vqa_answer_our.jsonl
We sincerely appreciate LLaVA for making their models and code available as open-source contributions.