質問編集履歴
4
モデル関連の追記
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
KerasのGenerator(fit_generator)の
|
1
|
+
KerasのGenerator(fit_generator)のdimensionエラーについて
|
test
CHANGED
@@ -134,7 +134,7 @@
|
|
134
134
|
|
135
135
|
```
|
136
136
|
|
137
|
-
shapeが間違っているエラーのようですが、どのように修正すれば良いかご教授ください
|
137
|
+
dimension(shape)が間違っているエラーのようですが、どのように修正すれば良いかご教授ください
|
138
138
|
|
139
139
|
|
140
140
|
|
@@ -228,6 +228,10 @@
|
|
228
228
|
|
229
229
|
|
230
230
|
|
231
|
+
input_shape = (1,n,4*4)
|
232
|
+
|
233
|
+
|
234
|
+
|
231
235
|
# 畳み込みニューラルネットワークを定義
|
232
236
|
|
233
237
|
model = Sequential()
|
3
model関連の追記修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -228,6 +228,34 @@
|
|
228
228
|
|
229
229
|
|
230
230
|
|
231
|
+
# 畳み込みニューラルネットワークを定義
|
232
|
+
|
233
|
+
model = Sequential()
|
234
|
+
|
235
|
+
model.add(Conv2D(filters=32, kernel_size=(3,3), activation='relu', input_shape=input_shape))
|
236
|
+
|
237
|
+
model.add(Conv2D(filters=64, kernel_size=(3,3), activation='relu'))
|
238
|
+
|
239
|
+
model.add(MaxPooling2D(pool_size=(2, 2)))
|
240
|
+
|
241
|
+
model.add(Dropout(0.25))
|
242
|
+
|
243
|
+
model.add(Flatten())
|
244
|
+
|
245
|
+
model.add(Dense(units=128, activation='relu'))
|
246
|
+
|
247
|
+
model.add(Dropout(0.5))
|
248
|
+
|
249
|
+
model.add(Dense(units=n_classes, activation='softmax'))
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
# モデルのコンパイル
|
254
|
+
|
255
|
+
model.compile(loss=keras.losses.categorical_crossentropy, optimizer=keras.optimizers.Adadelta(), metrics=['accuracy'])
|
256
|
+
|
257
|
+
|
258
|
+
|
231
259
|
# steps_per_epochはその名のとおり、1epochのstep数で、基本はデータ数 / バッチサイズ = int(srcdlen / batchsize)
|
232
260
|
|
233
261
|
history = model.fit_generator(
|
2
エラー内容が違っていましたので修正しました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
KerasのGenerator
|
1
|
+
KerasのGenerator(fit_generator)のShapeエラーについて
|
test
CHANGED
@@ -6,15 +6,11 @@
|
|
6
6
|
|
7
7
|
```Python
|
8
8
|
|
9
|
+
# プログラムで表示
|
10
|
+
|
9
|
-
|
11
|
+
1 2019-12-15 23:17:43.918748
|
10
|
-
|
11
|
-
|
12
|
+
|
12
|
-
|
13
|
-
|
13
|
+
Epoch 1/10
|
14
|
-
|
15
|
-
--> verbose=1)
|
16
|
-
|
17
|
-
|
18
14
|
|
19
15
|
# エラー内容
|
20
16
|
|
@@ -22,7 +18,7 @@
|
|
22
18
|
|
23
19
|
ValueError Traceback (most recent call last)
|
24
20
|
|
25
|
-
<ipython-input-5
|
21
|
+
<ipython-input-56-5381014b3057> in <module>()
|
26
22
|
|
27
23
|
131 steps_per_epoch=int(np.ceil(srcdlen / batch_size)),
|
28
24
|
|
@@ -80,29 +76,65 @@
|
|
80
76
|
|
81
77
|
/home/user/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_q_size, workers, pickle_safe, initial_epoch)
|
82
78
|
|
79
|
+
1900 outs = self.train_on_batch(x, y,
|
80
|
+
|
83
|
-
1
|
81
|
+
1901 sample_weight=sample_weight,
|
82
|
+
|
84
|
-
|
83
|
+
-> 1902 class_weight=class_weight)
|
84
|
+
|
85
|
+
1903
|
86
|
+
|
87
|
+
1904 if not isinstance(outs, list):
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
/home/user/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/keras/engine/training.py in train_on_batch(self, x, y, sample_weight, class_weight)
|
92
|
+
|
93
|
+
1634 sample_weight=sample_weight,
|
94
|
+
|
95
|
+
1635 class_weight=class_weight,
|
96
|
+
|
97
|
+
-> 1636 check_batch_axis=True)
|
98
|
+
|
99
|
+
1637 if self.uses_learning_phase and not isinstance(K.learning_phase(), int):
|
100
|
+
|
101
|
+
1638 ins = x + y + sample_weights + [1.]
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
/home/user/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_batch_axis, batch_size)
|
106
|
+
|
107
|
+
1309 self._feed_input_shapes,
|
108
|
+
|
109
|
+
1310 check_batch_axis=False,
|
110
|
+
|
85
|
-
|
111
|
+
-> 1311 exception_prefix='input')
|
112
|
+
|
86
|
-
|
113
|
+
1312 y = _standardize_input_data(y, self._feed_output_names,
|
114
|
+
|
115
|
+
1313 output_shapes,
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
/home/user/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/keras/engine/training.py in _standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
|
120
|
+
|
121
|
+
125 ' to have ' + str(len(shapes[i])) +
|
122
|
+
|
123
|
+
126 ' dimensions, but got array with shape ' +
|
124
|
+
|
87
|
-
-> 1
|
125
|
+
--> 127 str(array.shape))
|
88
|
-
|
126
|
+
|
89
|
-
18
|
127
|
+
128 for j, (dim, ref_dim) in enumerate(zip(array.shape, shapes[i])):
|
90
|
-
|
128
|
+
|
91
|
-
1
|
129
|
+
129 if not j and not check_batch_axis:
|
92
|
-
|
93
|
-
|
94
|
-
|
130
|
+
|
131
|
+
|
132
|
+
|
95
|
-
ValueError: output o
|
133
|
+
ValueError: Error when checking input: expected conv2d_71_input to have 4 dimensions, but got array with shape (1000, 160, 16)
|
96
134
|
|
97
135
|
```
|
98
136
|
|
99
|
-
def flow_from_datafile内の以下の行
|
100
|
-
|
101
|
-
yield inputs, targets
|
102
|
-
|
103
|
-
|
137
|
+
shapeが間違っているエラーのようですが、どのように修正すれば良いかご教授ください
|
104
|
-
|
105
|
-
いろいろ試してみましたがうまくいかないので、御教授ください。
|
106
138
|
|
107
139
|
|
108
140
|
|
1
エラー内容の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
```Python
|
8
8
|
|
9
|
-
# エラー箇所は以下となっています。
|
9
|
+
# エラー箇所は以下となっています。(プログラムの一番下のところ「model.fit_generator」)
|
10
10
|
|
11
11
|
steps_per_epoch=int(np.ceil(srcdlen / batch_size)),
|
12
12
|
|
@@ -18,6 +18,80 @@
|
|
18
18
|
|
19
19
|
# エラー内容
|
20
20
|
|
21
|
+
---------------------------------------------------------------------------
|
22
|
+
|
23
|
+
ValueError Traceback (most recent call last)
|
24
|
+
|
25
|
+
<ipython-input-50-82ec9caa5e8c> in <module>()
|
26
|
+
|
27
|
+
131 steps_per_epoch=int(np.ceil(srcdlen / batch_size)),
|
28
|
+
|
29
|
+
132 epochs=epochs,
|
30
|
+
|
31
|
+
--> 133 verbose=1)
|
32
|
+
|
33
|
+
134 #validation_data=test_datagen.flow_from_datafile(n_classes, batch_size, tstdlen),
|
34
|
+
|
35
|
+
135 #validation_steps=int(np.ceil(tstdlen / batch_size)))
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
/home/user/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
|
40
|
+
|
41
|
+
86 warnings.warn('Update your `' + object_name +
|
42
|
+
|
43
|
+
87 '` call to the Keras 2 API: ' + signature, stacklevel=2)
|
44
|
+
|
45
|
+
---> 88 return func(*args, **kwargs)
|
46
|
+
|
47
|
+
89 wrapper._legacy_support_signature = inspect.getargspec(func)
|
48
|
+
|
49
|
+
90 return wrapper
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
/home/user/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/keras/models.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_q_size, workers, pickle_safe, initial_epoch)
|
54
|
+
|
55
|
+
1122 workers=workers,
|
56
|
+
|
57
|
+
1123 pickle_safe=pickle_safe,
|
58
|
+
|
59
|
+
-> 1124 initial_epoch=initial_epoch)
|
60
|
+
|
61
|
+
1125
|
62
|
+
|
63
|
+
1126 @interfaces.legacy_generator_methods_support
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
/home/user/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
|
68
|
+
|
69
|
+
86 warnings.warn('Update your `' + object_name +
|
70
|
+
|
71
|
+
87 '` call to the Keras 2 API: ' + signature, stacklevel=2)
|
72
|
+
|
73
|
+
---> 88 return func(*args, **kwargs)
|
74
|
+
|
75
|
+
89 wrapper._legacy_support_signature = inspect.getargspec(func)
|
76
|
+
|
77
|
+
90 return wrapper
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
/home/user/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_q_size, workers, pickle_safe, initial_epoch)
|
82
|
+
|
83
|
+
1875 'a tuple `(x, y, sample_weight)` '
|
84
|
+
|
85
|
+
1876 'or `(x, y)`. Found: ' +
|
86
|
+
|
87
|
+
-> 1877 str(generator_output))
|
88
|
+
|
89
|
+
1878 if len(generator_output) == 2:
|
90
|
+
|
91
|
+
1879 x, y = generator_output
|
92
|
+
|
93
|
+
|
94
|
+
|
21
95
|
ValueError: output of generator should be a tuple `(x, y, sample_weight)` or `(x, y)`. Found: None
|
22
96
|
|
23
97
|
```
|