amaye15 commited on
Commit
692e598
1 Parent(s): c577abc

End of training

Browse files
Files changed (7) hide show
  1. README.md +191 -0
  2. config.json +285 -0
  3. config.toml +27 -0
  4. model.safetensors +3 -0
  5. preprocessor_config.json +37 -0
  6. train.ipynb +926 -0
  7. training_args.bin +3 -0
README.md ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: microsoft/resnet-50
4
+ tags:
5
+ - generated_from_trainer
6
+ datasets:
7
+ - stanford-dogs
8
+ metrics:
9
+ - accuracy
10
+ - f1
11
+ - precision
12
+ - recall
13
+ model-index:
14
+ - name: microsoft-resnet-50-batch32-lr0.0005-standford-dogs
15
+ results:
16
+ - task:
17
+ name: Image Classification
18
+ type: image-classification
19
+ dataset:
20
+ name: stanford-dogs
21
+ type: stanford-dogs
22
+ config: default
23
+ split: full
24
+ args: default
25
+ metrics:
26
+ - name: Accuracy
27
+ type: accuracy
28
+ value: 0.8386783284742468
29
+ - name: F1
30
+ type: f1
31
+ value: 0.8259546998355447
32
+ - name: Precision
33
+ type: precision
34
+ value: 0.8457483127517197
35
+ - name: Recall
36
+ type: recall
37
+ value: 0.8314858626273427
38
+ ---
39
+
40
+ <!-- This model card has been generated automatically according to the information the Trainer had access to. You
41
+ should probably proofread and complete it, then remove this comment. -->
42
+
43
+ # microsoft-resnet-50-batch32-lr0.0005-standford-dogs
44
+
45
+ This model is a fine-tuned version of [microsoft/resnet-50](https://huggingface.co/microsoft/resnet-50) on the stanford-dogs dataset.
46
+ It achieves the following results on the evaluation set:
47
+ - Loss: 1.1545
48
+ - Accuracy: 0.8387
49
+ - F1: 0.8260
50
+ - Precision: 0.8457
51
+ - Recall: 0.8315
52
+
53
+ ## Model description
54
+
55
+ More information needed
56
+
57
+ ## Intended uses & limitations
58
+
59
+ More information needed
60
+
61
+ ## Training and evaluation data
62
+
63
+ More information needed
64
+
65
+ ## Training procedure
66
+
67
+ ### Training hyperparameters
68
+
69
+ The following hyperparameters were used during training:
70
+ - learning_rate: 5e-05
71
+ - train_batch_size: 32
72
+ - eval_batch_size: 32
73
+ - seed: 42
74
+ - gradient_accumulation_steps: 4
75
+ - total_train_batch_size: 128
76
+ - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
77
+ - lr_scheduler_type: linear
78
+ - training_steps: 1000
79
+
80
+ ### Training results
81
+
82
+ | Training Loss | Epoch | Step | Validation Loss | Accuracy | F1 | Precision | Recall |
83
+ |:-------------:|:------:|:----:|:---------------:|:--------:|:------:|:---------:|:------:|
84
+ | 4.7829 | 0.0777 | 10 | 4.7747 | 0.2119 | 0.1874 | 0.3919 | 0.1982 |
85
+ | 4.7714 | 0.1553 | 20 | 4.7572 | 0.2038 | 0.1842 | 0.4262 | 0.1836 |
86
+ | 4.7606 | 0.2330 | 30 | 4.7367 | 0.3586 | 0.3433 | 0.6517 | 0.3307 |
87
+ | 4.747 | 0.3107 | 40 | 4.7149 | 0.4303 | 0.4272 | 0.7734 | 0.4039 |
88
+ | 4.7253 | 0.3883 | 50 | 4.6846 | 0.4361 | 0.4678 | 0.7906 | 0.4160 |
89
+ | 4.7069 | 0.4660 | 60 | 4.6534 | 0.5330 | 0.5397 | 0.8048 | 0.5093 |
90
+ | 4.6857 | 0.5437 | 70 | 4.6177 | 0.5500 | 0.5511 | 0.7998 | 0.5264 |
91
+ | 4.6569 | 0.6214 | 80 | 4.5764 | 0.5739 | 0.5800 | 0.8208 | 0.5517 |
92
+ | 4.6293 | 0.6990 | 90 | 4.5359 | 0.6142 | 0.6149 | 0.8075 | 0.5926 |
93
+ | 4.5953 | 0.7767 | 100 | 4.4828 | 0.6207 | 0.6233 | 0.8109 | 0.6000 |
94
+ | 4.5651 | 0.8544 | 110 | 4.4257 | 0.6591 | 0.6585 | 0.8148 | 0.6393 |
95
+ | 4.5296 | 0.9320 | 120 | 4.3647 | 0.7063 | 0.7012 | 0.8284 | 0.6882 |
96
+ | 4.4911 | 1.0097 | 130 | 4.2998 | 0.7089 | 0.7074 | 0.8326 | 0.6924 |
97
+ | 4.4442 | 1.0874 | 140 | 4.2288 | 0.6939 | 0.6890 | 0.8302 | 0.6759 |
98
+ | 4.3912 | 1.1650 | 150 | 4.1527 | 0.6873 | 0.6863 | 0.8262 | 0.6703 |
99
+ | 4.3393 | 1.2427 | 160 | 4.0884 | 0.7250 | 0.7127 | 0.8251 | 0.7082 |
100
+ | 4.3019 | 1.3204 | 170 | 3.9946 | 0.7262 | 0.7152 | 0.8234 | 0.7098 |
101
+ | 4.2366 | 1.3981 | 180 | 3.9314 | 0.7301 | 0.7177 | 0.8230 | 0.7143 |
102
+ | 4.1966 | 1.4757 | 190 | 3.8398 | 0.7325 | 0.7196 | 0.8169 | 0.7175 |
103
+ | 4.1402 | 1.5534 | 200 | 3.7587 | 0.7381 | 0.7217 | 0.8149 | 0.7221 |
104
+ | 4.0771 | 1.6311 | 210 | 3.6745 | 0.7310 | 0.7149 | 0.8125 | 0.7160 |
105
+ | 4.0436 | 1.7087 | 220 | 3.5729 | 0.7364 | 0.7189 | 0.8121 | 0.7214 |
106
+ | 3.9697 | 1.7864 | 230 | 3.5030 | 0.7490 | 0.7339 | 0.8172 | 0.7358 |
107
+ | 3.9181 | 1.8641 | 240 | 3.4505 | 0.7541 | 0.7379 | 0.8123 | 0.7408 |
108
+ | 3.8573 | 1.9417 | 250 | 3.3529 | 0.7646 | 0.7453 | 0.8136 | 0.7521 |
109
+ | 3.8077 | 2.0194 | 260 | 3.2566 | 0.7660 | 0.7482 | 0.8093 | 0.7540 |
110
+ | 3.7449 | 2.0971 | 270 | 3.1869 | 0.7709 | 0.7510 | 0.8144 | 0.7588 |
111
+ | 3.682 | 2.1748 | 280 | 3.0898 | 0.7668 | 0.7440 | 0.8097 | 0.7548 |
112
+ | 3.6461 | 2.2524 | 290 | 3.0377 | 0.7641 | 0.7381 | 0.8100 | 0.7511 |
113
+ | 3.6004 | 2.3301 | 300 | 2.9001 | 0.7648 | 0.7384 | 0.8061 | 0.7522 |
114
+ | 3.5478 | 2.4078 | 310 | 2.8623 | 0.7653 | 0.7410 | 0.8060 | 0.7529 |
115
+ | 3.4971 | 2.4854 | 320 | 2.7961 | 0.7675 | 0.7447 | 0.8068 | 0.7558 |
116
+ | 3.4446 | 2.5631 | 330 | 2.6960 | 0.7690 | 0.7486 | 0.8128 | 0.7582 |
117
+ | 3.4093 | 2.6408 | 340 | 2.6480 | 0.7821 | 0.7652 | 0.8151 | 0.7718 |
118
+ | 3.3994 | 2.7184 | 350 | 2.5330 | 0.7847 | 0.7676 | 0.8156 | 0.7742 |
119
+ | 3.2963 | 2.7961 | 360 | 2.4866 | 0.7855 | 0.7681 | 0.8154 | 0.7752 |
120
+ | 3.2615 | 2.8738 | 370 | 2.4344 | 0.7891 | 0.7740 | 0.8172 | 0.7792 |
121
+ | 3.2024 | 2.9515 | 380 | 2.4011 | 0.7794 | 0.7638 | 0.8126 | 0.7694 |
122
+ | 3.1641 | 3.0291 | 390 | 2.3039 | 0.7835 | 0.7659 | 0.8100 | 0.7736 |
123
+ | 3.0719 | 3.1068 | 400 | 2.2471 | 0.7796 | 0.7608 | 0.8072 | 0.7691 |
124
+ | 3.0808 | 3.1845 | 410 | 2.2130 | 0.7896 | 0.7717 | 0.8137 | 0.7795 |
125
+ | 2.9916 | 3.2621 | 420 | 2.1387 | 0.7823 | 0.7652 | 0.8104 | 0.7718 |
126
+ | 2.9898 | 3.3398 | 430 | 2.0905 | 0.7981 | 0.7821 | 0.8250 | 0.7886 |
127
+ | 2.9597 | 3.4175 | 440 | 2.0260 | 0.7923 | 0.7769 | 0.8192 | 0.7826 |
128
+ | 2.9068 | 3.4951 | 450 | 1.9944 | 0.7976 | 0.7816 | 0.8233 | 0.7877 |
129
+ | 2.8423 | 3.5728 | 460 | 1.9643 | 0.7976 | 0.7805 | 0.8185 | 0.7876 |
130
+ | 2.8323 | 3.6505 | 470 | 1.8926 | 0.7935 | 0.7754 | 0.8136 | 0.7837 |
131
+ | 2.7814 | 3.7282 | 480 | 1.8676 | 0.8017 | 0.7856 | 0.8208 | 0.7917 |
132
+ | 2.7337 | 3.8058 | 490 | 1.8320 | 0.8052 | 0.7905 | 0.8246 | 0.7957 |
133
+ | 2.7215 | 3.8835 | 500 | 1.8003 | 0.7986 | 0.7834 | 0.8208 | 0.7890 |
134
+ | 2.6456 | 3.9612 | 510 | 1.7754 | 0.8005 | 0.7848 | 0.8230 | 0.7914 |
135
+ | 2.6494 | 4.0388 | 520 | 1.7083 | 0.8054 | 0.7895 | 0.8252 | 0.7967 |
136
+ | 2.5878 | 4.1165 | 530 | 1.6836 | 0.8054 | 0.7878 | 0.8239 | 0.7967 |
137
+ | 2.592 | 4.1942 | 540 | 1.6770 | 0.8005 | 0.7826 | 0.8220 | 0.7912 |
138
+ | 2.5698 | 4.2718 | 550 | 1.6184 | 0.8056 | 0.7881 | 0.8268 | 0.7970 |
139
+ | 2.52 | 4.3495 | 560 | 1.6368 | 0.8064 | 0.7898 | 0.8267 | 0.7975 |
140
+ | 2.5317 | 4.4272 | 570 | 1.5952 | 0.8059 | 0.7891 | 0.8289 | 0.7972 |
141
+ | 2.4199 | 4.5049 | 580 | 1.5518 | 0.8163 | 0.8002 | 0.8337 | 0.8082 |
142
+ | 2.4357 | 4.5825 | 590 | 1.5375 | 0.8095 | 0.7933 | 0.8263 | 0.8012 |
143
+ | 2.4217 | 4.6602 | 600 | 1.4994 | 0.8127 | 0.7964 | 0.8297 | 0.8042 |
144
+ | 2.428 | 4.7379 | 610 | 1.4671 | 0.8156 | 0.8003 | 0.8309 | 0.8074 |
145
+ | 2.3725 | 4.8155 | 620 | 1.4402 | 0.8141 | 0.7973 | 0.8295 | 0.8054 |
146
+ | 2.3594 | 4.8932 | 630 | 1.4566 | 0.8134 | 0.7976 | 0.8287 | 0.8049 |
147
+ | 2.3279 | 4.9709 | 640 | 1.4359 | 0.8183 | 0.8034 | 0.8314 | 0.8100 |
148
+ | 2.3166 | 5.0485 | 650 | 1.4067 | 0.8226 | 0.8086 | 0.8343 | 0.8149 |
149
+ | 2.3062 | 5.1262 | 660 | 1.3913 | 0.8212 | 0.8072 | 0.8340 | 0.8131 |
150
+ | 2.3096 | 5.2039 | 670 | 1.3577 | 0.8241 | 0.8107 | 0.8373 | 0.8159 |
151
+ | 2.2514 | 5.2816 | 680 | 1.3574 | 0.8270 | 0.8136 | 0.8371 | 0.8193 |
152
+ | 2.2053 | 5.3592 | 690 | 1.3450 | 0.8239 | 0.8101 | 0.8370 | 0.8164 |
153
+ | 2.2347 | 5.4369 | 700 | 1.3331 | 0.8270 | 0.8137 | 0.8388 | 0.8194 |
154
+ | 2.215 | 5.5146 | 710 | 1.2902 | 0.8294 | 0.8154 | 0.8419 | 0.8219 |
155
+ | 2.175 | 5.5922 | 720 | 1.2861 | 0.8256 | 0.8114 | 0.8388 | 0.8181 |
156
+ | 2.2212 | 5.6699 | 730 | 1.2637 | 0.8321 | 0.8180 | 0.8440 | 0.8241 |
157
+ | 2.1459 | 5.7476 | 740 | 1.2827 | 0.8302 | 0.8166 | 0.8396 | 0.8227 |
158
+ | 2.1615 | 5.8252 | 750 | 1.2800 | 0.8311 | 0.8184 | 0.8496 | 0.8239 |
159
+ | 2.0966 | 5.9029 | 760 | 1.2742 | 0.8326 | 0.8195 | 0.8418 | 0.8251 |
160
+ | 2.1314 | 5.9806 | 770 | 1.2464 | 0.8316 | 0.8184 | 0.8407 | 0.8238 |
161
+ | 2.0846 | 6.0583 | 780 | 1.2409 | 0.8326 | 0.8189 | 0.8414 | 0.8250 |
162
+ | 2.0522 | 6.1359 | 790 | 1.2023 | 0.8365 | 0.8233 | 0.8455 | 0.8292 |
163
+ | 2.0724 | 6.2136 | 800 | 1.2252 | 0.8309 | 0.8174 | 0.8396 | 0.8235 |
164
+ | 2.0848 | 6.2913 | 810 | 1.2025 | 0.8321 | 0.8186 | 0.8424 | 0.8248 |
165
+ | 2.0402 | 6.3689 | 820 | 1.2130 | 0.8333 | 0.8189 | 0.8428 | 0.8255 |
166
+ | 2.0778 | 6.4466 | 830 | 1.1809 | 0.8375 | 0.8249 | 0.8532 | 0.8302 |
167
+ | 2.0963 | 6.5243 | 840 | 1.1696 | 0.8365 | 0.8231 | 0.8527 | 0.8289 |
168
+ | 2.0576 | 6.6019 | 850 | 1.1866 | 0.8321 | 0.8181 | 0.8411 | 0.8245 |
169
+ | 2.0386 | 6.6796 | 860 | 1.1882 | 0.8302 | 0.8160 | 0.8389 | 0.8227 |
170
+ | 2.0084 | 6.7573 | 870 | 1.1696 | 0.8372 | 0.8244 | 0.8446 | 0.8301 |
171
+ | 2.0571 | 6.8350 | 880 | 1.1622 | 0.8353 | 0.8217 | 0.8437 | 0.8280 |
172
+ | 2.0264 | 6.9126 | 890 | 1.1640 | 0.8336 | 0.8204 | 0.8429 | 0.8263 |
173
+ | 2.0077 | 6.9903 | 900 | 1.1673 | 0.8367 | 0.8241 | 0.8447 | 0.8295 |
174
+ | 2.0492 | 7.0680 | 910 | 1.1455 | 0.8404 | 0.8269 | 0.8462 | 0.8330 |
175
+ | 1.9973 | 7.1456 | 920 | 1.1538 | 0.8379 | 0.8250 | 0.8455 | 0.8307 |
176
+ | 1.9961 | 7.2233 | 930 | 1.1502 | 0.8367 | 0.8236 | 0.8415 | 0.8295 |
177
+ | 1.9681 | 7.3010 | 940 | 1.1657 | 0.8384 | 0.8254 | 0.8463 | 0.8311 |
178
+ | 2.0188 | 7.3786 | 950 | 1.1309 | 0.8379 | 0.8252 | 0.8445 | 0.8310 |
179
+ | 2.0225 | 7.4563 | 960 | 1.1547 | 0.8367 | 0.8231 | 0.8446 | 0.8294 |
180
+ | 1.9562 | 7.5340 | 970 | 1.1474 | 0.8377 | 0.8243 | 0.8457 | 0.8305 |
181
+ | 2.0247 | 7.6117 | 980 | 1.1251 | 0.8365 | 0.8241 | 0.8449 | 0.8294 |
182
+ | 1.9355 | 7.6893 | 990 | 1.1349 | 0.8397 | 0.8276 | 0.8532 | 0.8329 |
183
+ | 1.9804 | 7.7670 | 1000 | 1.1545 | 0.8387 | 0.8260 | 0.8457 | 0.8315 |
184
+
185
+
186
+ ### Framework versions
187
+
188
+ - Transformers 4.40.2
189
+ - Pytorch 2.3.0
190
+ - Datasets 2.19.1
191
+ - Tokenizers 0.19.1
config.json ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "microsoft/resnet-50",
3
+ "architectures": [
4
+ "ResNetForImageClassification"
5
+ ],
6
+ "depths": [
7
+ 3,
8
+ 4,
9
+ 6,
10
+ 3
11
+ ],
12
+ "downsample_in_bottleneck": false,
13
+ "downsample_in_first_stage": false,
14
+ "embedding_size": 64,
15
+ "hidden_act": "relu",
16
+ "hidden_sizes": [
17
+ 256,
18
+ 512,
19
+ 1024,
20
+ 2048
21
+ ],
22
+ "id2label": {
23
+ "0": "Affenpinscher",
24
+ "1": "Afghan Hound",
25
+ "2": "African Hunting Dog",
26
+ "3": "Airedale",
27
+ "4": "American Staffordshire Terrier",
28
+ "5": "Appenzeller",
29
+ "6": "Australian Terrier",
30
+ "7": "Basenji",
31
+ "8": "Basset",
32
+ "9": "Beagle",
33
+ "10": "Bedlington Terrier",
34
+ "11": "Bernese Mountain Dog",
35
+ "12": "Black And Tan Coonhound",
36
+ "13": "Blenheim Spaniel",
37
+ "14": "Bloodhound",
38
+ "15": "Bluetick",
39
+ "16": "Border Collie",
40
+ "17": "Border Terrier",
41
+ "18": "Borzoi",
42
+ "19": "Boston Bull",
43
+ "20": "Bouvier Des Flandres",
44
+ "21": "Boxer",
45
+ "22": "Brabancon Griffon",
46
+ "23": "Briard",
47
+ "24": "Brittany Spaniel",
48
+ "25": "Bull Mastiff",
49
+ "26": "Cairn",
50
+ "27": "Cardigan",
51
+ "28": "Chesapeake Bay Retriever",
52
+ "29": "Chihuahua",
53
+ "30": "Chow",
54
+ "31": "Clumber",
55
+ "32": "Cocker Spaniel",
56
+ "33": "Collie",
57
+ "34": "Curly Coated Retriever",
58
+ "35": "Dandie Dinmont",
59
+ "36": "Dhole",
60
+ "37": "Dingo",
61
+ "38": "Doberman",
62
+ "39": "English Foxhound",
63
+ "40": "English Setter",
64
+ "41": "English Springer",
65
+ "42": "Entlebucher",
66
+ "43": "Eskimo Dog",
67
+ "44": "Flat Coated Retriever",
68
+ "45": "French Bulldog",
69
+ "46": "German Shepherd",
70
+ "47": "German Short Haired Pointer",
71
+ "48": "Giant Schnauzer",
72
+ "49": "Golden Retriever",
73
+ "50": "Gordon Setter",
74
+ "51": "Great Dane",
75
+ "52": "Great Pyrenees",
76
+ "53": "Greater Swiss Mountain Dog",
77
+ "54": "Groenendael",
78
+ "55": "Ibizan Hound",
79
+ "56": "Irish Setter",
80
+ "57": "Irish Terrier",
81
+ "58": "Irish Water Spaniel",
82
+ "59": "Irish Wolfhound",
83
+ "60": "Italian Greyhound",
84
+ "61": "Japanese Spaniel",
85
+ "62": "Keeshond",
86
+ "63": "Kelpie",
87
+ "64": "Kerry Blue Terrier",
88
+ "65": "Komondor",
89
+ "66": "Kuvasz",
90
+ "67": "Labrador Retriever",
91
+ "68": "Lakeland Terrier",
92
+ "69": "Leonberg",
93
+ "70": "Lhasa",
94
+ "71": "Malamute",
95
+ "72": "Malinois",
96
+ "73": "Maltese Dog",
97
+ "74": "Mexican Hairless",
98
+ "75": "Miniature Pinscher",
99
+ "76": "Miniature Poodle",
100
+ "77": "Miniature Schnauzer",
101
+ "78": "Newfoundland",
102
+ "79": "Norfolk Terrier",
103
+ "80": "Norwegian Elkhound",
104
+ "81": "Norwich Terrier",
105
+ "82": "Old English Sheepdog",
106
+ "83": "Otterhound",
107
+ "84": "Papillon",
108
+ "85": "Pekinese",
109
+ "86": "Pembroke",
110
+ "87": "Pomeranian",
111
+ "88": "Pug",
112
+ "89": "Redbone",
113
+ "90": "Rhodesian Ridgeback",
114
+ "91": "Rottweiler",
115
+ "92": "Saint Bernard",
116
+ "93": "Saluki",
117
+ "94": "Samoyed",
118
+ "95": "Schipperke",
119
+ "96": "Scotch Terrier",
120
+ "97": "Scottish Deerhound",
121
+ "98": "Sealyham Terrier",
122
+ "99": "Shetland Sheepdog",
123
+ "100": "Shih Tzu",
124
+ "101": "Siberian Husky",
125
+ "102": "Silky Terrier",
126
+ "103": "Soft Coated Wheaten Terrier",
127
+ "104": "Staffordshire Bullterrier",
128
+ "105": "Standard Poodle",
129
+ "106": "Standard Schnauzer",
130
+ "107": "Sussex Spaniel",
131
+ "108": "Tibetan Mastiff",
132
+ "109": "Tibetan Terrier",
133
+ "110": "Toy Poodle",
134
+ "111": "Toy Terrier",
135
+ "112": "Vizsla",
136
+ "113": "Walker Hound",
137
+ "114": "Weimaraner",
138
+ "115": "Welsh Springer Spaniel",
139
+ "116": "West Highland White Terrier",
140
+ "117": "Whippet",
141
+ "118": "Wire Haired Fox Terrier",
142
+ "119": "Yorkshire Terrier"
143
+ },
144
+ "label2id": {
145
+ "Affenpinscher": 0,
146
+ "Afghan Hound": 1,
147
+ "African Hunting Dog": 2,
148
+ "Airedale": 3,
149
+ "American Staffordshire Terrier": 4,
150
+ "Appenzeller": 5,
151
+ "Australian Terrier": 6,
152
+ "Basenji": 7,
153
+ "Basset": 8,
154
+ "Beagle": 9,
155
+ "Bedlington Terrier": 10,
156
+ "Bernese Mountain Dog": 11,
157
+ "Black And Tan Coonhound": 12,
158
+ "Blenheim Spaniel": 13,
159
+ "Bloodhound": 14,
160
+ "Bluetick": 15,
161
+ "Border Collie": 16,
162
+ "Border Terrier": 17,
163
+ "Borzoi": 18,
164
+ "Boston Bull": 19,
165
+ "Bouvier Des Flandres": 20,
166
+ "Boxer": 21,
167
+ "Brabancon Griffon": 22,
168
+ "Briard": 23,
169
+ "Brittany Spaniel": 24,
170
+ "Bull Mastiff": 25,
171
+ "Cairn": 26,
172
+ "Cardigan": 27,
173
+ "Chesapeake Bay Retriever": 28,
174
+ "Chihuahua": 29,
175
+ "Chow": 30,
176
+ "Clumber": 31,
177
+ "Cocker Spaniel": 32,
178
+ "Collie": 33,
179
+ "Curly Coated Retriever": 34,
180
+ "Dandie Dinmont": 35,
181
+ "Dhole": 36,
182
+ "Dingo": 37,
183
+ "Doberman": 38,
184
+ "English Foxhound": 39,
185
+ "English Setter": 40,
186
+ "English Springer": 41,
187
+ "Entlebucher": 42,
188
+ "Eskimo Dog": 43,
189
+ "Flat Coated Retriever": 44,
190
+ "French Bulldog": 45,
191
+ "German Shepherd": 46,
192
+ "German Short Haired Pointer": 47,
193
+ "Giant Schnauzer": 48,
194
+ "Golden Retriever": 49,
195
+ "Gordon Setter": 50,
196
+ "Great Dane": 51,
197
+ "Great Pyrenees": 52,
198
+ "Greater Swiss Mountain Dog": 53,
199
+ "Groenendael": 54,
200
+ "Ibizan Hound": 55,
201
+ "Irish Setter": 56,
202
+ "Irish Terrier": 57,
203
+ "Irish Water Spaniel": 58,
204
+ "Irish Wolfhound": 59,
205
+ "Italian Greyhound": 60,
206
+ "Japanese Spaniel": 61,
207
+ "Keeshond": 62,
208
+ "Kelpie": 63,
209
+ "Kerry Blue Terrier": 64,
210
+ "Komondor": 65,
211
+ "Kuvasz": 66,
212
+ "Labrador Retriever": 67,
213
+ "Lakeland Terrier": 68,
214
+ "Leonberg": 69,
215
+ "Lhasa": 70,
216
+ "Malamute": 71,
217
+ "Malinois": 72,
218
+ "Maltese Dog": 73,
219
+ "Mexican Hairless": 74,
220
+ "Miniature Pinscher": 75,
221
+ "Miniature Poodle": 76,
222
+ "Miniature Schnauzer": 77,
223
+ "Newfoundland": 78,
224
+ "Norfolk Terrier": 79,
225
+ "Norwegian Elkhound": 80,
226
+ "Norwich Terrier": 81,
227
+ "Old English Sheepdog": 82,
228
+ "Otterhound": 83,
229
+ "Papillon": 84,
230
+ "Pekinese": 85,
231
+ "Pembroke": 86,
232
+ "Pomeranian": 87,
233
+ "Pug": 88,
234
+ "Redbone": 89,
235
+ "Rhodesian Ridgeback": 90,
236
+ "Rottweiler": 91,
237
+ "Saint Bernard": 92,
238
+ "Saluki": 93,
239
+ "Samoyed": 94,
240
+ "Schipperke": 95,
241
+ "Scotch Terrier": 96,
242
+ "Scottish Deerhound": 97,
243
+ "Sealyham Terrier": 98,
244
+ "Shetland Sheepdog": 99,
245
+ "Shih Tzu": 100,
246
+ "Siberian Husky": 101,
247
+ "Silky Terrier": 102,
248
+ "Soft Coated Wheaten Terrier": 103,
249
+ "Staffordshire Bullterrier": 104,
250
+ "Standard Poodle": 105,
251
+ "Standard Schnauzer": 106,
252
+ "Sussex Spaniel": 107,
253
+ "Tibetan Mastiff": 108,
254
+ "Tibetan Terrier": 109,
255
+ "Toy Poodle": 110,
256
+ "Toy Terrier": 111,
257
+ "Vizsla": 112,
258
+ "Walker Hound": 113,
259
+ "Weimaraner": 114,
260
+ "Welsh Springer Spaniel": 115,
261
+ "West Highland White Terrier": 116,
262
+ "Whippet": 117,
263
+ "Wire Haired Fox Terrier": 118,
264
+ "Yorkshire Terrier": 119
265
+ },
266
+ "layer_type": "bottleneck",
267
+ "model_type": "resnet",
268
+ "num_channels": 3,
269
+ "out_features": [
270
+ "stage4"
271
+ ],
272
+ "out_indices": [
273
+ 4
274
+ ],
275
+ "problem_type": "single_label_classification",
276
+ "stage_names": [
277
+ "stem",
278
+ "stage1",
279
+ "stage2",
280
+ "stage3",
281
+ "stage4"
282
+ ],
283
+ "torch_dtype": "float32",
284
+ "transformers_version": "4.40.2"
285
+ }
config.toml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [training_args]
2
+ output_dir="/Users/andrewmayes/Openclassroom/CanineNet/code/"
3
+ evaluation_strategy="steps"
4
+ save_strategy="steps"
5
+ learning_rate=5e-5
6
+ #per_device_train_batch_size=32 # 512
7
+ #per_device_eval_batch_size=32 # 512
8
+ # num_train_epochs=5,
9
+ eval_delay=0 # 50
10
+ eval_steps=0.01
11
+ #eval_accumulation_steps
12
+ gradient_accumulation_steps=4
13
+ gradient_checkpointing=false#true
14
+ optim="adafactor"
15
+ max_steps=1000 # 100
16
+ #logging_dir=""
17
+ #log_level="error"
18
+ load_best_model_at_end=true
19
+ metric_for_best_model="f1"
20
+ greater_is_better=true
21
+ #use_mps_device=true
22
+ logging_steps=0.01
23
+ save_steps=0.01
24
+ #auto_find_batch_size=true
25
+ report_to="mlflow"
26
+ save_total_limit=2
27
+ #hub_model_id="amaye15/SwinV2-Base-Document-Classifier"
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac8d97ad215b4ae316fdf257126ee3fd0726b047c176129bcc2d16eecd327bb2
3
+ size 95270232
preprocessor_config.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_valid_processor_keys": [
3
+ "images",
4
+ "do_resize",
5
+ "size",
6
+ "crop_pct",
7
+ "resample",
8
+ "do_rescale",
9
+ "rescale_factor",
10
+ "do_normalize",
11
+ "image_mean",
12
+ "image_std",
13
+ "return_tensors",
14
+ "data_format",
15
+ "input_data_format"
16
+ ],
17
+ "crop_pct": 0.875,
18
+ "do_normalize": true,
19
+ "do_rescale": true,
20
+ "do_resize": true,
21
+ "image_mean": [
22
+ 0.485,
23
+ 0.456,
24
+ 0.406
25
+ ],
26
+ "image_processor_type": "ConvNextImageProcessor",
27
+ "image_std": [
28
+ 0.229,
29
+ 0.224,
30
+ 0.225
31
+ ],
32
+ "resample": 3,
33
+ "rescale_factor": 0.00392156862745098,
34
+ "size": {
35
+ "shortest_edge": 224
36
+ }
37
+ }
train.ipynb ADDED
@@ -0,0 +1,926 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# Install"
8
+ ]
9
+ },
10
+ {
11
+ "cell_type": "code",
12
+ "execution_count": 1,
13
+ "metadata": {},
14
+ "outputs": [
15
+ {
16
+ "name": "stdout",
17
+ "output_type": "stream",
18
+ "text": [
19
+ "Requirement already satisfied: uv in /Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages (0.1.42)\n",
20
+ "Note: you may need to restart the kernel to use updated packages.\n"
21
+ ]
22
+ }
23
+ ],
24
+ "source": [
25
+ "%pip install uv"
26
+ ]
27
+ },
28
+ {
29
+ "cell_type": "code",
30
+ "execution_count": 2,
31
+ "metadata": {},
32
+ "outputs": [
33
+ {
34
+ "name": "stdout",
35
+ "output_type": "stream",
36
+ "text": [
37
+ "\u001b[2mAudited \u001b[1m12 packages\u001b[0m in 8ms\u001b[0m\n"
38
+ ]
39
+ }
40
+ ],
41
+ "source": [
42
+ "!uv pip install dagshub setuptools accelerate toml torch torchvision transformers mlflow datasets ipywidgets python-dotenv evaluate"
43
+ ]
44
+ },
45
+ {
46
+ "cell_type": "markdown",
47
+ "metadata": {},
48
+ "source": [
49
+ "# Setup"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "execution_count": 3,
55
+ "metadata": {},
56
+ "outputs": [
57
+ {
58
+ "data": {
59
+ "text/html": [
60
+ "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Initialized MLflow to track repo <span style=\"color: #008000; text-decoration-color: #008000\">\"amaye15/CanineNet\"</span>\n",
61
+ "</pre>\n"
62
+ ],
63
+ "text/plain": [
64
+ "Initialized MLflow to track repo \u001b[32m\"amaye15/CanineNet\"\u001b[0m\n"
65
+ ]
66
+ },
67
+ "metadata": {},
68
+ "output_type": "display_data"
69
+ },
70
+ {
71
+ "data": {
72
+ "text/html": [
73
+ "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Repository amaye15/CanineNet initialized!\n",
74
+ "</pre>\n"
75
+ ],
76
+ "text/plain": [
77
+ "Repository amaye15/CanineNet initialized!\n"
78
+ ]
79
+ },
80
+ "metadata": {},
81
+ "output_type": "display_data"
82
+ }
83
+ ],
84
+ "source": [
85
+ "import os\n",
86
+ "import toml\n",
87
+ "import torch\n",
88
+ "import mlflow\n",
89
+ "import dagshub\n",
90
+ "import datasets\n",
91
+ "import evaluate\n",
92
+ "from dotenv import load_dotenv\n",
93
+ "from torchvision.transforms import v2\n",
94
+ "from transformers import AutoImageProcessor, AutoModelForImageClassification, TrainingArguments, Trainer\n",
95
+ "\n",
96
+ "ENV_PATH = \"/Users/andrewmayes/Openclassroom/CanineNet/.env\"\n",
97
+ "CONFIG_PATH = \"/Users/andrewmayes/Openclassroom/CanineNet/code/config.toml\"\n",
98
+ "CONFIG = toml.load(CONFIG_PATH)\n",
99
+ "\n",
100
+ "load_dotenv(ENV_PATH)\n",
101
+ "\n",
102
+ "dagshub.init(repo_name=os.environ['MLFLOW_TRACKING_PROJECTNAME'], repo_owner=os.environ['MLFLOW_TRACKING_USERNAME'], mlflow=True, dvc=True)\n",
103
+ "\n",
104
+ "os.environ['MLFLOW_TRACKING_USERNAME'] = \"amaye15\"\n",
105
+ "\n",
106
+ "mlflow.set_tracking_uri(f'https://dagshub.com/' + os.environ['MLFLOW_TRACKING_USERNAME']\n",
107
+ " + '/' + os.environ['MLFLOW_TRACKING_PROJECTNAME'] + '.mlflow')\n",
108
+ "\n",
109
+ "CREATE_DATASET = True\n",
110
+ "ORIGINAL_DATASET = \"Alanox/stanford-dogs\"\n",
111
+ "MODIFIED_DATASET = \"amaye15/stanford-dogs\"\n",
112
+ "REMOVE_COLUMNS = [\"name\", \"annotations\"]\n",
113
+ "RENAME_COLUMNS = {\"image\":\"pixel_values\", \"target\":\"label\"}\n",
114
+ "SPLIT = 0.2\n",
115
+ "\n",
116
+ "METRICS = [\"accuracy\", \"f1\", \"precision\", \"recall\"]\n",
117
+ "# MODELS = 'google/vit-base-patch16-224'\n",
118
+ "# MODELS = \"google/siglip-base-patch16-224\"\n",
119
+ "\n"
120
+ ]
121
+ },
122
+ {
123
+ "cell_type": "markdown",
124
+ "metadata": {},
125
+ "source": [
126
+ "# Dataset"
127
+ ]
128
+ },
129
+ {
130
+ "cell_type": "code",
131
+ "execution_count": 4,
132
+ "metadata": {},
133
+ "outputs": [
134
+ {
135
+ "name": "stdout",
136
+ "output_type": "stream",
137
+ "text": [
138
+ "Affenpinscher: 0\n",
139
+ "Afghan Hound: 1\n",
140
+ "African Hunting Dog: 2\n",
141
+ "Airedale: 3\n",
142
+ "American Staffordshire Terrier: 4\n",
143
+ "Appenzeller: 5\n",
144
+ "Australian Terrier: 6\n",
145
+ "Basenji: 7\n",
146
+ "Basset: 8\n",
147
+ "Beagle: 9\n",
148
+ "Bedlington Terrier: 10\n",
149
+ "Bernese Mountain Dog: 11\n",
150
+ "Black And Tan Coonhound: 12\n",
151
+ "Blenheim Spaniel: 13\n",
152
+ "Bloodhound: 14\n",
153
+ "Bluetick: 15\n",
154
+ "Border Collie: 16\n",
155
+ "Border Terrier: 17\n",
156
+ "Borzoi: 18\n",
157
+ "Boston Bull: 19\n",
158
+ "Bouvier Des Flandres: 20\n",
159
+ "Boxer: 21\n",
160
+ "Brabancon Griffon: 22\n",
161
+ "Briard: 23\n",
162
+ "Brittany Spaniel: 24\n",
163
+ "Bull Mastiff: 25\n",
164
+ "Cairn: 26\n",
165
+ "Cardigan: 27\n",
166
+ "Chesapeake Bay Retriever: 28\n",
167
+ "Chihuahua: 29\n",
168
+ "Chow: 30\n",
169
+ "Clumber: 31\n",
170
+ "Cocker Spaniel: 32\n",
171
+ "Collie: 33\n",
172
+ "Curly Coated Retriever: 34\n",
173
+ "Dandie Dinmont: 35\n",
174
+ "Dhole: 36\n",
175
+ "Dingo: 37\n",
176
+ "Doberman: 38\n",
177
+ "English Foxhound: 39\n",
178
+ "English Setter: 40\n",
179
+ "English Springer: 41\n",
180
+ "Entlebucher: 42\n",
181
+ "Eskimo Dog: 43\n",
182
+ "Flat Coated Retriever: 44\n",
183
+ "French Bulldog: 45\n",
184
+ "German Shepherd: 46\n",
185
+ "German Short Haired Pointer: 47\n",
186
+ "Giant Schnauzer: 48\n",
187
+ "Golden Retriever: 49\n",
188
+ "Gordon Setter: 50\n",
189
+ "Great Dane: 51\n",
190
+ "Great Pyrenees: 52\n",
191
+ "Greater Swiss Mountain Dog: 53\n",
192
+ "Groenendael: 54\n",
193
+ "Ibizan Hound: 55\n",
194
+ "Irish Setter: 56\n",
195
+ "Irish Terrier: 57\n",
196
+ "Irish Water Spaniel: 58\n",
197
+ "Irish Wolfhound: 59\n",
198
+ "Italian Greyhound: 60\n",
199
+ "Japanese Spaniel: 61\n",
200
+ "Keeshond: 62\n",
201
+ "Kelpie: 63\n",
202
+ "Kerry Blue Terrier: 64\n",
203
+ "Komondor: 65\n",
204
+ "Kuvasz: 66\n",
205
+ "Labrador Retriever: 67\n",
206
+ "Lakeland Terrier: 68\n",
207
+ "Leonberg: 69\n",
208
+ "Lhasa: 70\n",
209
+ "Malamute: 71\n",
210
+ "Malinois: 72\n",
211
+ "Maltese Dog: 73\n",
212
+ "Mexican Hairless: 74\n",
213
+ "Miniature Pinscher: 75\n",
214
+ "Miniature Poodle: 76\n",
215
+ "Miniature Schnauzer: 77\n",
216
+ "Newfoundland: 78\n",
217
+ "Norfolk Terrier: 79\n",
218
+ "Norwegian Elkhound: 80\n",
219
+ "Norwich Terrier: 81\n",
220
+ "Old English Sheepdog: 82\n",
221
+ "Otterhound: 83\n",
222
+ "Papillon: 84\n",
223
+ "Pekinese: 85\n",
224
+ "Pembroke: 86\n",
225
+ "Pomeranian: 87\n",
226
+ "Pug: 88\n",
227
+ "Redbone: 89\n",
228
+ "Rhodesian Ridgeback: 90\n",
229
+ "Rottweiler: 91\n",
230
+ "Saint Bernard: 92\n",
231
+ "Saluki: 93\n",
232
+ "Samoyed: 94\n",
233
+ "Schipperke: 95\n",
234
+ "Scotch Terrier: 96\n",
235
+ "Scottish Deerhound: 97\n",
236
+ "Sealyham Terrier: 98\n",
237
+ "Shetland Sheepdog: 99\n",
238
+ "Shih Tzu: 100\n",
239
+ "Siberian Husky: 101\n",
240
+ "Silky Terrier: 102\n",
241
+ "Soft Coated Wheaten Terrier: 103\n",
242
+ "Staffordshire Bullterrier: 104\n",
243
+ "Standard Poodle: 105\n",
244
+ "Standard Schnauzer: 106\n",
245
+ "Sussex Spaniel: 107\n",
246
+ "Tibetan Mastiff: 108\n",
247
+ "Tibetan Terrier: 109\n",
248
+ "Toy Poodle: 110\n",
249
+ "Toy Terrier: 111\n",
250
+ "Vizsla: 112\n",
251
+ "Walker Hound: 113\n",
252
+ "Weimaraner: 114\n",
253
+ "Welsh Springer Spaniel: 115\n",
254
+ "West Highland White Terrier: 116\n",
255
+ "Whippet: 117\n",
256
+ "Wire Haired Fox Terrier: 118\n",
257
+ "Yorkshire Terrier: 119\n"
258
+ ]
259
+ }
260
+ ],
261
+ "source": [
262
+ "if CREATE_DATASET:\n",
263
+ " ds = datasets.load_dataset(ORIGINAL_DATASET, token=os.getenv(\"HF_TOKEN\"), split=\"full\", trust_remote_code=True)\n",
264
+ " ds = ds.remove_columns(REMOVE_COLUMNS).rename_columns(RENAME_COLUMNS)\n",
265
+ "\n",
266
+ " labels = ds.select_columns(\"label\").to_pandas().sort_values(\"label\").get(\"label\").unique().tolist()\n",
267
+ " numbers = range(len(labels))\n",
268
+ " label2int = dict(zip(labels, numbers))\n",
269
+ " int2label = dict(zip(numbers, labels))\n",
270
+ "\n",
271
+ " for key, val in label2int.items():\n",
272
+ " print(f\"{key}: {val}\")\n",
273
+ "\n",
274
+ " ds = ds.class_encode_column(\"label\")\n",
275
+ " ds = ds.align_labels_with_mapping(label2int, \"label\")\n",
276
+ "\n",
277
+ " ds = ds.train_test_split(test_size=SPLIT, stratify_by_column = \"label\")\n",
278
+ " #ds.push_to_hub(MODIFIED_DATASET, token=os.getenv(\"HF_TOKEN\"))\n",
279
+ "\n",
280
+ " CONFIG[\"label2int\"] = str(label2int)\n",
281
+ " CONFIG[\"int2label\"] = str(int2label)\n",
282
+ "\n",
283
+ " # with open(\"output.toml\", \"w\") as toml_file:\n",
284
+ " # toml.dump(toml.dumps(CONFIG), toml_file)\n",
285
+ "\n",
286
+ " #ds = datasets.load_dataset(MODIFIED_DATASET, token=os.getenv(\"HF_TOKEN\"), trust_remote_code=True, streaming=True)"
287
+ ]
288
+ },
289
+ {
290
+ "cell_type": "code",
291
+ "execution_count": 5,
292
+ "metadata": {},
293
+ "outputs": [
294
+ {
295
+ "name": "stderr",
296
+ "output_type": "stream",
297
+ "text": [
298
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/huggingface_hub/file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.\n",
299
+ " warnings.warn(\n",
300
+ "Could not find image processor class in the image processor config or the model config. Loading based on pattern matching with the model's feature extractor configuration. Please open a PR/issue to update `preprocessor_config.json` to use `image_processor_type` instead of `feature_extractor_type`. This warning will be removed in v4.40.\n",
301
+ "Some weights of ResNetForImageClassification were not initialized from the model checkpoint at microsoft/resnet-50 and are newly initialized because the shapes did not match:\n",
302
+ "- classifier.1.bias: found shape torch.Size([1000]) in the checkpoint and torch.Size([120]) in the model instantiated\n",
303
+ "- classifier.1.weight: found shape torch.Size([1000, 2048]) in the checkpoint and torch.Size([120, 2048]) in the model instantiated\n",
304
+ "You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n",
305
+ "max_steps is given, it will override any value given in num_train_epochs\n"
306
+ ]
307
+ },
308
+ {
309
+ "data": {
310
+ "application/vnd.jupyter.widget-view+json": {
311
+ "model_id": "037a86c2839440679fcff5595079beac",
312
+ "version_major": 2,
313
+ "version_minor": 0
314
+ },
315
+ "text/plain": [
316
+ " 0%| | 0/1000 [00:00<?, ?it/s]"
317
+ ]
318
+ },
319
+ "metadata": {},
320
+ "output_type": "display_data"
321
+ },
322
+ {
323
+ "name": "stdout",
324
+ "output_type": "stream",
325
+ "text": [
326
+ "{'loss': 4.7829, 'grad_norm': 0.6043907999992371, 'learning_rate': 4.9500000000000004e-05, 'epoch': 0.08}\n"
327
+ ]
328
+ },
329
+ {
330
+ "data": {
331
+ "application/vnd.jupyter.widget-view+json": {
332
+ "model_id": "b1f85d03fadd4763a741fec5e5285d2a",
333
+ "version_major": 2,
334
+ "version_minor": 0
335
+ },
336
+ "text/plain": [
337
+ " 0%| | 0/129 [00:00<?, ?it/s]"
338
+ ]
339
+ },
340
+ "metadata": {},
341
+ "output_type": "display_data"
342
+ },
343
+ {
344
+ "name": "stderr",
345
+ "output_type": "stream",
346
+ "text": [
347
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1509: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
348
+ " _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
349
+ ]
350
+ },
351
+ {
352
+ "name": "stdout",
353
+ "output_type": "stream",
354
+ "text": [
355
+ "{'eval_loss': 4.77471923828125, 'eval_accuracy': 0.2118561710398445, 'eval_f1': 0.187375517726323, 'eval_precision': 0.3919036860239945, 'eval_recall': 0.19824327355121704, 'eval_runtime': 33.4309, 'eval_samples_per_second': 123.12, 'eval_steps_per_second': 3.859, 'epoch': 0.08}\n",
356
+ "{'loss': 4.7714, 'grad_norm': 0.6754865050315857, 'learning_rate': 4.9e-05, 'epoch': 0.16}\n"
357
+ ]
358
+ },
359
+ {
360
+ "data": {
361
+ "application/vnd.jupyter.widget-view+json": {
362
+ "model_id": "268749f0d84a4fde98822b2ce1eead4f",
363
+ "version_major": 2,
364
+ "version_minor": 0
365
+ },
366
+ "text/plain": [
367
+ " 0%| | 0/129 [00:00<?, ?it/s]"
368
+ ]
369
+ },
370
+ "metadata": {},
371
+ "output_type": "display_data"
372
+ },
373
+ {
374
+ "name": "stderr",
375
+ "output_type": "stream",
376
+ "text": [
377
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1509: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
378
+ " _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
379
+ ]
380
+ },
381
+ {
382
+ "name": "stdout",
383
+ "output_type": "stream",
384
+ "text": [
385
+ "{'eval_loss': 4.757228851318359, 'eval_accuracy': 0.20383867832847424, 'eval_f1': 0.18416981866925827, 'eval_precision': 0.42618136770448983, 'eval_recall': 0.18363998800713158, 'eval_runtime': 30.7622, 'eval_samples_per_second': 133.801, 'eval_steps_per_second': 4.193, 'epoch': 0.16}\n",
386
+ "{'loss': 4.7606, 'grad_norm': 0.6417286992073059, 'learning_rate': 4.85e-05, 'epoch': 0.23}\n"
387
+ ]
388
+ },
389
+ {
390
+ "data": {
391
+ "application/vnd.jupyter.widget-view+json": {
392
+ "model_id": "907e888ac52d4fe18fb87cc1cfe2b22f",
393
+ "version_major": 2,
394
+ "version_minor": 0
395
+ },
396
+ "text/plain": [
397
+ " 0%| | 0/129 [00:00<?, ?it/s]"
398
+ ]
399
+ },
400
+ "metadata": {},
401
+ "output_type": "display_data"
402
+ },
403
+ {
404
+ "name": "stderr",
405
+ "output_type": "stream",
406
+ "text": [
407
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1509: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
408
+ " _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
409
+ ]
410
+ },
411
+ {
412
+ "name": "stdout",
413
+ "output_type": "stream",
414
+ "text": [
415
+ "{'eval_loss': 4.736657619476318, 'eval_accuracy': 0.358600583090379, 'eval_f1': 0.3433113409864575, 'eval_precision': 0.6517178219942168, 'eval_recall': 0.3306848427836897, 'eval_runtime': 29.5337, 'eval_samples_per_second': 139.366, 'eval_steps_per_second': 4.368, 'epoch': 0.23}\n",
416
+ "{'loss': 4.747, 'grad_norm': 0.6243997812271118, 'learning_rate': 4.8e-05, 'epoch': 0.31}\n"
417
+ ]
418
+ },
419
+ {
420
+ "data": {
421
+ "application/vnd.jupyter.widget-view+json": {
422
+ "model_id": "a2c7266f55814c86badb55ec9f3c12cc",
423
+ "version_major": 2,
424
+ "version_minor": 0
425
+ },
426
+ "text/plain": [
427
+ " 0%| | 0/129 [00:00<?, ?it/s]"
428
+ ]
429
+ },
430
+ "metadata": {},
431
+ "output_type": "display_data"
432
+ },
433
+ {
434
+ "name": "stderr",
435
+ "output_type": "stream",
436
+ "text": [
437
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1509: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
438
+ " _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
439
+ ]
440
+ },
441
+ {
442
+ "name": "stdout",
443
+ "output_type": "stream",
444
+ "text": [
445
+ "{'eval_loss': 4.714941501617432, 'eval_accuracy': 0.4302721088435374, 'eval_f1': 0.42721541071711805, 'eval_precision': 0.773414620851018, 'eval_recall': 0.40385862239180403, 'eval_runtime': 31.0076, 'eval_samples_per_second': 132.742, 'eval_steps_per_second': 4.16, 'epoch': 0.31}\n",
446
+ "{'loss': 4.7253, 'grad_norm': 0.6433669328689575, 'learning_rate': 4.75e-05, 'epoch': 0.39}\n"
447
+ ]
448
+ },
449
+ {
450
+ "data": {
451
+ "application/vnd.jupyter.widget-view+json": {
452
+ "model_id": "8a6ab27c180d4d68925da71fb6d734d8",
453
+ "version_major": 2,
454
+ "version_minor": 0
455
+ },
456
+ "text/plain": [
457
+ " 0%| | 0/129 [00:00<?, ?it/s]"
458
+ ]
459
+ },
460
+ "metadata": {},
461
+ "output_type": "display_data"
462
+ },
463
+ {
464
+ "name": "stderr",
465
+ "output_type": "stream",
466
+ "text": [
467
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1509: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
468
+ " _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
469
+ ]
470
+ },
471
+ {
472
+ "name": "stdout",
473
+ "output_type": "stream",
474
+ "text": [
475
+ "{'eval_loss': 4.684640884399414, 'eval_accuracy': 0.4361030126336249, 'eval_f1': 0.4677602303574034, 'eval_precision': 0.7906333558807621, 'eval_recall': 0.4160270614713831, 'eval_runtime': 31.2777, 'eval_samples_per_second': 131.595, 'eval_steps_per_second': 4.124, 'epoch': 0.39}\n",
476
+ "{'loss': 4.7069, 'grad_norm': 0.7207397818565369, 'learning_rate': 4.7e-05, 'epoch': 0.47}\n"
477
+ ]
478
+ },
479
+ {
480
+ "data": {
481
+ "application/vnd.jupyter.widget-view+json": {
482
+ "model_id": "ff7ef69b883549f988fda71b35cb9ef1",
483
+ "version_major": 2,
484
+ "version_minor": 0
485
+ },
486
+ "text/plain": [
487
+ " 0%| | 0/129 [00:00<?, ?it/s]"
488
+ ]
489
+ },
490
+ "metadata": {},
491
+ "output_type": "display_data"
492
+ },
493
+ {
494
+ "name": "stderr",
495
+ "output_type": "stream",
496
+ "text": [
497
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1509: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
498
+ " _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
499
+ ]
500
+ },
501
+ {
502
+ "name": "stdout",
503
+ "output_type": "stream",
504
+ "text": [
505
+ "{'eval_loss': 4.653403282165527, 'eval_accuracy': 0.533041788143829, 'eval_f1': 0.5396864056951644, 'eval_precision': 0.804847761263092, 'eval_recall': 0.5092981237432466, 'eval_runtime': 28.6761, 'eval_samples_per_second': 143.534, 'eval_steps_per_second': 4.499, 'epoch': 0.47}\n",
506
+ "{'loss': 4.6857, 'grad_norm': 0.7303667068481445, 'learning_rate': 4.6500000000000005e-05, 'epoch': 0.54}\n"
507
+ ]
508
+ },
509
+ {
510
+ "data": {
511
+ "application/vnd.jupyter.widget-view+json": {
512
+ "model_id": "c293ebbb0aec4666b6ad0d17517e2a29",
513
+ "version_major": 2,
514
+ "version_minor": 0
515
+ },
516
+ "text/plain": [
517
+ " 0%| | 0/129 [00:00<?, ?it/s]"
518
+ ]
519
+ },
520
+ "metadata": {},
521
+ "output_type": "display_data"
522
+ },
523
+ {
524
+ "name": "stderr",
525
+ "output_type": "stream",
526
+ "text": [
527
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1509: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
528
+ " _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
529
+ ]
530
+ },
531
+ {
532
+ "name": "stdout",
533
+ "output_type": "stream",
534
+ "text": [
535
+ "{'eval_loss': 4.617745399475098, 'eval_accuracy': 0.5500485908649174, 'eval_f1': 0.5511369002526866, 'eval_precision': 0.7998093864476505, 'eval_recall': 0.5263615811202424, 'eval_runtime': 28.5304, 'eval_samples_per_second': 144.267, 'eval_steps_per_second': 4.521, 'epoch': 0.54}\n",
536
+ "{'loss': 4.6569, 'grad_norm': 0.744701623916626, 'learning_rate': 4.600000000000001e-05, 'epoch': 0.62}\n"
537
+ ]
538
+ },
539
+ {
540
+ "data": {
541
+ "application/vnd.jupyter.widget-view+json": {
542
+ "model_id": "53ce3795c47f4dd18f0f926d1532fb9a",
543
+ "version_major": 2,
544
+ "version_minor": 0
545
+ },
546
+ "text/plain": [
547
+ " 0%| | 0/129 [00:00<?, ?it/s]"
548
+ ]
549
+ },
550
+ "metadata": {},
551
+ "output_type": "display_data"
552
+ },
553
+ {
554
+ "name": "stderr",
555
+ "output_type": "stream",
556
+ "text": [
557
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1509: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
558
+ " _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
559
+ ]
560
+ },
561
+ {
562
+ "name": "stdout",
563
+ "output_type": "stream",
564
+ "text": [
565
+ "{'eval_loss': 4.576382160186768, 'eval_accuracy': 0.5738581146744413, 'eval_f1': 0.5800354551041117, 'eval_precision': 0.8207891649420048, 'eval_recall': 0.5516830965289926, 'eval_runtime': 28.9367, 'eval_samples_per_second': 142.241, 'eval_steps_per_second': 4.458, 'epoch': 0.62}\n",
566
+ "{'loss': 4.6293, 'grad_norm': 0.8225492238998413, 'learning_rate': 4.55e-05, 'epoch': 0.7}\n"
567
+ ]
568
+ },
569
+ {
570
+ "data": {
571
+ "application/vnd.jupyter.widget-view+json": {
572
+ "model_id": "388b626051df4cde8bfacb4f10f53706",
573
+ "version_major": 2,
574
+ "version_minor": 0
575
+ },
576
+ "text/plain": [
577
+ " 0%| | 0/129 [00:00<?, ?it/s]"
578
+ ]
579
+ },
580
+ "metadata": {},
581
+ "output_type": "display_data"
582
+ },
583
+ {
584
+ "name": "stderr",
585
+ "output_type": "stream",
586
+ "text": [
587
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1509: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
588
+ " _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
589
+ ]
590
+ },
591
+ {
592
+ "name": "stdout",
593
+ "output_type": "stream",
594
+ "text": [
595
+ "{'eval_loss': 4.535852432250977, 'eval_accuracy': 0.6141885325558795, 'eval_f1': 0.6148517759248673, 'eval_precision': 0.807489842077252, 'eval_recall': 0.5926437581767611, 'eval_runtime': 29.8128, 'eval_samples_per_second': 138.062, 'eval_steps_per_second': 4.327, 'epoch': 0.7}\n",
596
+ "{'loss': 4.5953, 'grad_norm': 0.835442066192627, 'learning_rate': 4.5e-05, 'epoch': 0.78}\n"
597
+ ]
598
+ },
599
+ {
600
+ "data": {
601
+ "application/vnd.jupyter.widget-view+json": {
602
+ "model_id": "0969f9351eae4472814238ff34b3a129",
603
+ "version_major": 2,
604
+ "version_minor": 0
605
+ },
606
+ "text/plain": [
607
+ " 0%| | 0/129 [00:00<?, ?it/s]"
608
+ ]
609
+ },
610
+ "metadata": {},
611
+ "output_type": "display_data"
612
+ },
613
+ {
614
+ "name": "stderr",
615
+ "output_type": "stream",
616
+ "text": [
617
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1509: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
618
+ " _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
619
+ ]
620
+ },
621
+ {
622
+ "name": "stdout",
623
+ "output_type": "stream",
624
+ "text": [
625
+ "{'eval_loss': 4.482782363891602, 'eval_accuracy': 0.6207482993197279, 'eval_f1': 0.6233347480319061, 'eval_precision': 0.8108960881073339, 'eval_recall': 0.5999664720807305, 'eval_runtime': 30.0674, 'eval_samples_per_second': 136.893, 'eval_steps_per_second': 4.29, 'epoch': 0.78}\n",
626
+ "{'loss': 4.5651, 'grad_norm': 0.8578382134437561, 'learning_rate': 4.4500000000000004e-05, 'epoch': 0.85}\n"
627
+ ]
628
+ },
629
+ {
630
+ "data": {
631
+ "application/vnd.jupyter.widget-view+json": {
632
+ "model_id": "30b40f923e894e87b98cd86c2fe885e0",
633
+ "version_major": 2,
634
+ "version_minor": 0
635
+ },
636
+ "text/plain": [
637
+ " 0%| | 0/129 [00:00<?, ?it/s]"
638
+ ]
639
+ },
640
+ "metadata": {},
641
+ "output_type": "display_data"
642
+ },
643
+ {
644
+ "name": "stderr",
645
+ "output_type": "stream",
646
+ "text": [
647
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1509: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
648
+ " _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
649
+ ]
650
+ },
651
+ {
652
+ "name": "stdout",
653
+ "output_type": "stream",
654
+ "text": [
655
+ "{'eval_loss': 4.425670146942139, 'eval_accuracy': 0.6591350826044704, 'eval_f1': 0.6584699253003153, 'eval_precision': 0.8147592711787498, 'eval_recall': 0.6393439002306762, 'eval_runtime': 28.4304, 'eval_samples_per_second': 144.775, 'eval_steps_per_second': 4.537, 'epoch': 0.85}\n",
656
+ "{'loss': 4.5296, 'grad_norm': 0.9620392322540283, 'learning_rate': 4.4000000000000006e-05, 'epoch': 0.93}\n"
657
+ ]
658
+ },
659
+ {
660
+ "data": {
661
+ "application/vnd.jupyter.widget-view+json": {
662
+ "model_id": "0a2e4094efc9460e8b0720746df15da2",
663
+ "version_major": 2,
664
+ "version_minor": 0
665
+ },
666
+ "text/plain": [
667
+ " 0%| | 0/129 [00:00<?, ?it/s]"
668
+ ]
669
+ },
670
+ "metadata": {},
671
+ "output_type": "display_data"
672
+ },
673
+ {
674
+ "name": "stderr",
675
+ "output_type": "stream",
676
+ "text": [
677
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1509: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
678
+ " _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
679
+ ]
680
+ },
681
+ {
682
+ "name": "stdout",
683
+ "output_type": "stream",
684
+ "text": [
685
+ "{'eval_loss': 4.364680290222168, 'eval_accuracy': 0.706268221574344, 'eval_f1': 0.7012054635300039, 'eval_precision': 0.8284350125904834, 'eval_recall': 0.688199507444556, 'eval_runtime': 28.5471, 'eval_samples_per_second': 144.183, 'eval_steps_per_second': 4.519, 'epoch': 0.93}\n",
686
+ "{'loss': 4.4911, 'grad_norm': 0.9173192977905273, 'learning_rate': 4.35e-05, 'epoch': 1.01}\n"
687
+ ]
688
+ },
689
+ {
690
+ "data": {
691
+ "application/vnd.jupyter.widget-view+json": {
692
+ "model_id": "18ea4e46851043e9bd175bd132b7ed0f",
693
+ "version_major": 2,
694
+ "version_minor": 0
695
+ },
696
+ "text/plain": [
697
+ " 0%| | 0/129 [00:00<?, ?it/s]"
698
+ ]
699
+ },
700
+ "metadata": {},
701
+ "output_type": "display_data"
702
+ },
703
+ {
704
+ "name": "stderr",
705
+ "output_type": "stream",
706
+ "text": [
707
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1509: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
708
+ " _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
709
+ ]
710
+ },
711
+ {
712
+ "name": "stdout",
713
+ "output_type": "stream",
714
+ "text": [
715
+ "{'eval_loss': 4.299846649169922, 'eval_accuracy': 0.7089407191448007, 'eval_f1': 0.7073568856764126, 'eval_precision': 0.8325596625698185, 'eval_recall': 0.6924090542708233, 'eval_runtime': 28.5965, 'eval_samples_per_second': 143.934, 'eval_steps_per_second': 4.511, 'epoch': 1.01}\n",
716
+ "{'loss': 4.4442, 'grad_norm': 0.9183776378631592, 'learning_rate': 4.3e-05, 'epoch': 1.09}\n"
717
+ ]
718
+ },
719
+ {
720
+ "data": {
721
+ "application/vnd.jupyter.widget-view+json": {
722
+ "model_id": "f77e01f5212d46f49e8970bae34705be",
723
+ "version_major": 2,
724
+ "version_minor": 0
725
+ },
726
+ "text/plain": [
727
+ " 0%| | 0/129 [00:00<?, ?it/s]"
728
+ ]
729
+ },
730
+ "metadata": {},
731
+ "output_type": "display_data"
732
+ },
733
+ {
734
+ "name": "stderr",
735
+ "output_type": "stream",
736
+ "text": [
737
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1509: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
738
+ " _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
739
+ ]
740
+ },
741
+ {
742
+ "name": "stdout",
743
+ "output_type": "stream",
744
+ "text": [
745
+ "{'eval_loss': 4.228794574737549, 'eval_accuracy': 0.6938775510204082, 'eval_f1': 0.6890499178440211, 'eval_precision': 0.8302365826885487, 'eval_recall': 0.6758939664483897, 'eval_runtime': 28.7618, 'eval_samples_per_second': 143.106, 'eval_steps_per_second': 4.485, 'epoch': 1.09}\n",
746
+ "{'loss': 4.3912, 'grad_norm': 1.0323781967163086, 'learning_rate': 4.25e-05, 'epoch': 1.17}\n"
747
+ ]
748
+ },
749
+ {
750
+ "data": {
751
+ "application/vnd.jupyter.widget-view+json": {
752
+ "model_id": "12d209218a594953b4abfaf14de05b8b",
753
+ "version_major": 2,
754
+ "version_minor": 0
755
+ },
756
+ "text/plain": [
757
+ " 0%| | 0/129 [00:00<?, ?it/s]"
758
+ ]
759
+ },
760
+ "metadata": {},
761
+ "output_type": "display_data"
762
+ },
763
+ {
764
+ "name": "stderr",
765
+ "output_type": "stream",
766
+ "text": [
767
+ "/Users/andrewmayes/Openclassroom/CanineNet/env/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1509: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
768
+ " _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n"
769
+ ]
770
+ },
771
+ {
772
+ "name": "stdout",
773
+ "output_type": "stream",
774
+ "text": [
775
+ "{'eval_loss': 4.152723789215088, 'eval_accuracy': 0.6873177842565598, 'eval_f1': 0.6863011851876918, 'eval_precision': 0.8261897457310591, 'eval_recall': 0.6702606718880093, 'eval_runtime': 29.7578, 'eval_samples_per_second': 138.317, 'eval_steps_per_second': 4.335, 'epoch': 1.17}\n"
776
+ ]
777
+ }
778
+ ],
779
+ "source": [
780
+ "metrics = {metric: evaluate.load(metric) for metric in METRICS}\n",
781
+ "\n",
782
+ "\n",
783
+ "# for lr in [5e-3, 5e-4, 5e-5]: # 5e-5\n",
784
+ "# for batch in [64]: # 32\n",
785
+ "# for model_name in [\"google/vit-base-patch16-224\", \"microsoft/swinv2-base-patch4-window16-256\", \"google/siglip-base-patch16-224\"]: # \"facebook/dinov2-base\"\n",
786
+ "\n",
787
+ "lr = 5e-4\n",
788
+ "batch = 32\n",
789
+ "model_name = \"microsoft/resnet-50\"\n",
790
+ "\n",
791
+ "image_processor = AutoImageProcessor.from_pretrained(model_name)\n",
792
+ "model = AutoModelForImageClassification.from_pretrained(\n",
793
+ "model_name,\n",
794
+ "num_labels=len(label2int),\n",
795
+ "id2label=int2label,\n",
796
+ "label2id=label2int,\n",
797
+ "ignore_mismatched_sizes=True,\n",
798
+ ")\n",
799
+ "\n",
800
+ "# Then, in your transformations:\n",
801
+ "def train_transform(examples, num_ops=10, magnitude=9, num_magnitude_bins=31):\n",
802
+ "\n",
803
+ " transformation = v2.Compose(\n",
804
+ " [\n",
805
+ " v2.RandAugment(\n",
806
+ " num_ops=num_ops,\n",
807
+ " magnitude=magnitude,\n",
808
+ " num_magnitude_bins=num_magnitude_bins,\n",
809
+ " )\n",
810
+ " ]\n",
811
+ " )\n",
812
+ " # Ensure each image has three dimensions (in this case, ensure it's RGB)\n",
813
+ " examples[\"pixel_values\"] = [\n",
814
+ " image.convert(\"RGB\") for image in examples[\"pixel_values\"]\n",
815
+ " ]\n",
816
+ " # Apply transformations\n",
817
+ " examples[\"pixel_values\"] = [\n",
818
+ " image_processor(transformation(image), return_tensors=\"pt\")[\n",
819
+ " \"pixel_values\"\n",
820
+ " ].squeeze()\n",
821
+ " for image in examples[\"pixel_values\"]\n",
822
+ " ]\n",
823
+ " return examples\n",
824
+ "\n",
825
+ "\n",
826
+ "def test_transform(examples):\n",
827
+ " # Ensure each image is RGB\n",
828
+ " examples[\"pixel_values\"] = [\n",
829
+ " image.convert(\"RGB\") for image in examples[\"pixel_values\"]\n",
830
+ " ]\n",
831
+ " # Apply processing\n",
832
+ " examples[\"pixel_values\"] = [\n",
833
+ " image_processor(image, return_tensors=\"pt\")[\"pixel_values\"].squeeze()\n",
834
+ " for image in examples[\"pixel_values\"]\n",
835
+ " ]\n",
836
+ " return examples\n",
837
+ "\n",
838
+ "\n",
839
+ "def compute_metrics(eval_pred):\n",
840
+ " predictions, labels = eval_pred\n",
841
+ " # predictions = np.argmax(logits, axis=-1)\n",
842
+ " results = {}\n",
843
+ " for key, val in metrics.items():\n",
844
+ " if \"accuracy\" == key:\n",
845
+ " result = next(\n",
846
+ " iter(val.compute(predictions=predictions, references=labels).items())\n",
847
+ " )\n",
848
+ " if \"accuracy\" != key:\n",
849
+ " result = next(\n",
850
+ " iter(\n",
851
+ " val.compute(\n",
852
+ " predictions=predictions, references=labels, average=\"macro\"\n",
853
+ " ).items()\n",
854
+ " )\n",
855
+ " )\n",
856
+ " results[result[0]] = result[1]\n",
857
+ " return results\n",
858
+ "\n",
859
+ "\n",
860
+ "def collate_fn(examples):\n",
861
+ " pixel_values = torch.stack([example[\"pixel_values\"] for example in examples])\n",
862
+ " labels = torch.tensor([example[\"label\"] for example in examples])\n",
863
+ " return {\"pixel_values\": pixel_values, \"labels\": labels}\n",
864
+ "\n",
865
+ "\n",
866
+ "def preprocess_logits_for_metrics(logits, labels):\n",
867
+ " \"\"\"\n",
868
+ " Original Trainer may have a memory leak.\n",
869
+ " This is a workaround to avoid storing too many tensors that are not needed.\n",
870
+ " \"\"\"\n",
871
+ " pred_ids = torch.argmax(logits, dim=-1)\n",
872
+ " return pred_ids\n",
873
+ "\n",
874
+ "ds[\"train\"].set_transform(train_transform)\n",
875
+ "ds[\"test\"].set_transform(test_transform)\n",
876
+ "\n",
877
+ "training_args = TrainingArguments(**CONFIG[\"training_args\"])\n",
878
+ "training_args.per_device_train_batch_size = batch\n",
879
+ "training_args.per_device_eval_batch_size = batch\n",
880
+ "training_args.hub_model_id = f\"amaye15/{model_name.replace('/','-')}-batch{batch}-lr{lr}-standford-dogs\"\n",
881
+ "\n",
882
+ "mlflow.start_run(run_name=f\"{model_name.replace('/','-')}-batch{batch}-lr{lr}\")\n",
883
+ "\n",
884
+ "trainer = Trainer(\n",
885
+ " model=model,\n",
886
+ " args=training_args,\n",
887
+ " train_dataset=ds[\"train\"],\n",
888
+ " eval_dataset=ds[\"test\"],\n",
889
+ " tokenizer=image_processor,\n",
890
+ " data_collator=collate_fn,\n",
891
+ " compute_metrics=compute_metrics,\n",
892
+ " # callbacks=[early_stopping_callback],\n",
893
+ " preprocess_logits_for_metrics=preprocess_logits_for_metrics,\n",
894
+ ")\n",
895
+ "\n",
896
+ "# Train the model\n",
897
+ "trainer.train()\n",
898
+ "\n",
899
+ "trainer.push_to_hub()\n",
900
+ "\n",
901
+ "mlflow.end_run()"
902
+ ]
903
+ }
904
+ ],
905
+ "metadata": {
906
+ "kernelspec": {
907
+ "display_name": "env",
908
+ "language": "python",
909
+ "name": "python3"
910
+ },
911
+ "language_info": {
912
+ "codemirror_mode": {
913
+ "name": "ipython",
914
+ "version": 3
915
+ },
916
+ "file_extension": ".py",
917
+ "mimetype": "text/x-python",
918
+ "name": "python",
919
+ "nbconvert_exporter": "python",
920
+ "pygments_lexer": "ipython3",
921
+ "version": "3.12.3"
922
+ }
923
+ },
924
+ "nbformat": 4,
925
+ "nbformat_minor": 2
926
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:34687c9f8264a2f41d3953440fb5f2f2b6c7f894111aeed6b3a7f30826b01fb2
3
+ size 5112