質問編集履歴
3
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,9 +8,7 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
|
11
|
+
```python
|
12
|
-
|
13
|
-
|
14
12
|
|
15
13
|
from keras.models import Sequential
|
16
14
|
|
@@ -139,3 +137,7 @@
|
|
139
137
|
if __name__ == "__main__":
|
140
138
|
|
141
139
|
main()
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
```
|
2
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -5,3 +5,137 @@
|
|
5
5
|
|
6
6
|
|
7
7
|
![イメージ説明](45f2d31fb6c5d790d8173187a4f5393b.jpeg)
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
トレーニングのコードです↓
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
from keras.models import Sequential
|
16
|
+
|
17
|
+
from keras.layers import Convolution2D, MaxPooling2D
|
18
|
+
|
19
|
+
from keras.layers import Activation, Dropout, Flatten, Dense
|
20
|
+
|
21
|
+
from keras.utils import np_utils
|
22
|
+
|
23
|
+
import keras
|
24
|
+
|
25
|
+
import numpy as np
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
classes = ["kouroenkawa","kuroguchi"]
|
30
|
+
|
31
|
+
num_classes = len(classes)
|
32
|
+
|
33
|
+
image_width = 50
|
34
|
+
|
35
|
+
image_height = 50
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
#メインの関数を定義する
|
40
|
+
|
41
|
+
def main():
|
42
|
+
|
43
|
+
X_train, X_test, y_train, y_test = np.load("./orido.npy", allow_pickle=True)
|
44
|
+
|
45
|
+
X_train = X_train.astype("float") / 256
|
46
|
+
|
47
|
+
X_test = X_test.astype("float") / 256
|
48
|
+
|
49
|
+
y_train = np_utils.to_categorical(y_train,num_classes)
|
50
|
+
|
51
|
+
y_test = np_utils.to_categorical(y_test, num_classes)
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
model = model_train(X_train, y_train)
|
56
|
+
|
57
|
+
model_eval(model, X_test, y_test)
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
def model_train(X, y):
|
62
|
+
|
63
|
+
model = Sequential()
|
64
|
+
|
65
|
+
model.add(Convolution2D(32,(3,3),padding='same', input_shape=X.shape[1:]))
|
66
|
+
|
67
|
+
model.add(Activation('relu'))
|
68
|
+
|
69
|
+
model.add(Convolution2D(32,(3,3)))
|
70
|
+
|
71
|
+
model.add(Activation('relu'))
|
72
|
+
|
73
|
+
model.add(MaxPooling2D(pool_size=(2,2)))
|
74
|
+
|
75
|
+
model.add(Dropout(0.25))
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
model.add(Convolution2D(64,(3,3),padding='same'))
|
80
|
+
|
81
|
+
model.add(Activation('relu'))
|
82
|
+
|
83
|
+
model.add(Convolution2D(64,(3,3)))
|
84
|
+
|
85
|
+
model.add(Activation('relu'))
|
86
|
+
|
87
|
+
model.add(MaxPooling2D(pool_size=(2,2)))
|
88
|
+
|
89
|
+
model.add(Dropout(0.25))
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
model.add(Flatten())
|
94
|
+
|
95
|
+
model.add(Dense(512))
|
96
|
+
|
97
|
+
model.add(Activation('relu'))
|
98
|
+
|
99
|
+
model.add(Dropout(0.5))
|
100
|
+
|
101
|
+
model.add(Dense(2))
|
102
|
+
|
103
|
+
model.add(Activation('softmax'))
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
opt = keras.optimizers.rmsprop(lr=0.0001, decay=1e-6)
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
model.compile(loss='categorical_crossentropy', optimizer=opt, metrics=['accuracy'])
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
model.fit(X, y, batch_size=32, nb_epoch=100)
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
#モデルの保存
|
120
|
+
|
121
|
+
model.save('./orido_cnn.h5')
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
return model
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
def model_eval(model, X, y):
|
130
|
+
|
131
|
+
scores = model.evaluate(X, y, verbose=1)
|
132
|
+
|
133
|
+
print('test Loss: ', scores[0])
|
134
|
+
|
135
|
+
print('test Accuracy: ', scores[1])
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
if __name__ == "__main__":
|
140
|
+
|
141
|
+
main()
|
1
グラフ
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,7 @@
|
|
1
1
|
ミニバッチ学習法で2クラスの画像分類を行いました。実行結果からグラフ(このグラフが妥当なものかはわからないですが…)を作ってみました。
|
2
2
|
|
3
3
|
正解率データはあまり差はありませんでしたが、増幅した場合(下)損失関数が非常に高くなりました。これは過学習が起きたということでしょうか。
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
![イメージ説明](45f2d31fb6c5d790d8173187a4f5393b.jpeg)
|