martintmv commited on
Commit
47dbacc
1 Parent(s): efcf7ce

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +55 -3
  2. config.json +248 -0
  3. preprocessor_config.json +28 -0
README.md CHANGED
@@ -1,3 +1,55 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+
5
+ # InsectSAM: Insect Segmentation and Monitoring
6
+
7
+ <p align="left">
8
+ <a href="" rel="noopener">
9
+ <img width=200px height=200px src="https://i.imgur.com/hjWgAN9.png alt="Project logo"></a>
10
+ </p>
11
+
12
+ ## Overview
13
+
14
+ InsectSAM is an advanced machine learning model tailored for the https://diopsis.eu camera systems and https://www.arise-biodiversity.nl/, dedicated to Insect Biodiversity Detection and Monitoring in the Netherlands. Built on Meta AI's `segment-anything` model, InsectSAM is fine-tuned to be accurate at segmenting insects from complex backgrounds, enhancing the accuracy and efficiency of biodiversity monitoring efforts.
15
+
16
+ ## Purpose
17
+
18
+ This model has been meticulously trained to identify and segment insects against a variety of backgrounds that might otherwise confuse traditional algorithms. It is specifically designed to adapt to future changes in background environments, ensuring its long-term utility in the DIOPSIS / ARISE project.
19
+
20
+ ## Model Architecture
21
+
22
+ InsectSAM utilizes the advanced capabilities of the `segment-anything` architecture, enhanced by our custom training on an insect-centric dataset. The model is further refined by integrating with GroundingDINO, improving its ability to distinguish fine details and subtle variations in insect appearances.
23
+
24
+ ## Quick Start
25
+
26
+ ### Prerequisites
27
+
28
+ - Python
29
+ - Hugging Face Transformers
30
+ - PyTorch
31
+
32
+ ### Usage
33
+
34
+ #### Install
35
+ ``` bash
36
+ !pip install --upgrade -q git+https://github.com/huggingface/transformers
37
+ !pip install torch
38
+ ```
39
+ #### Load model directly via HF Transformers 🤗
40
+ ``` bash
41
+ from transformers import AutoProcessor, AutoModelForMaskGeneration
42
+
43
+ processor = AutoProcessor.from_pretrained("martintmv/InsectSAM")
44
+ model = AutoModelForMaskGeneration.from_pretrained("martintmv/InsectSAM")
45
+ ```
46
+
47
+ ### Notebooks
48
+
49
+ Three Jupyter notebooks are provided to demonstrate the model's capabilities and its integration with GroundingDINO:
50
+
51
+ - **InsectSAM.ipynb**: Covers the training process, from data preparation to model evaluation.
52
+ - **InsectSAM_GroundingDINO.ipynb**: Demonstrates how InsectSAM is combined with GroundingDINO for enhanced segmentation performance.
53
+ - **Run_InsectSAM_Inference_Transformers.ipynb**: Run InsectSAM using Transformers.
54
+
55
+ Check out the notebooks on RB-IBDM's GitHub page - https://github.com/martintmv-git/RB-IBDM/tree/main/InsectSAM
config.json ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_commit_hash": null,
3
+ "architectures": [
4
+ "SamModel"
5
+ ],
6
+ "initializer_range": 0.02,
7
+ "mask_decoder_config": {
8
+ "_name_or_path": "",
9
+ "add_cross_attention": false,
10
+ "architectures": null,
11
+ "attention_downsample_rate": 2,
12
+ "bad_words_ids": null,
13
+ "begin_suppress_tokens": null,
14
+ "bos_token_id": null,
15
+ "chunk_size_feed_forward": 0,
16
+ "cross_attention_hidden_size": null,
17
+ "decoder_start_token_id": null,
18
+ "diversity_penalty": 0.0,
19
+ "do_sample": false,
20
+ "early_stopping": false,
21
+ "encoder_no_repeat_ngram_size": 0,
22
+ "eos_token_id": null,
23
+ "exponential_decay_length_penalty": null,
24
+ "finetuning_task": null,
25
+ "forced_bos_token_id": null,
26
+ "forced_eos_token_id": null,
27
+ "hidden_act": "relu",
28
+ "hidden_size": 256,
29
+ "id2label": {
30
+ "0": "LABEL_0",
31
+ "1": "LABEL_1"
32
+ },
33
+ "iou_head_depth": 3,
34
+ "iou_head_hidden_dim": 256,
35
+ "is_decoder": false,
36
+ "is_encoder_decoder": false,
37
+ "label2id": {
38
+ "LABEL_0": 0,
39
+ "LABEL_1": 1
40
+ },
41
+ "layer_norm_eps": 1e-06,
42
+ "length_penalty": 1.0,
43
+ "max_length": 20,
44
+ "min_length": 0,
45
+ "mlp_dim": 2048,
46
+ "model_type": "",
47
+ "no_repeat_ngram_size": 0,
48
+ "num_attention_heads": 8,
49
+ "num_beam_groups": 1,
50
+ "num_beams": 1,
51
+ "num_hidden_layers": 2,
52
+ "num_multimask_outputs": 3,
53
+ "num_return_sequences": 1,
54
+ "output_attentions": false,
55
+ "output_hidden_states": false,
56
+ "output_scores": false,
57
+ "pad_token_id": null,
58
+ "prefix": null,
59
+ "problem_type": null,
60
+ "pruned_heads": {},
61
+ "remove_invalid_values": false,
62
+ "repetition_penalty": 1.0,
63
+ "return_dict": true,
64
+ "return_dict_in_generate": false,
65
+ "sep_token_id": null,
66
+ "suppress_tokens": null,
67
+ "task_specific_params": null,
68
+ "temperature": 1.0,
69
+ "tf_legacy_loss": false,
70
+ "tie_encoder_decoder": false,
71
+ "tie_word_embeddings": true,
72
+ "tokenizer_class": null,
73
+ "top_k": 50,
74
+ "top_p": 1.0,
75
+ "torch_dtype": null,
76
+ "torchscript": false,
77
+ "transformers_version": "4.29.0.dev0",
78
+ "typical_p": 1.0,
79
+ "use_bfloat16": false
80
+ },
81
+ "model_type": "sam",
82
+ "prompt_encoder_config": {
83
+ "_name_or_path": "",
84
+ "add_cross_attention": false,
85
+ "architectures": null,
86
+ "bad_words_ids": null,
87
+ "begin_suppress_tokens": null,
88
+ "bos_token_id": null,
89
+ "chunk_size_feed_forward": 0,
90
+ "cross_attention_hidden_size": null,
91
+ "decoder_start_token_id": null,
92
+ "diversity_penalty": 0.0,
93
+ "do_sample": false,
94
+ "early_stopping": false,
95
+ "encoder_no_repeat_ngram_size": 0,
96
+ "eos_token_id": null,
97
+ "exponential_decay_length_penalty": null,
98
+ "finetuning_task": null,
99
+ "forced_bos_token_id": null,
100
+ "forced_eos_token_id": null,
101
+ "hidden_act": "gelu",
102
+ "hidden_size": 256,
103
+ "id2label": {
104
+ "0": "LABEL_0",
105
+ "1": "LABEL_1"
106
+ },
107
+ "image_embedding_size": 64,
108
+ "image_size": 1024,
109
+ "is_decoder": false,
110
+ "is_encoder_decoder": false,
111
+ "label2id": {
112
+ "LABEL_0": 0,
113
+ "LABEL_1": 1
114
+ },
115
+ "layer_norm_eps": 1e-06,
116
+ "length_penalty": 1.0,
117
+ "mask_input_channels": 16,
118
+ "max_length": 20,
119
+ "min_length": 0,
120
+ "model_type": "",
121
+ "no_repeat_ngram_size": 0,
122
+ "num_beam_groups": 1,
123
+ "num_beams": 1,
124
+ "num_point_embeddings": 4,
125
+ "num_return_sequences": 1,
126
+ "output_attentions": false,
127
+ "output_hidden_states": false,
128
+ "output_scores": false,
129
+ "pad_token_id": null,
130
+ "patch_size": 16,
131
+ "prefix": null,
132
+ "problem_type": null,
133
+ "pruned_heads": {},
134
+ "remove_invalid_values": false,
135
+ "repetition_penalty": 1.0,
136
+ "return_dict": true,
137
+ "return_dict_in_generate": false,
138
+ "sep_token_id": null,
139
+ "suppress_tokens": null,
140
+ "task_specific_params": null,
141
+ "temperature": 1.0,
142
+ "tf_legacy_loss": false,
143
+ "tie_encoder_decoder": false,
144
+ "tie_word_embeddings": true,
145
+ "tokenizer_class": null,
146
+ "top_k": 50,
147
+ "top_p": 1.0,
148
+ "torch_dtype": null,
149
+ "torchscript": false,
150
+ "transformers_version": "4.29.0.dev0",
151
+ "typical_p": 1.0,
152
+ "use_bfloat16": false
153
+ },
154
+ "torch_dtype": "float32",
155
+ "transformers_version": null,
156
+ "vision_config": {
157
+ "_name_or_path": "",
158
+ "add_cross_attention": false,
159
+ "architectures": null,
160
+ "attention_dropout": 0.0,
161
+ "bad_words_ids": null,
162
+ "begin_suppress_tokens": null,
163
+ "bos_token_id": null,
164
+ "chunk_size_feed_forward": 0,
165
+ "cross_attention_hidden_size": null,
166
+ "decoder_start_token_id": null,
167
+ "diversity_penalty": 0.0,
168
+ "do_sample": false,
169
+ "dropout": 0.0,
170
+ "early_stopping": false,
171
+ "encoder_no_repeat_ngram_size": 0,
172
+ "eos_token_id": null,
173
+ "exponential_decay_length_penalty": null,
174
+ "finetuning_task": null,
175
+ "forced_bos_token_id": null,
176
+ "forced_eos_token_id": null,
177
+ "global_attn_indexes": [
178
+ 2,
179
+ 5,
180
+ 8,
181
+ 11
182
+ ],
183
+ "hidden_act": "gelu",
184
+ "hidden_size": 768,
185
+ "id2label": {
186
+ "0": "LABEL_0",
187
+ "1": "LABEL_1"
188
+ },
189
+ "image_size": 1024,
190
+ "initializer_factor": 1.0,
191
+ "initializer_range": 1e-10,
192
+ "intermediate_size": 6144,
193
+ "is_decoder": false,
194
+ "is_encoder_decoder": false,
195
+ "label2id": {
196
+ "LABEL_0": 0,
197
+ "LABEL_1": 1
198
+ },
199
+ "layer_norm_eps": 1e-06,
200
+ "length_penalty": 1.0,
201
+ "max_length": 20,
202
+ "min_length": 0,
203
+ "mlp_dim": 3072,
204
+ "mlp_ratio": 4.0,
205
+ "model_type": "",
206
+ "no_repeat_ngram_size": 0,
207
+ "num_attention_heads": 12,
208
+ "num_beam_groups": 1,
209
+ "num_beams": 1,
210
+ "num_channels": 3,
211
+ "num_hidden_layers": 12,
212
+ "num_pos_feats": 128,
213
+ "num_return_sequences": 1,
214
+ "output_attentions": false,
215
+ "output_channels": 256,
216
+ "output_hidden_states": false,
217
+ "output_scores": false,
218
+ "pad_token_id": null,
219
+ "patch_size": 16,
220
+ "prefix": null,
221
+ "problem_type": null,
222
+ "projection_dim": 512,
223
+ "pruned_heads": {},
224
+ "qkv_bias": true,
225
+ "remove_invalid_values": false,
226
+ "repetition_penalty": 1.0,
227
+ "return_dict": true,
228
+ "return_dict_in_generate": false,
229
+ "sep_token_id": null,
230
+ "suppress_tokens": null,
231
+ "task_specific_params": null,
232
+ "temperature": 1.0,
233
+ "tf_legacy_loss": false,
234
+ "tie_encoder_decoder": false,
235
+ "tie_word_embeddings": true,
236
+ "tokenizer_class": null,
237
+ "top_k": 50,
238
+ "top_p": 1.0,
239
+ "torch_dtype": null,
240
+ "torchscript": false,
241
+ "transformers_version": "4.29.0.dev0",
242
+ "typical_p": 1.0,
243
+ "use_abs_pos": true,
244
+ "use_bfloat16": false,
245
+ "use_rel_pos": true,
246
+ "window_size": 14
247
+ }
248
+ }
preprocessor_config.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_convert_rgb": true,
3
+ "do_normalize": true,
4
+ "do_pad": true,
5
+ "do_rescale": true,
6
+ "do_resize": true,
7
+ "image_mean": [
8
+ 0.485,
9
+ 0.456,
10
+ 0.406
11
+ ],
12
+ "image_processor_type": "SamImageProcessor",
13
+ "image_std": [
14
+ 0.229,
15
+ 0.224,
16
+ 0.225
17
+ ],
18
+ "pad_size": {
19
+ "height": 1024,
20
+ "width": 1024
21
+ },
22
+ "processor_class": "SamProcessor",
23
+ "resample": 2,
24
+ "rescale_factor": 0.00392156862745098,
25
+ "size": {
26
+ "longest_edge": 1024
27
+ }
28
+ }