質問編集履歴
2
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,395 +1 @@
|
|
1
|
-
### 前提・実現したいこと
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
ここに質問の内容を詳しく書いてください。
|
6
|
-
|
7
|
-
|
1
|
+
ああいうか。頑張ろうって言ったら不服だわなのでが!あのですねねなお写真ありがとうございますのお陰
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
### 発生している問題・エラーメッセージ
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
```
|
16
|
-
|
17
|
-
実行すると下記エラーのうちどちらかが発生します。
|
18
|
-
|
19
|
-
Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (None, 128, 128)
|
20
|
-
|
21
|
-
ValueError: Shapes (None, 1) and (None, 10, 10, 2) are incompatible
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
```
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
### 該当のソースコード
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
```python
|
34
|
-
|
35
|
-
import tensorflow as tf
|
36
|
-
|
37
|
-
from keras.preprocessing.image import load_img, img_to_array, array_to_img
|
38
|
-
|
39
|
-
from keras.preprocessing.image import random_rotation, random_shift, random_zoom
|
40
|
-
|
41
|
-
from keras.layers.convolutional import Conv2D
|
42
|
-
|
43
|
-
from keras.layers.pooling import MaxPooling2D
|
44
|
-
|
45
|
-
from keras.layers.core import Activation
|
46
|
-
|
47
|
-
from keras.layers.core import Dense
|
48
|
-
|
49
|
-
from keras.layers.core import Dropout
|
50
|
-
|
51
|
-
from keras.layers.core import Flatten
|
52
|
-
|
53
|
-
from keras.models import Sequential
|
54
|
-
|
55
|
-
from keras.models import model_from_json
|
56
|
-
|
57
|
-
from keras.callbacks import LearningRateScheduler
|
58
|
-
|
59
|
-
from keras.callbacks import ModelCheckpoint
|
60
|
-
|
61
|
-
from keras.optimizers import Adam
|
62
|
-
|
63
|
-
from keras.utils import np_utils
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
# coding:utf-8
|
70
|
-
|
71
|
-
from keras.utils import np_utils
|
72
|
-
|
73
|
-
from keras.models import Sequential
|
74
|
-
|
75
|
-
from keras.layers.convolutional import MaxPooling2D
|
76
|
-
|
77
|
-
from keras.layers import Activation, Conv2D, Flatten, Dense,Dropout
|
78
|
-
|
79
|
-
from sklearn.model_selection import train_test_split
|
80
|
-
|
81
|
-
from keras.optimizers import SGD, Adadelta, Adagrad, Adam, Adamax, RMSprop, Nadam
|
82
|
-
|
83
|
-
from PIL import Image
|
84
|
-
|
85
|
-
import numpy as np
|
86
|
-
|
87
|
-
import glob
|
88
|
-
|
89
|
-
import matplotlib.pyplot as plt
|
90
|
-
|
91
|
-
import time
|
92
|
-
|
93
|
-
import os
|
94
|
-
|
95
|
-
import keras
|
96
|
-
|
97
|
-
from keras.utils import np_utils
|
98
|
-
|
99
|
-
from keras.layers.convolutional import Conv2D, MaxPooling2D
|
100
|
-
|
101
|
-
from keras.models import Sequential
|
102
|
-
|
103
|
-
from keras.layers.core import Dense, Dropout, Activation, Flatten
|
104
|
-
|
105
|
-
from keras.preprocessing.image import load_img
|
106
|
-
|
107
|
-
from keras.preprocessing.image import img_to_array
|
108
|
-
|
109
|
-
import numpy as np
|
110
|
-
|
111
|
-
import pandas as pd
|
112
|
-
|
113
|
-
from sklearn.model_selection import train_test_split
|
114
|
-
|
115
|
-
import matplotlib.pyplot as plt
|
116
|
-
|
117
|
-
import glob
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
from keras.utils import np_utils
|
124
|
-
|
125
|
-
from keras.models import Sequential
|
126
|
-
|
127
|
-
from keras.layers.convolutional import MaxPooling2D
|
128
|
-
|
129
|
-
from keras.layers import Activation, Conv2D, Flatten, Dense,Dropout
|
130
|
-
|
131
|
-
from sklearn.model_selection import train_test_split
|
132
|
-
|
133
|
-
from keras.optimizers import SGD, Adadelta, Adagrad, Adam, Adamax, RMSprop, Nadam
|
134
|
-
|
135
|
-
from PIL import Image
|
136
|
-
|
137
|
-
import numpy as np
|
138
|
-
|
139
|
-
import glob
|
140
|
-
|
141
|
-
import matplotlib.pyplot as plt
|
142
|
-
|
143
|
-
import time
|
144
|
-
|
145
|
-
import os
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
NG_path='C:\NG\*'
|
150
|
-
|
151
|
-
NG_file=glob.glob(NG_path)
|
152
|
-
|
153
|
-
OK_path='C:\OK\*'
|
154
|
-
|
155
|
-
OK_file=glob.glob(OK_path)
|
156
|
-
|
157
|
-
X = []
|
158
|
-
|
159
|
-
Y = []
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
dense_size=len(NG_file)+len(OK_file)
|
164
|
-
|
165
|
-
for file in NG_file:
|
166
|
-
|
167
|
-
image = Image.open(file)
|
168
|
-
|
169
|
-
# image = image.convert("RGB")
|
170
|
-
|
171
|
-
data = np.asarray(image)
|
172
|
-
|
173
|
-
X.append(data)
|
174
|
-
|
175
|
-
Y.append(0)
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
for file in OK_file:
|
180
|
-
|
181
|
-
image = Image.open(file)
|
182
|
-
|
183
|
-
# image = image.convert("RGB")
|
184
|
-
|
185
|
-
data = np.asarray(image)
|
186
|
-
|
187
|
-
X.append(data)
|
188
|
-
|
189
|
-
Y.append(1)
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
X = np.array(X)
|
194
|
-
|
195
|
-
Y = np.array(Y)
|
196
|
-
|
197
|
-
X = X.astype('float32')
|
198
|
-
|
199
|
-
X = X / 255.0
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.20)
|
204
|
-
|
205
|
-
X_train = X_train.reshape((-1,128,128,1))
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
model = tf.keras.models.Sequential()
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
model.add(tf.keras.layers.Conv2D(64, kernel_size=(3, 3), input_shape=(128, 128, 1)))
|
214
|
-
|
215
|
-
model.add(tf.keras.layers.BatchNormalization())
|
216
|
-
|
217
|
-
model.add(tf.keras.layers.ReLU())
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
model.add(tf.keras.layers.Conv2D(64, kernel_size=(3, 3), input_shape=(128, 128, 64)))
|
222
|
-
|
223
|
-
model.add(tf.keras.layers.BatchNormalization())
|
224
|
-
|
225
|
-
model.add(tf.keras.layers.ReLU())
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
model.add(tf.keras.layers.Conv2D(64, kernel_size=(3, 3), input_shape=(128, 128, 64)))
|
230
|
-
|
231
|
-
model.add(tf.keras.layers.BatchNormalization())
|
232
|
-
|
233
|
-
model.add(tf.keras.layers.ReLU())
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
model.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
model.add(tf.keras.layers.Conv2D(128, kernel_size=(3, 3), input_shape=(64, 64, 64)))
|
242
|
-
|
243
|
-
model.add(tf.keras.layers.BatchNormalization())
|
244
|
-
|
245
|
-
model.add(tf.keras.layers.ReLU())
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
model.add(tf.keras.layers.Conv2D(128, kernel_size=(3, 3), input_shape=(64, 64, 64)))
|
250
|
-
|
251
|
-
model.add(tf.keras.layers.BatchNormalization())
|
252
|
-
|
253
|
-
model.add(tf.keras.layers.ReLU())
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
model.add(tf.keras.layers.Conv2D(128, kernel_size=(3, 3), input_shape=(64, 64, 128)))
|
258
|
-
|
259
|
-
model.add(tf.keras.layers.BatchNormalization())
|
260
|
-
|
261
|
-
model.add(tf.keras.layers.ReLU())
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
model.add(tf.keras.layers.Conv2D(128, kernel_size=(3, 3), input_shape=(64, 64, 128)))
|
266
|
-
|
267
|
-
model.add(tf.keras.layers.BatchNormalization())
|
268
|
-
|
269
|
-
model.add(tf.keras.layers.ReLU())
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
model.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
model.add(tf.keras.layers.Conv2D(128, kernel_size=(3, 3), input_shape=(32, 32, 128)))
|
278
|
-
|
279
|
-
model.add(tf.keras.layers.BatchNormalization())
|
280
|
-
|
281
|
-
model.add(tf.keras.layers.ReLU())
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
model.add(tf.keras.layers.Conv2D(128, kernel_size=(3, 3), input_shape=(32, 32, 128)))
|
286
|
-
|
287
|
-
model.add(tf.keras.layers.BatchNormalization())
|
288
|
-
|
289
|
-
model.add(tf.keras.layers.ReLU())
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
model.add(tf.keras.layers.Conv2D(128, kernel_size=(3, 3), input_shape=(32, 32, 128)))
|
294
|
-
|
295
|
-
model.add(tf.keras.layers.BatchNormalization())
|
296
|
-
|
297
|
-
model.add(tf.keras.layers.ReLU())
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
model.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
model.add(tf.keras.layers.Dropout(0.5))
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
model.add(tf.keras.layers.Dense(1026, activation='relu'))
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
model.add(tf.keras.layers.Dense(1026, activation='relu'))
|
314
|
-
|
315
|
-
model.add(tf.keras.layers.Dropout(0.5))
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
model.add(tf.keras.layers.Dense(2))
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
model.add(Flatten())
|
324
|
-
|
325
|
-
model.add(tf.keras.layers.Dense(2))
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
model.summary()
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
model.compile(loss='sparse_categorical_crossentropy',
|
336
|
-
|
337
|
-
optimizer=tf.keras.optimizers.Adam(),
|
338
|
-
|
339
|
-
metrics=['accuracy'])
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
history = model.fit(X_train, y_train, batch_size=16, epochs=10,
|
346
|
-
|
347
|
-
validation_data = (X_test, y_test), verbose = 0)
|
348
|
-
|
349
|
-
plt.plot(history.history['acc'])
|
350
|
-
|
351
|
-
plt.plot(history.history['val_acc'])
|
352
|
-
|
353
|
-
plt.title('model accuracy')
|
354
|
-
|
355
|
-
plt.xlabel('epoch')
|
356
|
-
|
357
|
-
plt.ylabel('accuracy')
|
358
|
-
|
359
|
-
plt.legend(['acc', 'val_acc'], loc='lower right')
|
360
|
-
|
361
|
-
plt.show()
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
```
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
### 試したこと
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
X_train = X_train.reshape((-1,128,128,1))
|
386
|
-
|
387
|
-
で形を変形。
|
388
|
-
|
389
|
-
入力形式の変更。
|
390
|
-
|
391
|
-
### 補足情報(FW/ツールのバージョンなど)
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
ここにより詳細な情報を記載してください。
|
1
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|