ragavsachdeva commited on
Commit
d9a550a
·
verified ·
1 Parent(s): 6f06913

Upload model

Browse files
Files changed (5) hide show
  1. README.md +199 -0
  2. config.json +491 -0
  3. configuration_magiv2.py +19 -0
  4. model.safetensors +3 -0
  5. modelling_magiv2.py +58 -0
README.md ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ tags: []
4
+ ---
5
+
6
+ # Model Card for Model ID
7
+
8
+ <!-- Provide a quick summary of what the model is/does. -->
9
+
10
+
11
+
12
+ ## Model Details
13
+
14
+ ### Model Description
15
+
16
+ <!-- Provide a longer summary of what this model is. -->
17
+
18
+ This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
+
20
+ - **Developed by:** [More Information Needed]
21
+ - **Funded by [optional]:** [More Information Needed]
22
+ - **Shared by [optional]:** [More Information Needed]
23
+ - **Model type:** [More Information Needed]
24
+ - **Language(s) (NLP):** [More Information Needed]
25
+ - **License:** [More Information Needed]
26
+ - **Finetuned from model [optional]:** [More Information Needed]
27
+
28
+ ### Model Sources [optional]
29
+
30
+ <!-- Provide the basic links for the model. -->
31
+
32
+ - **Repository:** [More Information Needed]
33
+ - **Paper [optional]:** [More Information Needed]
34
+ - **Demo [optional]:** [More Information Needed]
35
+
36
+ ## Uses
37
+
38
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
+
40
+ ### Direct Use
41
+
42
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
+
44
+ [More Information Needed]
45
+
46
+ ### Downstream Use [optional]
47
+
48
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
+
50
+ [More Information Needed]
51
+
52
+ ### Out-of-Scope Use
53
+
54
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
+
56
+ [More Information Needed]
57
+
58
+ ## Bias, Risks, and Limitations
59
+
60
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
+
62
+ [More Information Needed]
63
+
64
+ ### Recommendations
65
+
66
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
+
68
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
+
70
+ ## How to Get Started with the Model
71
+
72
+ Use the code below to get started with the model.
73
+
74
+ [More Information Needed]
75
+
76
+ ## Training Details
77
+
78
+ ### Training Data
79
+
80
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
+
82
+ [More Information Needed]
83
+
84
+ ### Training Procedure
85
+
86
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
+
88
+ #### Preprocessing [optional]
89
+
90
+ [More Information Needed]
91
+
92
+
93
+ #### Training Hyperparameters
94
+
95
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
+
97
+ #### Speeds, Sizes, Times [optional]
98
+
99
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
+
101
+ [More Information Needed]
102
+
103
+ ## Evaluation
104
+
105
+ <!-- This section describes the evaluation protocols and provides the results. -->
106
+
107
+ ### Testing Data, Factors & Metrics
108
+
109
+ #### Testing Data
110
+
111
+ <!-- This should link to a Dataset Card if possible. -->
112
+
113
+ [More Information Needed]
114
+
115
+ #### Factors
116
+
117
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
+
119
+ [More Information Needed]
120
+
121
+ #### Metrics
122
+
123
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
+
125
+ [More Information Needed]
126
+
127
+ ### Results
128
+
129
+ [More Information Needed]
130
+
131
+ #### Summary
132
+
133
+
134
+
135
+ ## Model Examination [optional]
136
+
137
+ <!-- Relevant interpretability work for the model goes here -->
138
+
139
+ [More Information Needed]
140
+
141
+ ## Environmental Impact
142
+
143
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
+
145
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
+
147
+ - **Hardware Type:** [More Information Needed]
148
+ - **Hours used:** [More Information Needed]
149
+ - **Cloud Provider:** [More Information Needed]
150
+ - **Compute Region:** [More Information Needed]
151
+ - **Carbon Emitted:** [More Information Needed]
152
+
153
+ ## Technical Specifications [optional]
154
+
155
+ ### Model Architecture and Objective
156
+
157
+ [More Information Needed]
158
+
159
+ ### Compute Infrastructure
160
+
161
+ [More Information Needed]
162
+
163
+ #### Hardware
164
+
165
+ [More Information Needed]
166
+
167
+ #### Software
168
+
169
+ [More Information Needed]
170
+
171
+ ## Citation [optional]
172
+
173
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
+
175
+ **BibTeX:**
176
+
177
+ [More Information Needed]
178
+
179
+ **APA:**
180
+
181
+ [More Information Needed]
182
+
183
+ ## Glossary [optional]
184
+
185
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
+
187
+ [More Information Needed]
188
+
189
+ ## More Information [optional]
190
+
191
+ [More Information Needed]
192
+
193
+ ## Model Card Authors [optional]
194
+
195
+ [More Information Needed]
196
+
197
+ ## Model Card Contact
198
+
199
+ [More Information Needed]
config.json ADDED
@@ -0,0 +1,491 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "ragavsachdeva/magiv2",
3
+ "architectures": [
4
+ "Magiv2Model"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_magiv2.Magiv2Config",
8
+ "AutoModel": "modelling_magiv2.Magiv2Model"
9
+ },
10
+ "crop_embedding_image_preprocessing_config": {
11
+ "_processor_class": null,
12
+ "do_normalize": true,
13
+ "do_rescale": true,
14
+ "do_resize": true,
15
+ "image_mean": [
16
+ 0.485,
17
+ 0.456,
18
+ 0.406
19
+ ],
20
+ "image_processor_type": "ViTImageProcessor",
21
+ "image_std": [
22
+ 0.229,
23
+ 0.224,
24
+ 0.225
25
+ ],
26
+ "resample": 2,
27
+ "rescale_factor": 0.00392156862745098,
28
+ "size": {
29
+ "height": 224,
30
+ "width": 224
31
+ }
32
+ },
33
+ "crop_embedding_model_config": {
34
+ "_attn_implementation_autoset": true,
35
+ "_name_or_path": "facebook/vit-mae-base",
36
+ "add_cross_attention": false,
37
+ "architectures": [
38
+ "ViTMAEForPreTraining"
39
+ ],
40
+ "attention_probs_dropout_prob": 0.0,
41
+ "bad_words_ids": null,
42
+ "begin_suppress_tokens": null,
43
+ "bos_token_id": null,
44
+ "chunk_size_feed_forward": 0,
45
+ "cross_attention_hidden_size": null,
46
+ "decoder_hidden_size": 512,
47
+ "decoder_intermediate_size": 2048,
48
+ "decoder_num_attention_heads": 16,
49
+ "decoder_num_hidden_layers": 8,
50
+ "decoder_start_token_id": null,
51
+ "diversity_penalty": 0.0,
52
+ "do_sample": false,
53
+ "early_stopping": false,
54
+ "encoder_no_repeat_ngram_size": 0,
55
+ "eos_token_id": null,
56
+ "exponential_decay_length_penalty": null,
57
+ "finetuning_task": null,
58
+ "forced_bos_token_id": null,
59
+ "forced_eos_token_id": null,
60
+ "hidden_act": "gelu",
61
+ "hidden_dropout_prob": 0.0,
62
+ "hidden_size": 768,
63
+ "id2label": {
64
+ "0": "LABEL_0",
65
+ "1": "LABEL_1"
66
+ },
67
+ "image_size": 224,
68
+ "initializer_range": 0.02,
69
+ "intermediate_size": 3072,
70
+ "is_decoder": false,
71
+ "is_encoder_decoder": false,
72
+ "label2id": {
73
+ "LABEL_0": 0,
74
+ "LABEL_1": 1
75
+ },
76
+ "layer_norm_eps": 1e-12,
77
+ "length_penalty": 1.0,
78
+ "mask_ratio": 0.75,
79
+ "max_length": 20,
80
+ "min_length": 0,
81
+ "model_type": "",
82
+ "no_repeat_ngram_size": 0,
83
+ "norm_pix_loss": false,
84
+ "num_attention_heads": 12,
85
+ "num_beam_groups": 1,
86
+ "num_beams": 1,
87
+ "num_channels": 3,
88
+ "num_hidden_layers": 12,
89
+ "num_return_sequences": 1,
90
+ "output_attentions": false,
91
+ "output_hidden_states": false,
92
+ "output_scores": false,
93
+ "pad_token_id": null,
94
+ "patch_size": 16,
95
+ "prefix": null,
96
+ "problem_type": null,
97
+ "pruned_heads": {},
98
+ "qkv_bias": true,
99
+ "remove_invalid_values": false,
100
+ "repetition_penalty": 1.0,
101
+ "return_dict": true,
102
+ "return_dict_in_generate": false,
103
+ "sep_token_id": null,
104
+ "suppress_tokens": null,
105
+ "task_specific_params": null,
106
+ "temperature": 1.0,
107
+ "tf_legacy_loss": false,
108
+ "tie_encoder_decoder": false,
109
+ "tie_word_embeddings": true,
110
+ "tokenizer_class": null,
111
+ "top_k": 50,
112
+ "top_p": 1.0,
113
+ "torch_dtype": "float32",
114
+ "torchscript": false,
115
+ "typical_p": 1.0,
116
+ "use_bfloat16": false
117
+ },
118
+ "detection_image_preprocessing_config": {
119
+ "_processor_class": null,
120
+ "do_normalize": true,
121
+ "do_pad": true,
122
+ "do_rescale": true,
123
+ "do_resize": true,
124
+ "format": "coco_detection",
125
+ "image_mean": [
126
+ 0.485,
127
+ 0.456,
128
+ 0.406
129
+ ],
130
+ "image_processor_type": "ConditionalDetrImageProcessor",
131
+ "image_std": [
132
+ 0.229,
133
+ 0.224,
134
+ 0.225
135
+ ],
136
+ "resample": 2,
137
+ "rescale_factor": 0.00392156862745098,
138
+ "size": {
139
+ "longest_edge": 1333,
140
+ "shortest_edge": 800
141
+ }
142
+ },
143
+ "detection_model_config": {
144
+ "_name_or_path": "microsoft/conditional-detr-resnet-50",
145
+ "activation_dropout": 0.0,
146
+ "activation_function": "relu",
147
+ "add_cross_attention": false,
148
+ "architectures": [
149
+ "ConditionalDETRForObjectDetection"
150
+ ],
151
+ "attention_dropout": 0.0,
152
+ "auxiliary_loss": false,
153
+ "backbone": "resnet50",
154
+ "backbone_config": null,
155
+ "bad_words_ids": null,
156
+ "bbox_cost": 5,
157
+ "bbox_loss_coefficient": 5,
158
+ "begin_suppress_tokens": null,
159
+ "bos_token_id": null,
160
+ "chunk_size_feed_forward": 0,
161
+ "class_cost": 2,
162
+ "cls_loss_coefficient": 2,
163
+ "cross_attention_hidden_size": null,
164
+ "d_model": 256,
165
+ "decoder_attention_heads": 8,
166
+ "decoder_ffn_dim": 2048,
167
+ "decoder_layerdrop": 0.0,
168
+ "decoder_layers": 6,
169
+ "decoder_start_token_id": null,
170
+ "dice_loss_coefficient": 1,
171
+ "dilation": false,
172
+ "diversity_penalty": 0.0,
173
+ "do_sample": false,
174
+ "dropout": 0.1,
175
+ "early_stopping": false,
176
+ "encoder_attention_heads": 8,
177
+ "encoder_ffn_dim": 2048,
178
+ "encoder_layerdrop": 0.0,
179
+ "encoder_layers": 6,
180
+ "encoder_no_repeat_ngram_size": 0,
181
+ "eos_token_id": null,
182
+ "exponential_decay_length_penalty": null,
183
+ "finetuning_task": null,
184
+ "focal_alpha": 0.25,
185
+ "forced_bos_token_id": null,
186
+ "forced_eos_token_id": null,
187
+ "giou_cost": 2,
188
+ "giou_loss_coefficient": 2,
189
+ "id2label": {
190
+ "0": "LABEL_0",
191
+ "1": "LABEL_1",
192
+ "2": "LABEL_2",
193
+ "3": "LABEL_3"
194
+ },
195
+ "init_std": 0.02,
196
+ "init_xavier_std": 1.0,
197
+ "is_decoder": false,
198
+ "is_encoder_decoder": true,
199
+ "label2id": {
200
+ "LABEL_0": 0,
201
+ "LABEL_1": 1,
202
+ "LABEL_2": 2,
203
+ "LABEL_3": 3
204
+ },
205
+ "length_penalty": 1.0,
206
+ "mask_loss_coefficient": 1,
207
+ "max_length": 20,
208
+ "max_position_embeddings": 1024,
209
+ "min_length": 0,
210
+ "model_type": "",
211
+ "no_repeat_ngram_size": 0,
212
+ "num_beam_groups": 1,
213
+ "num_beams": 1,
214
+ "num_channels": 3,
215
+ "num_hidden_layers": 6,
216
+ "num_queries": 305,
217
+ "num_return_sequences": 1,
218
+ "output_attentions": false,
219
+ "output_hidden_states": false,
220
+ "output_scores": false,
221
+ "pad_token_id": null,
222
+ "position_embedding_type": "sine",
223
+ "prefix": null,
224
+ "problem_type": null,
225
+ "pruned_heads": {},
226
+ "remove_invalid_values": false,
227
+ "repetition_penalty": 1.0,
228
+ "return_dict": true,
229
+ "return_dict_in_generate": false,
230
+ "scale_embedding": false,
231
+ "sep_token_id": null,
232
+ "suppress_tokens": null,
233
+ "task_specific_params": null,
234
+ "temperature": 1.0,
235
+ "tf_legacy_loss": false,
236
+ "tie_encoder_decoder": false,
237
+ "tie_word_embeddings": true,
238
+ "tokenizer_class": null,
239
+ "top_k": 50,
240
+ "top_p": 1.0,
241
+ "torch_dtype": "float32",
242
+ "torchscript": false,
243
+ "typical_p": 1.0,
244
+ "use_bfloat16": false,
245
+ "use_pretrained_backbone": true,
246
+ "use_timm_backbone": true
247
+ },
248
+ "disable_crop_embeddings": false,
249
+ "disable_detections": false,
250
+ "disable_ocr": false,
251
+ "kwargs": {
252
+ "_commit_hash": null,
253
+ "_name_or_path": "ragavsachdeva/magiv2",
254
+ "architectures": [
255
+ "Magiv2Model"
256
+ ],
257
+ "auto_map": {
258
+ "AutoConfig": "configuration_magiv2.Magiv2Config",
259
+ "AutoModel": "modelling_magiv2.Magiv2Model"
260
+ },
261
+ "model_type": "magiv2",
262
+ "torch_dtype": "float32",
263
+ "transformers_version": "4.34.0.dev0"
264
+ },
265
+ "model_type": "magiv2",
266
+ "ocr_model_config": {
267
+ "_name_or_path": "microsoft/trocr-base-printed",
268
+ "add_cross_attention": false,
269
+ "architectures": [
270
+ "VisionEncoderDecoderModel"
271
+ ],
272
+ "bad_words_ids": null,
273
+ "begin_suppress_tokens": null,
274
+ "bos_token_id": null,
275
+ "chunk_size_feed_forward": 0,
276
+ "cross_attention_hidden_size": null,
277
+ "decoder": {
278
+ "_name_or_path": "",
279
+ "activation_dropout": 0.0,
280
+ "activation_function": "gelu",
281
+ "add_cross_attention": true,
282
+ "architectures": null,
283
+ "attention_dropout": 0.0,
284
+ "bad_words_ids": null,
285
+ "begin_suppress_tokens": null,
286
+ "bos_token_id": 0,
287
+ "chunk_size_feed_forward": 0,
288
+ "classifier_dropout": 0.0,
289
+ "cross_attention_hidden_size": 768,
290
+ "d_model": 1024,
291
+ "decoder_attention_heads": 16,
292
+ "decoder_ffn_dim": 4096,
293
+ "decoder_layerdrop": 0.0,
294
+ "decoder_layers": 12,
295
+ "decoder_start_token_id": 2,
296
+ "diversity_penalty": 0.0,
297
+ "do_sample": false,
298
+ "dropout": 0.1,
299
+ "early_stopping": false,
300
+ "encoder_no_repeat_ngram_size": 0,
301
+ "eos_token_id": 2,
302
+ "exponential_decay_length_penalty": null,
303
+ "finetuning_task": null,
304
+ "forced_bos_token_id": null,
305
+ "forced_eos_token_id": null,
306
+ "id2label": {
307
+ "0": "LABEL_0",
308
+ "1": "LABEL_1"
309
+ },
310
+ "init_std": 0.02,
311
+ "is_decoder": true,
312
+ "is_encoder_decoder": false,
313
+ "label2id": {
314
+ "LABEL_0": 0,
315
+ "LABEL_1": 1
316
+ },
317
+ "layernorm_embedding": true,
318
+ "length_penalty": 1.0,
319
+ "max_length": 20,
320
+ "max_position_embeddings": 512,
321
+ "min_length": 0,
322
+ "model_type": "trocr",
323
+ "no_repeat_ngram_size": 0,
324
+ "num_beam_groups": 1,
325
+ "num_beams": 1,
326
+ "num_return_sequences": 1,
327
+ "output_attentions": false,
328
+ "output_hidden_states": false,
329
+ "output_scores": false,
330
+ "pad_token_id": 1,
331
+ "prefix": null,
332
+ "problem_type": null,
333
+ "pruned_heads": {},
334
+ "remove_invalid_values": false,
335
+ "repetition_penalty": 1.0,
336
+ "return_dict": true,
337
+ "return_dict_in_generate": false,
338
+ "scale_embedding": false,
339
+ "sep_token_id": null,
340
+ "suppress_tokens": null,
341
+ "task_specific_params": null,
342
+ "temperature": 1.0,
343
+ "tf_legacy_loss": false,
344
+ "tie_encoder_decoder": false,
345
+ "tie_word_embeddings": true,
346
+ "tokenizer_class": null,
347
+ "top_k": 50,
348
+ "top_p": 1.0,
349
+ "torch_dtype": null,
350
+ "torchscript": false,
351
+ "typical_p": 1.0,
352
+ "use_bfloat16": false,
353
+ "use_cache": false,
354
+ "use_learned_position_embeddings": true,
355
+ "vocab_size": 50265
356
+ },
357
+ "decoder_start_token_id": null,
358
+ "diversity_penalty": 0.0,
359
+ "do_sample": false,
360
+ "early_stopping": false,
361
+ "encoder": {
362
+ "_name_or_path": "",
363
+ "add_cross_attention": false,
364
+ "architectures": null,
365
+ "attention_probs_dropout_prob": 0.0,
366
+ "bad_words_ids": null,
367
+ "begin_suppress_tokens": null,
368
+ "bos_token_id": null,
369
+ "chunk_size_feed_forward": 0,
370
+ "cross_attention_hidden_size": null,
371
+ "decoder_start_token_id": null,
372
+ "diversity_penalty": 0.0,
373
+ "do_sample": false,
374
+ "early_stopping": false,
375
+ "encoder_no_repeat_ngram_size": 0,
376
+ "encoder_stride": 16,
377
+ "eos_token_id": null,
378
+ "exponential_decay_length_penalty": null,
379
+ "finetuning_task": null,
380
+ "forced_bos_token_id": null,
381
+ "forced_eos_token_id": null,
382
+ "hidden_act": "gelu",
383
+ "hidden_dropout_prob": 0.0,
384
+ "hidden_size": 768,
385
+ "id2label": {
386
+ "0": "LABEL_0",
387
+ "1": "LABEL_1"
388
+ },
389
+ "image_size": 384,
390
+ "initializer_range": 0.02,
391
+ "intermediate_size": 3072,
392
+ "is_decoder": false,
393
+ "is_encoder_decoder": false,
394
+ "label2id": {
395
+ "LABEL_0": 0,
396
+ "LABEL_1": 1
397
+ },
398
+ "layer_norm_eps": 1e-12,
399
+ "length_penalty": 1.0,
400
+ "max_length": 20,
401
+ "min_length": 0,
402
+ "model_type": "vit",
403
+ "no_repeat_ngram_size": 0,
404
+ "num_attention_heads": 12,
405
+ "num_beam_groups": 1,
406
+ "num_beams": 1,
407
+ "num_channels": 3,
408
+ "num_hidden_layers": 12,
409
+ "num_return_sequences": 1,
410
+ "output_attentions": false,
411
+ "output_hidden_states": false,
412
+ "output_scores": false,
413
+ "pad_token_id": null,
414
+ "patch_size": 16,
415
+ "prefix": null,
416
+ "problem_type": null,
417
+ "pruned_heads": {},
418
+ "qkv_bias": false,
419
+ "remove_invalid_values": false,
420
+ "repetition_penalty": 1.0,
421
+ "return_dict": true,
422
+ "return_dict_in_generate": false,
423
+ "sep_token_id": null,
424
+ "suppress_tokens": null,
425
+ "task_specific_params": null,
426
+ "temperature": 1.0,
427
+ "tf_legacy_loss": false,
428
+ "tie_encoder_decoder": false,
429
+ "tie_word_embeddings": true,
430
+ "tokenizer_class": null,
431
+ "top_k": 50,
432
+ "top_p": 1.0,
433
+ "torch_dtype": null,
434
+ "torchscript": false,
435
+ "typical_p": 1.0,
436
+ "use_bfloat16": false
437
+ },
438
+ "encoder_no_repeat_ngram_size": 0,
439
+ "eos_token_id": null,
440
+ "exponential_decay_length_penalty": null,
441
+ "finetuning_task": null,
442
+ "forced_bos_token_id": null,
443
+ "forced_eos_token_id": null,
444
+ "id2label": {
445
+ "0": "LABEL_0",
446
+ "1": "LABEL_1"
447
+ },
448
+ "is_decoder": false,
449
+ "is_encoder_decoder": true,
450
+ "label2id": {
451
+ "LABEL_0": 0,
452
+ "LABEL_1": 1
453
+ },
454
+ "length_penalty": 1.0,
455
+ "max_length": 20,
456
+ "min_length": 0,
457
+ "model_type": "vision-encoder-decoder",
458
+ "no_repeat_ngram_size": 0,
459
+ "num_beam_groups": 1,
460
+ "num_beams": 1,
461
+ "num_return_sequences": 1,
462
+ "output_attentions": false,
463
+ "output_hidden_states": false,
464
+ "output_scores": false,
465
+ "pad_token_id": null,
466
+ "prefix": null,
467
+ "problem_type": null,
468
+ "pruned_heads": {},
469
+ "remove_invalid_values": false,
470
+ "repetition_penalty": 1.0,
471
+ "return_dict": true,
472
+ "return_dict_in_generate": false,
473
+ "sep_token_id": null,
474
+ "suppress_tokens": null,
475
+ "task_specific_params": null,
476
+ "temperature": 1.0,
477
+ "tf_legacy_loss": false,
478
+ "tie_encoder_decoder": false,
479
+ "tie_word_embeddings": false,
480
+ "tokenizer_class": null,
481
+ "top_k": 50,
482
+ "top_p": 1.0,
483
+ "torch_dtype": "float32",
484
+ "torchscript": false,
485
+ "typical_p": 1.0,
486
+ "use_bfloat16": false
487
+ },
488
+ "ocr_pretrained_processor_path": "microsoft/trocr-base-printed",
489
+ "torch_dtype": "float32",
490
+ "transformers_version": "4.47.1"
491
+ }
configuration_magiv2.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig, VisionEncoderDecoderConfig
2
+ from typing import List
3
+
4
+
5
+ class Magiv2Config(PretrainedConfig):
6
+ model_type = "magiv2"
7
+
8
+ def __init__(
9
+ self,
10
+ crop_embedding_model_config: dict = None,
11
+ crop_embedding_image_preprocessing_config: dict = None,
12
+ **kwargs,
13
+ ):
14
+ self.kwargs = kwargs
15
+ self.crop_embedding_model_config = None
16
+ if crop_embedding_model_config is not None:
17
+ self.crop_embedding_model_config = PretrainedConfig.from_dict(crop_embedding_model_config)
18
+ self.crop_embedding_image_preprocessing_config = crop_embedding_image_preprocessing_config
19
+ super().__init__(**kwargs)
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3d6bd5ae35f4bfe26cb4b66b6ae7f23edf56e2d249c10d1d38ff4a97c1a71645
3
+ size 343221032
modelling_magiv2.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PreTrainedModel, ViTMAEModel
2
+ from .configuration_magiv2 import Magiv2Config
3
+ import torch
4
+ import numpy as np
5
+ from transformers import ViTImageProcessor
6
+ import PIL
7
+
8
+ def move_to_device(inputs, device):
9
+ if hasattr(inputs, "keys"):
10
+ return {k: move_to_device(v, device) for k, v in inputs.items()}
11
+ elif isinstance(inputs, list):
12
+ return [move_to_device(v, device) for v in inputs]
13
+ elif isinstance(inputs, tuple):
14
+ return tuple([move_to_device(v, device) for v in inputs])
15
+ elif isinstance(inputs, np.ndarray):
16
+ return torch.from_numpy(inputs).to(device)
17
+ else:
18
+ return inputs.to(device)
19
+
20
+ class Magiv2Model(PreTrainedModel):
21
+ config_class = Magiv2Config
22
+
23
+ def __init__(self, config):
24
+ super().__init__(config)
25
+ self.config = config
26
+ self.processor = ViTImageProcessor.from_dict(config.crop_embedding_image_preprocessing_config)
27
+ self.crop_embedding_model = ViTMAEModel(config.crop_embedding_model_config)
28
+
29
+ def move_to_device(self, input):
30
+ return move_to_device(input, self.device)
31
+
32
+ def forward(self, images, move_to_device_fn=None, mask_ratio=0.0, batch_size=256):
33
+ if len(images) == 0:
34
+ return move_to_device_fn(torch.zeros(len(images), self.config.crop_embedding_model_config.hidden_size))
35
+
36
+ assert all(isinstance(image, PIL.Image.Image) for image in images), "please provide a list of PIL images"
37
+
38
+ move_to_device_fn = self.move_to_device if move_to_device_fn is None else move_to_device_fn
39
+ images = [np.array(image.convert("L").convert("RGB")) for image in images]
40
+ images = self.processor(images, return_tensors="pt").pixel_values
41
+ images = move_to_device_fn(images)
42
+
43
+ # temporarily change the mask ratio from default to the one specified
44
+ old_mask_ratio = self.crop_embedding_model.embeddings.config.mask_ratio
45
+ self.crop_embedding_model.embeddings.config.mask_ratio = mask_ratio
46
+
47
+ # process the crops in batches to avoid OOM
48
+ embeddings = []
49
+ for i in range(0, len(images), batch_size):
50
+ crops = images[i:i+batch_size]
51
+ embeddings_per_batch = self.crop_embedding_model(crops).last_hidden_state[:, 0]
52
+ embeddings.append(embeddings_per_batch)
53
+ embeddings = torch.cat(embeddings, dim=0)
54
+
55
+ # restore the mask ratio to the default
56
+ self.crop_embedding_model.embeddings.config.mask_ratio = old_mask_ratio
57
+
58
+ return embeddings