質問編集履歴
1
Pythonコードと出力されたグラフ等を追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -25,3 +25,135 @@
|
|
25
25
|
|
26
26
|
|
27
27
|
謎すぎてよろしくお願いします。
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
------------------------------------------------------------
|
32
|
+
|
33
|
+
言葉足らずですいません。追記させていただきます。
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
【モジュールのインポート】
|
38
|
+
|
39
|
+
```Python
|
40
|
+
|
41
|
+
import keras
|
42
|
+
|
43
|
+
from keras.utils import np_utils
|
44
|
+
|
45
|
+
from keras.models import Sequential
|
46
|
+
|
47
|
+
from keras.layers.convolutional import Conv2D, MaxPooling2D
|
48
|
+
|
49
|
+
from keras.layers.core import Dense, Dropout, Activation, Flatten
|
50
|
+
|
51
|
+
import numpy as np
|
52
|
+
|
53
|
+
from sklearn.model_selection import train_test_split
|
54
|
+
|
55
|
+
from PIL import Image
|
56
|
+
|
57
|
+
import glob
|
58
|
+
|
59
|
+
import matplotlib.pyplot as plt
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
【モデルの学習】
|
66
|
+
|
67
|
+
```Python
|
68
|
+
|
69
|
+
# コンパイル
|
70
|
+
|
71
|
+
model.compile(loss='categorical_crossentropy',optimizer='SGD',metrics=['accuracy'])
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
#訓練
|
76
|
+
|
77
|
+
history = model.fit(X_train, Y_train, epochs=68)
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
結果
|
82
|
+
|
83
|
+
Epoch 63/68
|
84
|
+
|
85
|
+
11/11 [==============================] - 8s 738ms/step - loss: 0.6579 - accuracy: 0.5960
|
86
|
+
|
87
|
+
Epoch 64/68
|
88
|
+
|
89
|
+
11/11 [==============================] - 8s 741ms/step - loss: 0.6106 - accuracy: 0.7025
|
90
|
+
|
91
|
+
Epoch 65/68
|
92
|
+
|
93
|
+
11/11 [==============================] - 8s 742ms/step - loss: 0.5175 - accuracy: 0.8125
|
94
|
+
|
95
|
+
Epoch 66/68
|
96
|
+
|
97
|
+
11/11 [==============================] - 8s 743ms/step - loss: 0.4060 - accuracy: 0.8675
|
98
|
+
|
99
|
+
Epoch 67/68
|
100
|
+
|
101
|
+
11/11 [==============================] - 8s 736ms/step - loss: 0.2739 - accuracy: 0.9247
|
102
|
+
|
103
|
+
Epoch 68/68
|
104
|
+
|
105
|
+
11/11 [==============================] - 8s 740ms/step - loss: 0.1299 - accuracy: 0.9590
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
【学習結果の表示】
|
110
|
+
|
111
|
+
```Python
|
112
|
+
|
113
|
+
#学習結果を表示
|
114
|
+
|
115
|
+
accuracy = history.history['accuracy']
|
116
|
+
|
117
|
+
loss = history.history['loss']
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
epochs = range(len(accuracy))
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
plt.plot(epochs, accuracy, 'bo', label='Training accuracy')
|
126
|
+
|
127
|
+
plt.title('Training and validation accuracy')
|
128
|
+
|
129
|
+
plt.legend()
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
plt.plot(epochs, loss, 'bo', label='Training loss')
|
134
|
+
|
135
|
+
plt.title('Training and validation loss')
|
136
|
+
|
137
|
+
plt.legend()
|
138
|
+
|
139
|
+
```
|
140
|
+
|
141
|
+
![イメージ説明](e4278ca5aba3327193ddad26f1f3eda0.png)
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
【学習したモデルの保存】
|
146
|
+
|
147
|
+
```Python
|
148
|
+
|
149
|
+
model.save("model.hdf5")
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
ここでエラーを起こしました。
|
156
|
+
|
157
|
+
AttributeError: 'NoneType' object has no attribute 'save'
|
158
|
+
|
159
|
+
とでてきました。
|