본 레포지토리는 이미지 질의 응답 작업을 위한 BLIP-2의 학습 및 추론 코드를 제공합니다.
원본 코드는 salesforce의 BLIP-2임을 밝힙니다.
아래에는 이 레포지토리에 대한 자세한 정보와 사용 방법, 저작권 및 라이센스 세부 정보를 제공합니다.
BLIP-2는 이미지 인코더와 대규모 언어 모델을 결합한 구조로 이루어져 있습니다. 이 모델은 'Querying Transformer'라 불리는 경량화된 변환 모델을 활용하여 이미지와 텍스트 간의 정보를 효과적으로 연결합니다. BLIP-2는 모달리티 간의 간격을 메우는 데 중점을 두며, 이를 통해 비전과 언어를 결합한 학습이 가능합니다.
BLIP-2의 학습 과정은 두 단계로 구성됩니다:
이러한 구조와 학습 방법 덕분에 BLIP-2는 기존 모델에 비해 훨씬 적은 수의 학습 가능한 파라미터를 가지면서도 뛰어난 성능을 달성했습니다. 예를 들어, 학습 가능한 파라미터가 54배 적은 BLIP-2는 제로샷 VQAv2 작업에서 Flamingo80B 모델보다 8.7% 높은 성능을 보여주었습니다.
또한, BLIP-2 모델은 "24번 한국어 GQA 데이터"라는 장문형 질의응답 데이터를 사용하여 파인튜닝되었습니다. 이 데이터는 2023년 인공지능 학습용 데이터 구축사업의 일환으로 제공되었으며, BLIP-2의 언어 이해 및 생성 능력을 한층 더 향상시키는 데 기여했습니다.
이러한 특징과 성능은 BLIP-2를 비전-언어 관련 다양한 작업에서 최선의 선택으로 만들며, 동시에 기존 방법들보다 효율적인 모델 구조를 제공합니다.
pip3 install -r requirements.txt
pip3 install --force-reinstall timm==0.9.7
python3 preprocess.py
# 단일 GPU를 사용하는 경우:
python3 train.py
# 다중 GPU를 사용하는 경우: multi_gpu_config.yaml 파일의 num_processes 인자에 사용할 GPU 개수 입력(기본값:4)
accelerate launch --config_file multi_gpu_config.yaml train_multi.py
# ex) GPU 1번과 3번을 사용하는 경우
accelerate launch --config_file multi_gpu_config.yaml train_multi.py --gpu_num 1,3
output 디렉토리 아래 model_best.pth 이름으로 저장되며 학습 중 갱신됩니다.# 단일 GPU를 사용하는 경우:
python3 test.py
# 다중 GPU를 사용하는 경우: multi_gpu_config.yaml 파일의 num_processes 인자에 사용할 GPU 개수 입력(기본값:4)
accelerate launch --config_file multi_gpu_config.yaml test_multi.py
# ex) GPU 1번과 3번을 사용하는 경우
accelerate launch --config_file multi_gpu_config.yaml test_multi.py --gpu_num 1,3
python3 inference.py --img_path sample_data/C-220705_07_CR14_03_A1147_add.jpg
출력 : Predicted class name: BMW#1시리즈_F20(2012)
demo 폴더 내 'app.py' 파일을 다음 명령어를 사용하여 실행하면, 웹페이지를 통해 모델을 직접 테스트해 볼 수 있습니다.
python3 demo/app.py
@inproceedings{li2023blip2,
title={{BLIP-2:} Bootstrapping Language-Image Pre-training with Frozen Image Encoders and Large Language Models},
author={Junnan Li and Dongxu Li and Silvio Savarese and Steven Hoi},
year={2023},
booktitle={ICML},
}
BSD 3-Clause License
Copyright (c) 2022 Salesforce, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Please adhere to the above license terms and conditions when using this model. For any queries or further clarification, feel free to reach out to our support team.
Thank you for choosing our AI model for your applications.
1 commits
Jupyter Notebook
94.6%
Python
5.4%
본 레포지토리는 이미지 질의 응답 작업을 위한 BLIP-2의 학습 및 추론 코드를 제공합니다.
원본 코드는 salesforce의 BLIP-2임을 밝힙니다.
아래에는 이 레포지토리에 대한 자세한 정보와 사용 방법, 저작권 및 라이센스 세부 정보를 제공합니다.
BLIP-2는 이미지 인코더와 대규모 언어 모델을 결합한 구조로 이루어져 있습니다. 이 모델은 'Querying Transformer'라 불리는 경량화된 변환 모델을 활용하여 이미지와 텍스트 간의 정보를 효과적으로 연결합니다. BLIP-2는 모달리티 간의 간격을 메우는 데 중점을 두며, 이를 통해 비전과 언어를 결합한 학습이 가능합니다.
BLIP-2의 학습 과정은 두 단계로 구성됩니다:
이러한 구조와 학습 방법 덕분에 BLIP-2는 기존 모델에 비해 훨씬 적은 수의 학습 가능한 파라미터를 가지면서도 뛰어난 성능을 달성했습니다. 예를 들어, 학습 가능한 파라미터가 54배 적은 BLIP-2는 제로샷 VQAv2 작업에서 Flamingo80B 모델보다 8.7% 높은 성능을 보여주었습니다.
또한, BLIP-2 모델은 "24번 한국어 GQA 데이터"라는 장문형 질의응답 데이터를 사용하여 파인튜닝되었습니다. 이 데이터는 2023년 인공지능 학습용 데이터 구축사업의 일환으로 제공되었으며, BLIP-2의 언어 이해 및 생성 능력을 한층 더 향상시키는 데 기여했습니다.
이러한 특징과 성능은 BLIP-2를 비전-언어 관련 다양한 작업에서 최선의 선택으로 만들며, 동시에 기존 방법들보다 효율적인 모델 구조를 제공합니다.
pip3 install -r requirements.txt
pip3 install --force-reinstall timm==0.9.7
python3 preprocess.py
# 단일 GPU를 사용하는 경우:
python3 train.py
# 다중 GPU를 사용하는 경우: multi_gpu_config.yaml 파일의 num_processes 인자에 사용할 GPU 개수 입력(기본값:4)
accelerate launch --config_file multi_gpu_config.yaml train_multi.py
# ex) GPU 1번과 3번을 사용하는 경우
accelerate launch --config_file multi_gpu_config.yaml train_multi.py --gpu_num 1,3
output 디렉토리 아래 model_best.pth 이름으로 저장되며 학습 중 갱신됩니다.# 단일 GPU를 사용하는 경우:
python3 test.py
# 다중 GPU를 사용하는 경우: multi_gpu_config.yaml 파일의 num_processes 인자에 사용할 GPU 개수 입력(기본값:4)
accelerate launch --config_file multi_gpu_config.yaml test_multi.py
# ex) GPU 1번과 3번을 사용하는 경우
accelerate launch --config_file multi_gpu_config.yaml test_multi.py --gpu_num 1,3
python3 inference.py --img_path sample_data/C-220705_07_CR14_03_A1147_add.jpg
출력 : Predicted class name: BMW#1시리즈_F20(2012)
demo 폴더 내 'app.py' 파일을 다음 명령어를 사용하여 실행하면, 웹페이지를 통해 모델을 직접 테스트해 볼 수 있습니다.
python3 demo/app.py
@inproceedings{li2023blip2,
title={{BLIP-2:} Bootstrapping Language-Image Pre-training with Frozen Image Encoders and Large Language Models},
author={Junnan Li and Dongxu Li and Silvio Savarese and Steven Hoi},
year={2023},
booktitle={ICML},
}
BSD 3-Clause License
Copyright (c) 2022 Salesforce, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Please adhere to the above license terms and conditions when using this model. For any queries or further clarification, feel free to reach out to our support team.
Thank you for choosing our AI model for your applications.
1 commits
Jupyter Notebook
94.6%
Python
5.4%