hkondle commited on
Commit
33c52be
·
verified ·
1 Parent(s): 864bd32

Add BLIP diagram captioner trained on AI2D part-to-whole data

Browse files
README.md CHANGED
@@ -1,3 +1,30 @@
1
  ---
2
  license: mit
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
+ library_name: transformers
4
+ pipeline_tag: image-to-text
5
+ base_model: Salesforce/blip-image-captioning-base
6
+ tags:
7
+ - blip
8
+ - accessibility
9
+ - diagram-captioning
10
  ---
11
+
12
+ # VisAble diagram captioner
13
+
14
+ BLIP fine-tuned on AI2D-Caption diagrams to produce part-to-whole descriptions for blind and
15
+ low-vision students. The vision encoder was frozen and only the text decoder was trained, using a
16
+ cross entropy loss that up-weights AI2D entity labels by 5.0x.
17
+
18
+ Trained for 10 epochs, batch size 8, learning rate 5e-05.
19
+
20
+ ```python
21
+ from transformers import BlipForConditionalGeneration, BlipProcessor
22
+ from PIL import Image
23
+
24
+ processor = BlipProcessor.from_pretrained("hkondle/CapstoneMainModel-10ep")
25
+ model = BlipForConditionalGeneration.from_pretrained("hkondle/CapstoneMainModel-10ep")
26
+
27
+ image = Image.open("diagram.png").convert("RGB")
28
+ inputs = processor(images=image, return_tensors="pt")
29
+ print(processor.decode(model.generate(**inputs, max_length=256, num_beams=4)[0], skip_special_tokens=True))
30
+ ```
config.json ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BlipForConditionalGeneration"
4
+ ],
5
+ "dtype": "float32",
6
+ "image_text_hidden_size": 256,
7
+ "initializer_factor": 1.0,
8
+ "initializer_range": 0.02,
9
+ "label_smoothing": 0.0,
10
+ "logit_scale_init_value": 2.6592,
11
+ "model_type": "blip",
12
+ "projection_dim": 512,
13
+ "text_config": {
14
+ "add_cross_attention": false,
15
+ "attention_probs_dropout_prob": 0.0,
16
+ "bos_token_id": 30522,
17
+ "cross_attention_hidden_size": null,
18
+ "decoder_start_token_id": null,
19
+ "dtype": "float32",
20
+ "encoder_hidden_size": 768,
21
+ "eos_token_id": 2,
22
+ "finetuning_task": null,
23
+ "hidden_act": "gelu",
24
+ "hidden_dropout_prob": 0.0,
25
+ "hidden_size": 768,
26
+ "initializer_factor": 1.0,
27
+ "initializer_range": 0.02,
28
+ "intermediate_size": 3072,
29
+ "is_decoder": true,
30
+ "label_smoothing": 0.0,
31
+ "layer_norm_eps": 1e-12,
32
+ "max_position_embeddings": 512,
33
+ "model_type": "blip_text_model",
34
+ "num_attention_heads": 12,
35
+ "num_hidden_layers": 12,
36
+ "pad_token_id": 0,
37
+ "prefix": null,
38
+ "projection_dim": 768,
39
+ "pruned_heads": {},
40
+ "sep_token_id": 102,
41
+ "task_specific_params": null,
42
+ "tf_legacy_loss": false,
43
+ "tie_encoder_decoder": false,
44
+ "tie_word_embeddings": true,
45
+ "tokenizer_class": null,
46
+ "torchscript": false,
47
+ "use_bfloat16": false,
48
+ "use_cache": true,
49
+ "vocab_size": 30524
50
+ },
51
+ "tie_word_embeddings": true,
52
+ "transformers_version": "5.0.0",
53
+ "vision_config": {
54
+ "add_cross_attention": false,
55
+ "attention_dropout": 0.0,
56
+ "bos_token_id": null,
57
+ "cross_attention_hidden_size": null,
58
+ "decoder_start_token_id": null,
59
+ "dropout": 0.0,
60
+ "dtype": "float32",
61
+ "eos_token_id": null,
62
+ "finetuning_task": null,
63
+ "hidden_act": "gelu",
64
+ "hidden_size": 768,
65
+ "image_size": 384,
66
+ "initializer_factor": 1.0,
67
+ "initializer_range": 0.02,
68
+ "intermediate_size": 3072,
69
+ "is_decoder": false,
70
+ "layer_norm_eps": 1e-05,
71
+ "model_type": "blip_vision_model",
72
+ "num_attention_heads": 12,
73
+ "num_channels": 3,
74
+ "num_hidden_layers": 12,
75
+ "pad_token_id": null,
76
+ "patch_size": 16,
77
+ "prefix": null,
78
+ "projection_dim": 512,
79
+ "pruned_heads": {},
80
+ "sep_token_id": null,
81
+ "task_specific_params": null,
82
+ "tf_legacy_loss": false,
83
+ "tie_encoder_decoder": false,
84
+ "tie_word_embeddings": true,
85
+ "tokenizer_class": null,
86
+ "torchscript": false,
87
+ "use_bfloat16": false
88
+ }
89
+ }
generation_config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 30522,
4
+ "diversity_penalty": 0.0,
5
+ "do_sample": false,
6
+ "early_stopping": false,
7
+ "encoder_no_repeat_ngram_size": 0,
8
+ "eos_token_id": 2,
9
+ "length_penalty": 1.0,
10
+ "max_length": 20,
11
+ "min_length": 0,
12
+ "no_repeat_ngram_size": 0,
13
+ "num_beam_groups": 1,
14
+ "num_beams": 1,
15
+ "num_return_sequences": 1,
16
+ "output_attentions": false,
17
+ "output_hidden_states": false,
18
+ "output_scores": false,
19
+ "pad_token_id": 0,
20
+ "remove_invalid_values": false,
21
+ "repetition_penalty": 1.0,
22
+ "return_dict_in_generate": false,
23
+ "temperature": 1.0,
24
+ "top_k": 50,
25
+ "top_p": 1.0,
26
+ "transformers_version": "5.0.0",
27
+ "typical_p": 1.0,
28
+ "use_cache": true
29
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2c079de1c52f8650f54c7b368e66de66bd0d1cf0bab76b0087f6c409d7aea8c0
3
+ size 989839224
processor_config.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "image_processor": {
3
+ "data_format": "channels_first",
4
+ "do_convert_rgb": true,
5
+ "do_normalize": true,
6
+ "do_rescale": true,
7
+ "do_resize": true,
8
+ "image_mean": [
9
+ 0.48145466,
10
+ 0.4578275,
11
+ 0.40821073
12
+ ],
13
+ "image_processor_type": "BlipImageProcessorFast",
14
+ "image_std": [
15
+ 0.26862954,
16
+ 0.26130258,
17
+ 0.27577711
18
+ ],
19
+ "resample": 3,
20
+ "rescale_factor": 0.00392156862745098,
21
+ "size": {
22
+ "height": 384,
23
+ "width": 384
24
+ }
25
+ },
26
+ "processor_class": "BlipProcessor"
27
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "cls_token": "[CLS]",
4
+ "do_basic_tokenize": true,
5
+ "do_lower_case": true,
6
+ "is_local": false,
7
+ "mask_token": "[MASK]",
8
+ "model_input_names": [
9
+ "input_ids",
10
+ "attention_mask"
11
+ ],
12
+ "model_max_length": 512,
13
+ "never_split": null,
14
+ "pad_token": "[PAD]",
15
+ "processor_class": "BlipProcessor",
16
+ "sep_token": "[SEP]",
17
+ "strip_accents": null,
18
+ "tokenize_chinese_chars": true,
19
+ "tokenizer_class": "BertTokenizer",
20
+ "unk_token": "[UNK]"
21
+ }