Unifying Architectures, Tasks, and Modalities Through a Simple Sequence-to-Sequence Learning Framework
![image captioning](https://private-user-images.githubusercontent.com/75362328/268621865-69884bd3-b050-4aad-ab43-c2fae7c85e9c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwMzM5NjgsIm5iZiI6MTcyNDAzMzY2OCwicGF0aCI6Ii83NTM2MjMyOC8yNjg2MjE4NjUtNjk4ODRiZDMtYjA1MC00YWFkLWFiNDMtYzJmYWU3Yzg1ZTljLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE5VDAyMTQyOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTYyMmRmMDAwMWZjODQ3M2NkODE3NGM1Mzc2ZGZiYTg0ZTI1OTI5ZDg1MWExYzc0MDZmZGU5YzU3ZWI5ZGE4ZDEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.TnzY_XqpvxTwD0GyglWKfQpy359O0ZvEC4V33H_v5ZQ)
BLEU-4 Score 44.9 (2022 SOTA)
![vqa](https://private-user-images.githubusercontent.com/75362328/268621868-2436f122-cd2c-43b3-b8d8-e4bee1c0035b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwMzM5NjgsIm5iZiI6MTcyNDAzMzY2OCwicGF0aCI6Ii83NTM2MjMyOC8yNjg2MjE4NjgtMjQzNmYxMjItY2QyYy00M2IzLWI4ZDgtZTRiZWUxYzAwMzViLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE5VDAyMTQyOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQzYTBjM2VhN2Y4NzJhMmE4NDdhYWJkOGEwYTU2YTA1ZWUxMjA2YTUxZDRlNDExMDA2ZDQ1ZDI3Y2QyODY5MDUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Lr1sol5ewtAnEL00cm0zqoG3L8XOOV0SprTtpwAz-hE)
Accuracy 79.36 test-dev / Accuracy 79.48 test-std
![ve](https://private-user-images.githubusercontent.com/75362328/268621866-7bfa4ae9-f424-4186-b66c-127b3c4e5831.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwMzM5NjgsIm5iZiI6MTcyNDAzMzY2OCwicGF0aCI6Ii83NTM2MjMyOC8yNjg2MjE4NjYtN2JmYTRhZTktZjQyNC00MTg2LWI2NmMtMTI3YjNjNGU1ODMxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE5VDAyMTQyOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTdlNjhiZjU4YzBiOWQ5ZTk1NjhhNTg1MTQyNzAxNWM1YjQzZjdiOTAxM2ZmN2RkZDRkODBjZmE0N2NkYTYwZTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.UPP9re05-7JeavYDjqj6RdfjXWwi2kFtIGU7Lj5l29c)
Accuracy 91.2 test (SOTA) / Accuracy 91.0 val (SOTA)
- multimodal pretraining을 위한 통합된 패러다임을 구축함
- OFA(One-for-All)라는 unified multimodal pretrained model을 제시
- OFA는 단순한 sequence-to-sequence 학습 프레임워크를 기반으로 하고 인코더-디코더 구조를 사용
- OFA는 fine-tuning시 task-specific한 레이어를 요구하지도 않음
- OFA는 다양한 multimodal task에서 SOTA를 달성함은 물론이고 unimodal task 에서조차 unimodal 만을 위해 학습된 모델들과 동등한 수준의 성능을 보여줌
1. Task-Agnostic(TA): 분류, 생성, self-supervised pretext task 등의 다양한 과제에 공통적으로 사용할 수 있는 unified task representation를 활용해야 함
2. Modality-Agnostic(MA): 여러 가지 양식(modality)를 다룰 수 있는 unified input and output representation
3. Task Comprehensiveness(TC): generalization 능력을 얻을 수 있을 만큼의 과제(task) 다양성
- batch_size, 한 번 학습할 때 얼마나 많은 문장(max_sentences)을 학습할 것인지
- beam_size, 일정한 수의 가장 가능성 있는 후보를 유지하면서 시퀀스를 생성
import re
from PIL import Image
def inference(model_path, image_path):
# specify some options for evaluation
parser = options.get_generation_parser()
input_args = ["", "--task=vqa_gen", "--beam=100", "--unnormalized", f"--path=checkpoints/{model_path}.pt", "--bpe-dir=utils/BPE"]
args = options.parse_args_and_arch(parser, input_args)
cfg = convert_namespace_to_omegaconf(args)
# Load pretrained ckpt & config
task = tasks.setup_task(cfg.task)
models, cfg = checkpoint_utils.load_model_ensemble(
utils.split_paths(cfg.common_eval.path),
task=task
)
# Move models to GPU
for model in models:
model.eval()
if use_fp16:
model.half()
if use_cuda and not cfg.distributed_training.pipeline_model_parallel:
model.cuda()
model.prepare_for_inference_(cfg)
# Initialize generator
generator = task.build_generator(models, cfg.generation)
image = Image.open(f'./input_images/{image_path}')
questions = [
"Where is the person?",
"How many people are in the picture?",
"How is the weather like in the picture?",
"What accessories does the person wearing?",
"What kind of hairstyle does the person have?",
"What kind of shirt does a person wearing?",
"How old does the person look like exactly?",
"What country do you look like?"
]
display(image)
for idx, question in enumerate(questions):
sample = construct_sample(image, question)
sample = utils.move_to_cuda(sample) if use_cuda else sample
sample = utils.apply_to_sample(apply_half, sample) if use_fp16 else sample
# Run eval step for open-domain VQA
with torch.no_grad():
result, scores = zero_shot_step(task, generator, models, sample)
print(f"Q{idx + 1}: {question}")
print(f"A{idx + 1}: {result[0]['answer']}")
print()
- ofa_tiny, ofa_medium, ofa_base, ofa_large, ofa_huge 5개의 모델 실험
- 모델의 크기가 커질수록 정확한 답을 하며 주관적인 질문도 그럴듯하게 잘 답변하는 것을 확인할 수 있음
- 에니메이션 사진, 합성 사진 등 out-of-domain input에 대해서도 잘 작동함
- 정성적인 결과는 demo.py 파일 참고