Upload 3 files
Browse files- best_model.keras +3 -0
- bettermodel.ipynb +236 -0
- dog_breed_classification_training.ipynb +331 -0
best_model.keras
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:04ea03a925b5705497c7a6dcef747055eaf14b3cc786810836150b79a567f6c0
|
3 |
+
size 81816136
|
bettermodel.ipynb
ADDED
@@ -0,0 +1,236 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 8,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"Found 579 images belonging to 5 classes.\n",
|
13 |
+
"Found 124 images belonging to 5 classes.\n",
|
14 |
+
"Found 235 images belonging to 5 classes.\n",
|
15 |
+
"Epoch 1/50\n",
|
16 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m14s\u001b[0m 423ms/step - accuracy: 0.2483 - loss: 2.7352 - val_accuracy: 0.2339 - val_loss: 2.1511\n",
|
17 |
+
"Epoch 2/50\n",
|
18 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 370ms/step - accuracy: 0.2506 - loss: 2.0916 - val_accuracy: 0.2339 - val_loss: 1.9442\n",
|
19 |
+
"Epoch 3/50\n",
|
20 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m10s\u001b[0m 397ms/step - accuracy: 0.2298 - loss: 1.9145 - val_accuracy: 0.2339 - val_loss: 1.8353\n",
|
21 |
+
"Epoch 4/50\n",
|
22 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 374ms/step - accuracy: 0.2367 - loss: 1.8245 - val_accuracy: 0.2339 - val_loss: 1.7828\n",
|
23 |
+
"Epoch 5/50\n",
|
24 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m10s\u001b[0m 373ms/step - accuracy: 0.2411 - loss: 1.7718 - val_accuracy: 0.2339 - val_loss: 1.7444\n",
|
25 |
+
"Epoch 6/50\n",
|
26 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 369ms/step - accuracy: 0.1975 - loss: 1.7408 - val_accuracy: 0.2339 - val_loss: 1.7163\n",
|
27 |
+
"Epoch 7/50\n",
|
28 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 387ms/step - accuracy: 0.2479 - loss: 1.7097 - val_accuracy: 0.2339 - val_loss: 1.6960\n",
|
29 |
+
"Epoch 8/50\n",
|
30 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 360ms/step - accuracy: 0.2480 - loss: 1.6955 - val_accuracy: 0.2339 - val_loss: 1.6844\n",
|
31 |
+
"Epoch 9/50\n",
|
32 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 381ms/step - accuracy: 0.2417 - loss: 1.6826 - val_accuracy: 0.2339 - val_loss: 1.6750\n",
|
33 |
+
"Epoch 10/50\n",
|
34 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m10s\u001b[0m 415ms/step - accuracy: 0.2540 - loss: 1.6696 - val_accuracy: 0.2339 - val_loss: 1.6658\n",
|
35 |
+
"Epoch 11/50\n",
|
36 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 377ms/step - accuracy: 0.2436 - loss: 1.6617 - val_accuracy: 0.2339 - val_loss: 1.6583\n",
|
37 |
+
"Epoch 12/50\n",
|
38 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 367ms/step - accuracy: 0.2333 - loss: 1.6566 - val_accuracy: 0.2339 - val_loss: 1.6490\n",
|
39 |
+
"Epoch 13/50\n",
|
40 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 363ms/step - accuracy: 0.2229 - loss: 1.6558 - val_accuracy: 0.2339 - val_loss: 1.6456\n",
|
41 |
+
"Epoch 14/50\n",
|
42 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 359ms/step - accuracy: 0.2277 - loss: 1.6478 - val_accuracy: 0.2339 - val_loss: 1.6423\n",
|
43 |
+
"Epoch 15/50\n",
|
44 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 354ms/step - accuracy: 0.2638 - loss: 1.6418 - val_accuracy: 0.2339 - val_loss: 1.6430\n",
|
45 |
+
"Epoch 16/50\n",
|
46 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 374ms/step - accuracy: 0.2305 - loss: 1.6422 - val_accuracy: 0.2339 - val_loss: 1.6400\n",
|
47 |
+
"Epoch 17/50\n",
|
48 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 382ms/step - accuracy: 0.2539 - loss: 1.6356 - val_accuracy: 0.2339 - val_loss: 1.6367\n",
|
49 |
+
"Epoch 18/50\n",
|
50 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 391ms/step - accuracy: 0.2547 - loss: 1.6336 - val_accuracy: 0.2339 - val_loss: 1.6331\n",
|
51 |
+
"Epoch 19/50\n",
|
52 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 366ms/step - accuracy: 0.2326 - loss: 1.6322 - val_accuracy: 0.2339 - val_loss: 1.6280\n",
|
53 |
+
"Epoch 20/50\n",
|
54 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 365ms/step - accuracy: 0.2219 - loss: 1.6340 - val_accuracy: 0.2339 - val_loss: 1.6312\n",
|
55 |
+
"Epoch 21/50\n",
|
56 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 351ms/step - accuracy: 0.2411 - loss: 1.6299 - val_accuracy: 0.2339 - val_loss: 1.6290\n",
|
57 |
+
"Epoch 22/50\n",
|
58 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 356ms/step - accuracy: 0.2371 - loss: 1.6308 - val_accuracy: 0.2339 - val_loss: 1.6272\n",
|
59 |
+
"Epoch 23/50\n",
|
60 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 359ms/step - accuracy: 0.2460 - loss: 1.6243 - val_accuracy: 0.2339 - val_loss: 1.6255\n",
|
61 |
+
"Epoch 24/50\n",
|
62 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 365ms/step - accuracy: 0.2181 - loss: 1.6281 - val_accuracy: 0.2339 - val_loss: 1.6240\n",
|
63 |
+
"Epoch 25/50\n",
|
64 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 364ms/step - accuracy: 0.2336 - loss: 1.6254 - val_accuracy: 0.2339 - val_loss: 1.6226\n",
|
65 |
+
"Epoch 26/50\n",
|
66 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 360ms/step - accuracy: 0.2102 - loss: 1.6278 - val_accuracy: 0.2339 - val_loss: 1.6217\n",
|
67 |
+
"Epoch 27/50\n",
|
68 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 359ms/step - accuracy: 0.2553 - loss: 1.6174 - val_accuracy: 0.2339 - val_loss: 1.6204\n",
|
69 |
+
"Epoch 28/50\n",
|
70 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 366ms/step - accuracy: 0.2452 - loss: 1.6189 - val_accuracy: 0.2339 - val_loss: 1.6191\n",
|
71 |
+
"Epoch 29/50\n",
|
72 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 360ms/step - accuracy: 0.2409 - loss: 1.6163 - val_accuracy: 0.2339 - val_loss: 1.6163\n",
|
73 |
+
"Epoch 30/50\n",
|
74 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 388ms/step - accuracy: 0.2268 - loss: 1.6160 - val_accuracy: 0.2339 - val_loss: 1.6186\n",
|
75 |
+
"Epoch 31/50\n",
|
76 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 393ms/step - accuracy: 0.2233 - loss: 1.6230 - val_accuracy: 0.2339 - val_loss: 1.6179\n",
|
77 |
+
"Epoch 32/50\n",
|
78 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 359ms/step - accuracy: 0.2562 - loss: 1.6140 - val_accuracy: 0.2339 - val_loss: 1.6170\n",
|
79 |
+
"Epoch 33/50\n",
|
80 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 360ms/step - accuracy: 0.2387 - loss: 1.6158 - val_accuracy: 0.2339 - val_loss: 1.6163\n",
|
81 |
+
"Epoch 34/50\n",
|
82 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 352ms/step - accuracy: 0.2353 - loss: 1.6159 - val_accuracy: 0.2339 - val_loss: 1.6155\n",
|
83 |
+
"Epoch 35/50\n",
|
84 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 367ms/step - accuracy: 0.2491 - loss: 1.6107 - val_accuracy: 0.2339 - val_loss: 1.6145\n",
|
85 |
+
"Epoch 36/50\n",
|
86 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 347ms/step - accuracy: 0.2277 - loss: 1.6167 - val_accuracy: 0.2339 - val_loss: 1.6142\n",
|
87 |
+
"Epoch 37/50\n",
|
88 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 361ms/step - accuracy: 0.2633 - loss: 1.6109 - val_accuracy: 0.2339 - val_loss: 1.6143\n",
|
89 |
+
"Epoch 38/50\n",
|
90 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 355ms/step - accuracy: 0.2541 - loss: 1.6108 - val_accuracy: 0.2339 - val_loss: 1.6136\n",
|
91 |
+
"Epoch 39/50\n",
|
92 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 349ms/step - accuracy: 0.2679 - loss: 1.6037 - val_accuracy: 0.2339 - val_loss: 1.6120\n",
|
93 |
+
"Epoch 40/50\n",
|
94 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 362ms/step - accuracy: 0.2324 - loss: 1.6133 - val_accuracy: 0.2339 - val_loss: 1.6077\n",
|
95 |
+
"Epoch 41/50\n",
|
96 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 357ms/step - accuracy: 0.2440 - loss: 1.6085 - val_accuracy: 0.2339 - val_loss: 1.6138\n",
|
97 |
+
"Epoch 42/50\n",
|
98 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 380ms/step - accuracy: 0.2423 - loss: 1.6108 - val_accuracy: 0.2339 - val_loss: 1.6136\n",
|
99 |
+
"Epoch 43/50\n",
|
100 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 354ms/step - accuracy: 0.2276 - loss: 1.6149 - val_accuracy: 0.2339 - val_loss: 1.6136\n",
|
101 |
+
"Epoch 44/50\n",
|
102 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 357ms/step - accuracy: 0.2335 - loss: 1.6132 - val_accuracy: 0.2339 - val_loss: 1.6128\n",
|
103 |
+
"Epoch 45/50\n",
|
104 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 356ms/step - accuracy: 0.2477 - loss: 1.6109 - val_accuracy: 0.2339 - val_loss: 1.6119\n",
|
105 |
+
"\u001b[1m8/8\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 89ms/step - accuracy: 0.1173 - loss: 1.6083\n",
|
106 |
+
"Test loss: 1.607354760169983\n",
|
107 |
+
"Test accuracy: 0.12340425699949265\n"
|
108 |
+
]
|
109 |
+
}
|
110 |
+
],
|
111 |
+
"source": [
|
112 |
+
"import numpy as np\n",
|
113 |
+
"import tensorflow as tf\n",
|
114 |
+
"from tensorflow.keras.preprocessing.image import ImageDataGenerator\n",
|
115 |
+
"from tensorflow.keras.models import Sequential\n",
|
116 |
+
"from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout\n",
|
117 |
+
"from tensorflow.keras.regularizers import l2\n",
|
118 |
+
"from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint\n",
|
119 |
+
"\n",
|
120 |
+
"# Definiere die GrΓΆΓe der Bilder und den Pfad zum Datensatz\n",
|
121 |
+
"img_size = (150, 150)\n",
|
122 |
+
"data_dir = r'C:\\kiamep'\n",
|
123 |
+
"\n",
|
124 |
+
"# Erstelle Datengeneratoren fΓΌr Training, Validierung und Test mit DatenvergrΓΆΓerung\n",
|
125 |
+
"train_datagen = ImageDataGenerator(\n",
|
126 |
+
" rescale=1./255,\n",
|
127 |
+
" rotation_range=40,\n",
|
128 |
+
" width_shift_range=0.2,\n",
|
129 |
+
" height_shift_range=0.2,\n",
|
130 |
+
" shear_range=0.2,\n",
|
131 |
+
" zoom_range=0.2,\n",
|
132 |
+
" horizontal_flip=True,\n",
|
133 |
+
" fill_mode='nearest',\n",
|
134 |
+
" vertical_flip=True, # Vertikale Spiegelung hinzugefΓΌgt\n",
|
135 |
+
" brightness_range=[0.8, 1.2], # Helligkeitsanpassung hinzugefΓΌgt\n",
|
136 |
+
" \n",
|
137 |
+
"\n",
|
138 |
+
")\n",
|
139 |
+
"\n",
|
140 |
+
"train_generator = train_datagen.flow_from_directory(\n",
|
141 |
+
" data_dir + '\\\\Trainingsdaten',\n",
|
142 |
+
" target_size=img_size,\n",
|
143 |
+
" batch_size=32,\n",
|
144 |
+
" class_mode='categorical'\n",
|
145 |
+
")\n",
|
146 |
+
"\n",
|
147 |
+
"validation_datagen = ImageDataGenerator(rescale=1./255)\n",
|
148 |
+
"\n",
|
149 |
+
"validation_generator = validation_datagen.flow_from_directory(\n",
|
150 |
+
" data_dir + '\\\\Validierungsdaten',\n",
|
151 |
+
" target_size=img_size,\n",
|
152 |
+
" batch_size=32,\n",
|
153 |
+
" class_mode='categorical'\n",
|
154 |
+
")\n",
|
155 |
+
"\n",
|
156 |
+
"test_datagen = ImageDataGenerator(rescale=1./255)\n",
|
157 |
+
"\n",
|
158 |
+
"test_generator = test_datagen.flow_from_directory(\n",
|
159 |
+
" data_dir + '\\\\Testdaten',\n",
|
160 |
+
" target_size=img_size,\n",
|
161 |
+
" batch_size=32,\n",
|
162 |
+
" class_mode='categorical'\n",
|
163 |
+
")\n",
|
164 |
+
"\n",
|
165 |
+
"# Definiere das verbesserte CNN-Modell\n",
|
166 |
+
"# Regularisierung gegen overfiting (Gwicht)\n",
|
167 |
+
"# Dropout auch gegen overfiting (Neuronen Drop)\n",
|
168 |
+
"# Mehr Neuronen 512\n",
|
169 |
+
"model = Sequential([\n",
|
170 |
+
" Conv2D(32, (3, 3), activation='relu', kernel_regularizer=l2(0.001), input_shape=(img_size[0], img_size[1], 3)),\n",
|
171 |
+
" MaxPooling2D(pool_size=(2, 2)),\n",
|
172 |
+
" \n",
|
173 |
+
" Conv2D(64, (3, 3), activation='relu', kernel_regularizer=l2(0.001)),\n",
|
174 |
+
" MaxPooling2D(pool_size=(2, 2)),\n",
|
175 |
+
" \n",
|
176 |
+
" Conv2D(128, (3, 3), activation='relu', kernel_regularizer=l2(0.001)),\n",
|
177 |
+
" MaxPooling2D(pool_size=(2, 2)),\n",
|
178 |
+
" \n",
|
179 |
+
" Conv2D(256, (3, 3), activation='relu', kernel_regularizer=l2(0.001)),\n",
|
180 |
+
" MaxPooling2D(pool_size=(2, 2)),\n",
|
181 |
+
" \n",
|
182 |
+
" Flatten(),\n",
|
183 |
+
" Dense(512, activation='relu', kernel_regularizer=l2(0.001)),\n",
|
184 |
+
" Dropout(0.5),\n",
|
185 |
+
" Dense(5, activation='softmax')\n",
|
186 |
+
"])\n",
|
187 |
+
"\n",
|
188 |
+
"# Kompiliere das Modell\n",
|
189 |
+
"model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])\n",
|
190 |
+
"\n",
|
191 |
+
"# Definiere Callbacks\n",
|
192 |
+
"# Auch gegen Overfiting early stop \n",
|
193 |
+
"early_stopping = EarlyStopping(monitor='val_loss', patience=5, restore_best_weights=True)\n",
|
194 |
+
"model_checkpoint = ModelCheckpoint('best_model.keras', monitor='val_accuracy', save_best_only=True)\n",
|
195 |
+
"\n",
|
196 |
+
"# Trainiere das Modell\n",
|
197 |
+
"# mehr epochen\n",
|
198 |
+
"history = model.fit(\n",
|
199 |
+
" train_generator,\n",
|
200 |
+
" epochs=50,\n",
|
201 |
+
" validation_data=validation_generator,\n",
|
202 |
+
" callbacks=[early_stopping, model_checkpoint]\n",
|
203 |
+
")\n",
|
204 |
+
"\n",
|
205 |
+
"# Evaluiere das Modell auf den Testdaten\n",
|
206 |
+
"test_loss, test_accuracy = model.evaluate(test_generator)\n",
|
207 |
+
"print(\"Test loss:\", test_loss)\n",
|
208 |
+
"print(\"Test accuracy:\", test_accuracy)\n",
|
209 |
+
"\n",
|
210 |
+
"# Speichere das beste Modell im Keras-Format\n",
|
211 |
+
"model.save('best_model.keras')"
|
212 |
+
]
|
213 |
+
}
|
214 |
+
],
|
215 |
+
"metadata": {
|
216 |
+
"kernelspec": {
|
217 |
+
"display_name": "kia",
|
218 |
+
"language": "python",
|
219 |
+
"name": "python3"
|
220 |
+
},
|
221 |
+
"language_info": {
|
222 |
+
"codemirror_mode": {
|
223 |
+
"name": "ipython",
|
224 |
+
"version": 3
|
225 |
+
},
|
226 |
+
"file_extension": ".py",
|
227 |
+
"mimetype": "text/x-python",
|
228 |
+
"name": "python",
|
229 |
+
"nbconvert_exporter": "python",
|
230 |
+
"pygments_lexer": "ipython3",
|
231 |
+
"version": "3.12.2"
|
232 |
+
}
|
233 |
+
},
|
234 |
+
"nbformat": 4,
|
235 |
+
"nbformat_minor": 2
|
236 |
+
}
|
dog_breed_classification_training.ipynb
ADDED
@@ -0,0 +1,331 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 3,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"Found 579 images belonging to 5 classes.\n",
|
13 |
+
"Found 124 images belonging to 5 classes.\n",
|
14 |
+
"Found 235 images belonging to 5 classes.\n"
|
15 |
+
]
|
16 |
+
},
|
17 |
+
{
|
18 |
+
"name": "stderr",
|
19 |
+
"output_type": "stream",
|
20 |
+
"text": [
|
21 |
+
"c:\\Users\\papic\\anaconda3\\envs\\kia\\Lib\\site-packages\\keras\\src\\layers\\convolutional\\base_conv.py:99: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.\n",
|
22 |
+
" super().__init__(\n"
|
23 |
+
]
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"name": "stdout",
|
27 |
+
"output_type": "stream",
|
28 |
+
"text": [
|
29 |
+
"Epoch 1/10\n"
|
30 |
+
]
|
31 |
+
},
|
32 |
+
{
|
33 |
+
"name": "stderr",
|
34 |
+
"output_type": "stream",
|
35 |
+
"text": [
|
36 |
+
"c:\\Users\\papic\\anaconda3\\envs\\kia\\Lib\\site-packages\\keras\\src\\trainers\\data_adapters\\py_dataset_adapter.py:120: UserWarning: Your `PyDataset` class should call `super().__init__(**kwargs)` in its constructor. `**kwargs` can include `workers`, `use_multiprocessing`, `max_queue_size`. Do not pass these arguments to `fit()`, as they will be ignored.\n",
|
37 |
+
" self._warn_if_super_not_called()\n"
|
38 |
+
]
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"name": "stdout",
|
42 |
+
"output_type": "stream",
|
43 |
+
"text": [
|
44 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m11s\u001b[0m 319ms/step - accuracy: 0.2299 - loss: 2.0734 - val_accuracy: 0.2823 - val_loss: 1.6074\n",
|
45 |
+
"Epoch 2/10\n",
|
46 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 309ms/step - accuracy: 0.2566 - loss: 1.6081 - val_accuracy: 0.1774 - val_loss: 1.6082\n",
|
47 |
+
"Epoch 3/10\n",
|
48 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 339ms/step - accuracy: 0.1996 - loss: 1.6083 - val_accuracy: 0.2903 - val_loss: 1.5758\n",
|
49 |
+
"Epoch 4/10\n",
|
50 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 309ms/step - accuracy: 0.2638 - loss: 1.5865 - val_accuracy: 0.2984 - val_loss: 1.5241\n",
|
51 |
+
"Epoch 5/10\n",
|
52 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 299ms/step - accuracy: 0.2650 - loss: 1.5385 - val_accuracy: 0.4435 - val_loss: 1.4655\n",
|
53 |
+
"Epoch 6/10\n",
|
54 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 302ms/step - accuracy: 0.3636 - loss: 1.4539 - val_accuracy: 0.4274 - val_loss: 1.4295\n",
|
55 |
+
"Epoch 7/10\n",
|
56 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 286ms/step - accuracy: 0.3446 - loss: 1.4875 - val_accuracy: 0.4274 - val_loss: 1.3986\n",
|
57 |
+
"Epoch 8/10\n",
|
58 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 284ms/step - accuracy: 0.3989 - loss: 1.4304 - val_accuracy: 0.3710 - val_loss: 1.4821\n",
|
59 |
+
"Epoch 9/10\n",
|
60 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 280ms/step - accuracy: 0.3640 - loss: 1.4761 - val_accuracy: 0.4032 - val_loss: 1.4074\n",
|
61 |
+
"Epoch 10/10\n",
|
62 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 282ms/step - accuracy: 0.3923 - loss: 1.4042 - val_accuracy: 0.3710 - val_loss: 1.4259\n",
|
63 |
+
"\u001b[1m8/8\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 93ms/step - accuracy: 0.2815 - loss: 1.5283 \n",
|
64 |
+
"Test loss: 1.5475623607635498\n",
|
65 |
+
"Test accuracy: 0.2851063907146454\n"
|
66 |
+
]
|
67 |
+
}
|
68 |
+
],
|
69 |
+
"source": [
|
70 |
+
"import numpy as np\n",
|
71 |
+
"import tensorflow as tf\n",
|
72 |
+
"from tensorflow.keras.preprocessing.image import ImageDataGenerator\n",
|
73 |
+
"from tensorflow.keras.models import Sequential\n",
|
74 |
+
"from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense\n",
|
75 |
+
"\n",
|
76 |
+
"# Definiere die GrΓΆΓe der Bilder und den Pfad zum Datensatz\n",
|
77 |
+
"img_size = (150, 150)\n",
|
78 |
+
"data_dir = r'C:\\kiamep'\n",
|
79 |
+
"\n",
|
80 |
+
"# Erstelle Datengeneratoren fΓΌr Training mit DatenvergrΓΆΓerung\n",
|
81 |
+
"train_datagen_augmented = ImageDataGenerator(\n",
|
82 |
+
" rescale=1./255,\n",
|
83 |
+
" shear_range=0.2,\n",
|
84 |
+
" zoom_range=0.2,\n",
|
85 |
+
" horizontal_flip=True,\n",
|
86 |
+
" rotation_range=40,\n",
|
87 |
+
" width_shift_range=0.2,\n",
|
88 |
+
" height_shift_range=0.2,\n",
|
89 |
+
" \n",
|
90 |
+
")\n",
|
91 |
+
"\n",
|
92 |
+
"# Erstelle Datengeneratoren fΓΌr Validierung und Test ohne DatenvergrΓΆΓerung\n",
|
93 |
+
"validation_datagen = ImageDataGenerator(rescale=1./255)\n",
|
94 |
+
"test_datagen = ImageDataGenerator(rescale=1./255)\n",
|
95 |
+
"\n",
|
96 |
+
"train_generator_augmented = train_datagen_augmented.flow_from_directory(\n",
|
97 |
+
" data_dir + '\\\\Trainingsdaten',\n",
|
98 |
+
" target_size=img_size,\n",
|
99 |
+
" batch_size=32,\n",
|
100 |
+
" class_mode='categorical',\n",
|
101 |
+
")\n",
|
102 |
+
"\n",
|
103 |
+
"validation_generator = validation_datagen.flow_from_directory(\n",
|
104 |
+
" data_dir + '\\\\Validierungsdaten',\n",
|
105 |
+
" target_size=img_size,\n",
|
106 |
+
" batch_size=32,\n",
|
107 |
+
" class_mode='categorical',\n",
|
108 |
+
")\n",
|
109 |
+
"\n",
|
110 |
+
"test_generator = test_datagen.flow_from_directory(\n",
|
111 |
+
" data_dir + '\\\\Testdaten',\n",
|
112 |
+
" target_size=img_size,\n",
|
113 |
+
" batch_size=32,\n",
|
114 |
+
" class_mode='categorical',\n",
|
115 |
+
")\n",
|
116 |
+
"\n",
|
117 |
+
"# Definiere das CNN-Modell\n",
|
118 |
+
"model = Sequential([\n",
|
119 |
+
" Conv2D(32, (3, 3), activation='relu', input_shape=(img_size[0], img_size[1], 3)),\n",
|
120 |
+
" MaxPooling2D(pool_size=(2, 2)),\n",
|
121 |
+
" \n",
|
122 |
+
" Conv2D(64, (3, 3), activation='relu'),\n",
|
123 |
+
" MaxPooling2D(pool_size=(2, 2)),\n",
|
124 |
+
" \n",
|
125 |
+
" Conv2D(128, (3, 3), activation='relu'),\n",
|
126 |
+
" MaxPooling2D(pool_size=(2, 2)),\n",
|
127 |
+
" \n",
|
128 |
+
" Flatten(),\n",
|
129 |
+
" Dense(128, activation='relu'),\n",
|
130 |
+
" Dense(5, activation='softmax') # Annahme: 5 verschiedene Hunderassen\n",
|
131 |
+
"])\n",
|
132 |
+
"\n",
|
133 |
+
"# Kompiliere das Modell\n",
|
134 |
+
"model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])\n",
|
135 |
+
"\n",
|
136 |
+
"# Trainiere das Modell mit den Trainingsdaten und validiere es mit den Validierungsdaten\n",
|
137 |
+
"model.fit(train_generator_augmented, epochs=10, validation_data=validation_generator)\n",
|
138 |
+
"\n",
|
139 |
+
"# Bewerte das Modell mit den Testdaten\n",
|
140 |
+
"test_loss, test_accuracy = model.evaluate(test_generator)\n",
|
141 |
+
"print(\"Test loss:\", test_loss)\n",
|
142 |
+
"print(\"Test accuracy:\", test_accuracy)\n",
|
143 |
+
"\n",
|
144 |
+
"\n"
|
145 |
+
]
|
146 |
+
},
|
147 |
+
{
|
148 |
+
"cell_type": "code",
|
149 |
+
"execution_count": 4,
|
150 |
+
"metadata": {},
|
151 |
+
"outputs": [
|
152 |
+
{
|
153 |
+
"name": "stdout",
|
154 |
+
"output_type": "stream",
|
155 |
+
"text": [
|
156 |
+
"Found 579 images belonging to 5 classes.\n",
|
157 |
+
"Found 124 images belonging to 5 classes.\n",
|
158 |
+
"Found 235 images belonging to 5 classes.\n",
|
159 |
+
"Epoch 1/10\n",
|
160 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m74s\u001b[0m 3s/step - accuracy: 0.2039 - loss: 2.5350 - val_accuracy: 0.2097 - val_loss: 1.6096\n",
|
161 |
+
"Epoch 2/10\n",
|
162 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m69s\u001b[0m 4s/step - accuracy: 0.1875 - loss: 1.6273 - val_accuracy: 0.2097 - val_loss: 1.6332\n",
|
163 |
+
"Epoch 3/10\n",
|
164 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m70s\u001b[0m 4s/step - accuracy: 0.2389 - loss: 1.6126 - val_accuracy: 0.2339 - val_loss: 1.6050\n",
|
165 |
+
"Epoch 4/10\n",
|
166 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m67s\u001b[0m 3s/step - accuracy: 0.2433 - loss: 1.6050 - val_accuracy: 0.2339 - val_loss: 1.6064\n",
|
167 |
+
"Epoch 5/10\n",
|
168 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m65s\u001b[0m 3s/step - accuracy: 0.2169 - loss: 1.6130 - val_accuracy: 0.2339 - val_loss: 1.6071\n",
|
169 |
+
"Epoch 6/10\n",
|
170 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m64s\u001b[0m 3s/step - accuracy: 0.2531 - loss: 1.6066 - val_accuracy: 0.2339 - val_loss: 1.6066\n",
|
171 |
+
"Epoch 7/10\n",
|
172 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m65s\u001b[0m 3s/step - accuracy: 0.2488 - loss: 1.6057 - val_accuracy: 0.2339 - val_loss: 1.6055\n",
|
173 |
+
"Epoch 8/10\n",
|
174 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m64s\u001b[0m 3s/step - accuracy: 0.2469 - loss: 1.6042 - val_accuracy: 0.2339 - val_loss: 1.6046\n",
|
175 |
+
"Epoch 9/10\n",
|
176 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m65s\u001b[0m 3s/step - accuracy: 0.2664 - loss: 1.6031 - val_accuracy: 0.2339 - val_loss: 1.6029\n",
|
177 |
+
"Epoch 10/10\n",
|
178 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m64s\u001b[0m 3s/step - accuracy: 0.2423 - loss: 1.6020 - val_accuracy: 0.2339 - val_loss: 1.6027\n",
|
179 |
+
"\u001b[1m8/8\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 724ms/step - accuracy: 0.1127 - loss: 1.6211\n",
|
180 |
+
"Test loss: 1.6218193769454956\n",
|
181 |
+
"Test accuracy: 0.12340425699949265\n",
|
182 |
+
"Epoch 1/10\n",
|
183 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m102s\u001b[0m 2s/step - accuracy: 0.3654 - loss: 1.9313 - val_accuracy: 0.2097 - val_loss: 154.1117\n",
|
184 |
+
"Epoch 2/10\n",
|
185 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m35s\u001b[0m 2s/step - accuracy: 0.4419 - loss: 1.4328 - val_accuracy: 0.2097 - val_loss: 1264.2780\n",
|
186 |
+
"Epoch 3/10\n",
|
187 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m34s\u001b[0m 2s/step - accuracy: 0.5456 - loss: 1.2366 - val_accuracy: 0.1774 - val_loss: 305.5775\n",
|
188 |
+
"Epoch 4/10\n",
|
189 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m35s\u001b[0m 2s/step - accuracy: 0.4869 - loss: 1.2390 - val_accuracy: 0.2339 - val_loss: 58.4713\n",
|
190 |
+
"Epoch 5/10\n",
|
191 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m35s\u001b[0m 2s/step - accuracy: 0.5579 - loss: 1.1611 - val_accuracy: 0.1855 - val_loss: 5.8782\n",
|
192 |
+
"Epoch 6/10\n",
|
193 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m36s\u001b[0m 2s/step - accuracy: 0.6491 - loss: 0.9665 - val_accuracy: 0.1774 - val_loss: 2.1772\n",
|
194 |
+
"Epoch 7/10\n",
|
195 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m34s\u001b[0m 2s/step - accuracy: 0.6568 - loss: 0.9378 - val_accuracy: 0.2097 - val_loss: 3.0409\n",
|
196 |
+
"Epoch 8/10\n",
|
197 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m34s\u001b[0m 2s/step - accuracy: 0.6401 - loss: 0.9623 - val_accuracy: 0.1774 - val_loss: 5.2191\n",
|
198 |
+
"Epoch 9/10\n",
|
199 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m35s\u001b[0m 2s/step - accuracy: 0.6719 - loss: 0.9113 - val_accuracy: 0.1774 - val_loss: 9.8093\n",
|
200 |
+
"Epoch 10/10\n",
|
201 |
+
"\u001b[1m19/19\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m34s\u001b[0m 2s/step - accuracy: 0.6057 - loss: 1.0410 - val_accuracy: 0.1774 - val_loss: 22.0870\n",
|
202 |
+
"\u001b[1m8/8\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m3s\u001b[0m 365ms/step - accuracy: 0.0961 - loss: 23.2958\n",
|
203 |
+
"Test loss: 23.437267303466797\n",
|
204 |
+
"Test accuracy: 0.0936170220375061\n"
|
205 |
+
]
|
206 |
+
}
|
207 |
+
],
|
208 |
+
"source": [
|
209 |
+
"import numpy as np\n",
|
210 |
+
"import tensorflow as tf\n",
|
211 |
+
"from tensorflow.keras.preprocessing.image import ImageDataGenerator\n",
|
212 |
+
"from tensorflow.keras.applications import VGG16, ResNet50\n",
|
213 |
+
"from tensorflow.keras.models import Sequential\n",
|
214 |
+
"from tensorflow.keras.layers import Dense, GlobalAveragePooling2D\n",
|
215 |
+
"\n",
|
216 |
+
"\n",
|
217 |
+
"# Definiere die GrΓΆΓe der Bilder und den Pfad zum Datensatz\n",
|
218 |
+
"img_size = (150, 150)\n",
|
219 |
+
"data_dir = r'C:\\kiamep'\n",
|
220 |
+
"\n",
|
221 |
+
"# Erstelle Datengeneratoren fΓΌr Training mit DatenvergrΓΆΓerung\n",
|
222 |
+
"train_datagen_augmented = ImageDataGenerator(\n",
|
223 |
+
" rescale=1./255,\n",
|
224 |
+
" shear_range=0.2,\n",
|
225 |
+
" zoom_range=0.2,\n",
|
226 |
+
" horizontal_flip=True,\n",
|
227 |
+
" rotation_range=40,\n",
|
228 |
+
" width_shift_range=0.2,\n",
|
229 |
+
" height_shift_range=0.2,\n",
|
230 |
+
")\n",
|
231 |
+
"\n",
|
232 |
+
"# Erstelle Datengeneratoren fΓΌr Validierung und Test ohne DatenvergrΓΆΓerung\n",
|
233 |
+
"validation_datagen = ImageDataGenerator(rescale=1./255)\n",
|
234 |
+
"test_datagen = ImageDataGenerator(rescale=1./255)\n",
|
235 |
+
"\n",
|
236 |
+
"train_generator_augmented = train_datagen_augmented.flow_from_directory(\n",
|
237 |
+
" data_dir + '\\\\Trainingsdaten',\n",
|
238 |
+
" target_size=img_size,\n",
|
239 |
+
" batch_size=32,\n",
|
240 |
+
" class_mode='categorical',\n",
|
241 |
+
")\n",
|
242 |
+
"\n",
|
243 |
+
"validation_generator = validation_datagen.flow_from_directory(\n",
|
244 |
+
" data_dir + '\\\\Validierungsdaten',\n",
|
245 |
+
" target_size=img_size,\n",
|
246 |
+
" batch_size=32,\n",
|
247 |
+
" class_mode='categorical',\n",
|
248 |
+
")\n",
|
249 |
+
"\n",
|
250 |
+
"test_generator = test_datagen.flow_from_directory(\n",
|
251 |
+
" data_dir + '\\\\Testdaten',\n",
|
252 |
+
" target_size=img_size,\n",
|
253 |
+
" batch_size=32,\n",
|
254 |
+
" class_mode='categorical',\n",
|
255 |
+
")\n",
|
256 |
+
"\n",
|
257 |
+
"# VGG16-Modell laden\n",
|
258 |
+
"base_model_vgg16 = VGG16(weights='imagenet', include_top=False, input_shape=(img_size[0], img_size[1], 3))\n",
|
259 |
+
"\n",
|
260 |
+
"# FΓΌge eigene Klassifizierungsschicht hinzu\n",
|
261 |
+
"model_vgg16 = Sequential([\n",
|
262 |
+
" base_model_vgg16,\n",
|
263 |
+
" GlobalAveragePooling2D(),\n",
|
264 |
+
" Dense(256, activation='relu'),\n",
|
265 |
+
" Dense(5, activation='softmax') # Annahme: 5 verschiedene Hunderassen\n",
|
266 |
+
"])\n",
|
267 |
+
"\n",
|
268 |
+
"# Kompiliere das Modell\n",
|
269 |
+
"model_vgg16.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])\n",
|
270 |
+
"\n",
|
271 |
+
"# Trainiere das Modell\n",
|
272 |
+
"model_vgg16.fit(train_generator_augmented, epochs=10, validation_data=validation_generator)\n",
|
273 |
+
"\n",
|
274 |
+
"# Bewerte das Modell mit den Testdaten\n",
|
275 |
+
"test_loss, test_accuracy = model_vgg16.evaluate(test_generator)\n",
|
276 |
+
"print(\"Test loss:\", test_loss)\n",
|
277 |
+
"print(\"Test accuracy:\", test_accuracy)\n",
|
278 |
+
"\n",
|
279 |
+
"\n",
|
280 |
+
"\n",
|
281 |
+
"\n",
|
282 |
+
"\n",
|
283 |
+
"\n",
|
284 |
+
"\n",
|
285 |
+
"\n",
|
286 |
+
"# ResNet50-Modell laden\n",
|
287 |
+
"base_model_resnet50 = ResNet50(weights='imagenet', include_top=False, input_shape=(img_size[0], img_size[1], 3))\n",
|
288 |
+
"\n",
|
289 |
+
"# FΓΌge eigene Klassifizierungsschicht hinzu\n",
|
290 |
+
"model_resnet50 = Sequential([\n",
|
291 |
+
" base_model_resnet50,\n",
|
292 |
+
" GlobalAveragePooling2D(),\n",
|
293 |
+
" Dense(256, activation='relu'),\n",
|
294 |
+
" Dense(5, activation='softmax') # Annahme: 5 verschiedene Hunderassen\n",
|
295 |
+
"])\n",
|
296 |
+
"\n",
|
297 |
+
"# Kompiliere das Modell\n",
|
298 |
+
"model_resnet50.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])\n",
|
299 |
+
"\n",
|
300 |
+
"# Trainiere das Modell\n",
|
301 |
+
"model_resnet50.fit(train_generator_augmented, epochs=10, validation_data=validation_generator)\n",
|
302 |
+
"\n",
|
303 |
+
"# Bewerte das Modell mit den Testdaten\n",
|
304 |
+
"test_loss, test_accuracy = model_resnet50.evaluate(test_generator)\n",
|
305 |
+
"print(\"Test loss:\", test_loss)\n",
|
306 |
+
"print(\"Test accuracy:\", test_accuracy)"
|
307 |
+
]
|
308 |
+
}
|
309 |
+
],
|
310 |
+
"metadata": {
|
311 |
+
"kernelspec": {
|
312 |
+
"display_name": "kia",
|
313 |
+
"language": "python",
|
314 |
+
"name": "python3"
|
315 |
+
},
|
316 |
+
"language_info": {
|
317 |
+
"codemirror_mode": {
|
318 |
+
"name": "ipython",
|
319 |
+
"version": 3
|
320 |
+
},
|
321 |
+
"file_extension": ".py",
|
322 |
+
"mimetype": "text/x-python",
|
323 |
+
"name": "python",
|
324 |
+
"nbconvert_exporter": "python",
|
325 |
+
"pygments_lexer": "ipython3",
|
326 |
+
"version": "3.12.2"
|
327 |
+
}
|
328 |
+
},
|
329 |
+
"nbformat": 4,
|
330 |
+
"nbformat_minor": 2
|
331 |
+
}
|