質問編集履歴

4

別の結果を追記

2020/10/09 08:06

投稿

ThoughtKnotSeer
ThoughtKnotSeer

スコア14

test CHANGED
File without changes
test CHANGED
@@ -142,72 +142,30 @@
142
142
 
143
143
  -----
144
144
 
145
+ 仕方ないので特徴ベクトルで学習させた全結合層と畳み込み層(imagenet学習済みResnet)を結合させてFine tuningを行ってみましたが、
146
+
147
+ 不思議な結果になりました。
148
+
145
149
  ```python
146
150
 
147
- model = resnet.ResNet152(weights='imagenet', include_top=False, pooling="avg")
151
+ model.evaluate(test_image, test_encord)
148
152
 
149
- image_feature = model.predict(image_data, verbose=1)
153
+ # [0.2531382454914993, 0.6142322]
150
154
 
151
- pc = PCA(n_components=2).fit_transform(image_feature)
155
+ model.fit(train_image, train_encord, epochs=3, batch_size=16,validation_split=0.1)
152
156
 
153
- pc1, pc2 = pc[:,0],pc[:,1]
157
+ # 2160/2160 [==============================] - 93s 43ms/sample - loss: 1.5922 - total_acc: 0.2333 - val_loss: 0.2954 - val_total_acc: 0.5643
154
158
 
155
- plt.scatter(pc1, pc2, c=np.sum(encorded,axis=1), cmap="jet")
159
+ model.evaluate(test_image, test_encord)
156
160
 
157
- plt.colorbar()
161
+ # [0.2892280397343725, 0.54681647]
158
162
 
159
- plt.show()
163
+ model.evaluate(train_image, train_encord)
164
+
165
+ # [0.2311001866869706, 0.6222407]
160
166
 
161
167
  ```
162
168
 
163
- preprocess無し
169
+ 悪い方向に学習するだけでなく、進捗で表示される結果とevaluateの結果が異なる等、何が起きているのか良く分かりません。
164
170
 
165
- ![イメージ説明](97f09c6d97846ff3cf0894564ddbab56.png)
166
-
167
- preprocessあり
168
-
169
- ![イメージ説明](51dfa49c1eac6b343416a5d31763f07d.png)
170
-
171
- ---
172
-
173
- Preprocess_inputの検証
174
-
175
- ```python
176
-
177
- resnet.preprocess_input(image_array)
178
-
179
- train_image, test_image, train_score, test_score = train_test_split(image_array, encorded, test_size=0.1, random_state=100)
180
-
181
- conv_model = resnet.ResNet152(weights='imagenet', include_top=False, pooling="avg",input_shape=(224,224,3))
182
-
183
- conv_model.trainable = False
184
-
185
-
186
-
187
- top_model = Sequential()
188
-
189
- top_model.add(Input(2048))
190
-
191
- top_model.add(Dense(256, activation="relu"))
192
-
193
- top_model.add(Dropout(0.5))
194
-
195
- top_model.add(Dense(4, activation="sigmoid"))
196
-
197
-
198
-
199
- model = Sequential([conv_model,top_model])
200
-
201
-
202
-
203
- model.compile(optimizer="adam",
204
-
205
- loss="binary_crossentropy",
206
-
207
- metrics=[total_acc])
208
-
209
- history = model.fit(train_image, train_score, epochs=20, batch_size=16,validation_split=0.1)
171
+ バグのような気もしてきたので環境を変えてみようかと思いますが、質問は数日で打ち切らせていただき、Tensorflowのコミュニティで聞いてみることにします。ありがとうございました。
210
-
211
- ```
212
-
213
- ![イメージ説明](cd4dcef334151010c931b79fa62f6dd4.png)

3

Preprocess_inputの検証を追加

2020/10/09 08:06

投稿

ThoughtKnotSeer
ThoughtKnotSeer

スコア14

test CHANGED
File without changes
test CHANGED
@@ -167,3 +167,47 @@
167
167
  preprocessあり
168
168
 
169
169
  ![イメージ説明](51dfa49c1eac6b343416a5d31763f07d.png)
170
+
171
+ ---
172
+
173
+ Preprocess_inputの検証
174
+
175
+ ```python
176
+
177
+ resnet.preprocess_input(image_array)
178
+
179
+ train_image, test_image, train_score, test_score = train_test_split(image_array, encorded, test_size=0.1, random_state=100)
180
+
181
+ conv_model = resnet.ResNet152(weights='imagenet', include_top=False, pooling="avg",input_shape=(224,224,3))
182
+
183
+ conv_model.trainable = False
184
+
185
+
186
+
187
+ top_model = Sequential()
188
+
189
+ top_model.add(Input(2048))
190
+
191
+ top_model.add(Dense(256, activation="relu"))
192
+
193
+ top_model.add(Dropout(0.5))
194
+
195
+ top_model.add(Dense(4, activation="sigmoid"))
196
+
197
+
198
+
199
+ model = Sequential([conv_model,top_model])
200
+
201
+
202
+
203
+ model.compile(optimizer="adam",
204
+
205
+ loss="binary_crossentropy",
206
+
207
+ metrics=[total_acc])
208
+
209
+ history = model.fit(train_image, train_score, epochs=20, batch_size=16,validation_split=0.1)
210
+
211
+ ```
212
+
213
+ ![イメージ説明](cd4dcef334151010c931b79fa62f6dd4.png)

2

コードミスを修正

2020/10/06 06:32

投稿

ThoughtKnotSeer
ThoughtKnotSeer

スコア14

test CHANGED
File without changes
test CHANGED
@@ -88,12 +88,6 @@
88
88
 
89
89
  top_model.add(Dense(4, activation="sigmoid"))
90
90
 
91
- top_model.compile(optimizer="adam",
92
-
93
- loss="binary_crossentropy",
94
-
95
- metrics=[total_acc])
96
-
97
91
 
98
92
 
99
93
  model = Sequential([conv_model,top_model])

1

preprocess_input有無の差について追記

2020/10/06 05:44

投稿

ThoughtKnotSeer
ThoughtKnotSeer

スコア14

test CHANGED
File without changes
test CHANGED
@@ -141,3 +141,35 @@
141
141
  tensorflow version2.1.0のtf.kerasを使っています。
142
142
 
143
143
  宜しくお願いします。
144
+
145
+
146
+
147
+ 追記
148
+
149
+ -----
150
+
151
+ ```python
152
+
153
+ model = resnet.ResNet152(weights='imagenet', include_top=False, pooling="avg")
154
+
155
+ image_feature = model.predict(image_data, verbose=1)
156
+
157
+ pc = PCA(n_components=2).fit_transform(image_feature)
158
+
159
+ pc1, pc2 = pc[:,0],pc[:,1]
160
+
161
+ plt.scatter(pc1, pc2, c=np.sum(encorded,axis=1), cmap="jet")
162
+
163
+ plt.colorbar()
164
+
165
+ plt.show()
166
+
167
+ ```
168
+
169
+ preprocess無し
170
+
171
+ ![イメージ説明](97f09c6d97846ff3cf0894564ddbab56.png)
172
+
173
+ preprocessあり
174
+
175
+ ![イメージ説明](51dfa49c1eac6b343416a5d31763f07d.png)