質問編集履歴
1
質問を修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,5 +1,93 @@
|
|
1
1
|
googlecolab上でChainerを用いて224枚のシカの画像を学習させ、その学習データを生成するプログラムを作成しているのですが、おそらく、L.Convolution2DとL.linearの使い方がいまいちわからず、不適切な値を入れているせいで以下のエラーが出てしまいます。どうしたらよろしいでしょうか。
|
2
2
|
|
3
|
+
|
4
|
+
|
5
|
+
**エラー文**
|
6
|
+
|
7
|
+
Exception in main training loop: index 218 is out of bounds for axis 0 with size 3
|
8
|
+
|
9
|
+
Traceback (most recent call last):
|
10
|
+
|
11
|
+
File "/usr/local/lib/python3.6/dist-packages/chainer/training/trainer.py", line 343, in run
|
12
|
+
|
13
|
+
update()
|
14
|
+
|
15
|
+
File "/usr/local/lib/python3.6/dist-packages/chainer/training/updaters/standard_updater.py", line 240, in update
|
16
|
+
|
17
|
+
self.update_core()
|
18
|
+
|
19
|
+
File "/usr/local/lib/python3.6/dist-packages/chainer/training/updaters/standard_updater.py", line 253, in update_core
|
20
|
+
|
21
|
+
optimizer.update(loss_func, *in_arrays)
|
22
|
+
|
23
|
+
File "/usr/local/lib/python3.6/dist-packages/chainer/optimizer.py", line 874, in update
|
24
|
+
|
25
|
+
loss = lossfun(*args, **kwds)
|
26
|
+
|
27
|
+
File "/usr/local/lib/python3.6/dist-packages/chainer/link.py", line 287, in __call__
|
28
|
+
|
29
|
+
out = forward(*args, **kwargs)
|
30
|
+
|
31
|
+
File "/usr/local/lib/python3.6/dist-packages/chainer/links/model/classifier.py", line 144, in forward
|
32
|
+
|
33
|
+
self.loss = self.lossfun(self.y, t)
|
34
|
+
|
35
|
+
File "/usr/local/lib/python3.6/dist-packages/chainer/functions/loss/softmax_cross_entropy.py", line 556, in softmax_cross_entropy
|
36
|
+
|
37
|
+
loss, = func.apply((x, t))
|
38
|
+
|
39
|
+
File "/usr/local/lib/python3.6/dist-packages/chainer/function_node.py", line 334, in apply
|
40
|
+
|
41
|
+
outputs = self.forward(in_data)
|
42
|
+
|
43
|
+
File "/usr/local/lib/python3.6/dist-packages/chainer/function_node.py", line 592, in forward
|
44
|
+
|
45
|
+
return self.forward_cpu(inputs)
|
46
|
+
|
47
|
+
File "/usr/local/lib/python3.6/dist-packages/chainer/functions/loss/softmax_cross_entropy.py", line 162, in forward_cpu
|
48
|
+
|
49
|
+
log_p = log_yd[t.ravel(), numpy.arange(t.size)]
|
50
|
+
|
51
|
+
Will finalize trainer extensions and updater before reraising the exception.
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
IndexError Traceback (most recent call last)
|
56
|
+
|
57
|
+
<ipython-input-1-3bf3422f7400> in <module>()
|
58
|
+
|
59
|
+
81 trainer.extend(extensions.PlotReport(['main/loss'],'epoch',file_name='loss.png'))
|
60
|
+
|
61
|
+
82 trainer.extend(extensions.PlotReport(['main/accuracy'],'epoch',file_name='accuracy.png'))
|
62
|
+
|
63
|
+
---> 83 trainer.run()
|
64
|
+
|
65
|
+
84
|
66
|
+
|
67
|
+
85 serializer.save_npz("mymodel.npz",model)
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
/usr/local/lib/python3.6/dist-packages/chainer/functions/loss/softmax_cross_entropy.py in forward_cpu(self, inputs)
|
72
|
+
|
73
|
+
160 t_valid = t != self.ignore_label
|
74
|
+
|
75
|
+
161 t = t * t_valid
|
76
|
+
|
77
|
+
--> 162 log_p = log_yd[t.ravel(), numpy.arange(t.size)]
|
78
|
+
|
79
|
+
163
|
80
|
+
|
81
|
+
164 log_p *= t_valid.ravel()
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
IndexError: index 218 is out of bounds for axis 0 with size 3
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
**コード**
|
90
|
+
|
3
91
|
```python
|
4
92
|
|
5
93
|
import chainer
|
@@ -36,21 +124,21 @@
|
|
36
124
|
|
37
125
|
with self.init_scope():
|
38
126
|
|
39
|
-
self.conv1 = L.Convolution2D(None,16,
|
127
|
+
self.conv1 = L.Convolution2D(None,16,3,pad=2)
|
40
|
-
|
128
|
+
|
41
|
-
self.conv2 = L.Convolution2D(None,32,
|
129
|
+
self.conv2 = L.Convolution2D(None,32,3,pad=2)
|
42
130
|
|
43
131
|
self.l3 = L.Linear(None,256)
|
44
132
|
|
45
|
-
self.l4 = L.Linear(None,
|
133
|
+
self.l4 = L.Linear(None,3)
|
46
134
|
|
47
135
|
|
48
136
|
|
49
137
|
def __call__(self,x):
|
50
138
|
|
51
|
-
h = F.max_pooling_2d(F.relu(self.conv1(x)),ksize=
|
139
|
+
h = F.max_pooling_2d(F.relu(self.conv1(x)),ksize=3,stride=2,pad=2)
|
52
|
-
|
140
|
+
|
53
|
-
h = F.max_pooling_2d(F.relu(self.conv2(x)),ksize=
|
141
|
+
h = F.max_pooling_2d(F.relu(self.conv2(x)),ksize=3,stride=2,pad=2)
|
54
142
|
|
55
143
|
h = F.dropout(F.relu(self.l3(h)))
|
56
144
|
|
@@ -62,7 +150,7 @@
|
|
62
150
|
|
63
151
|
|
64
152
|
|
65
|
-
#-----
|
153
|
+
#-----img-----
|
66
154
|
|
67
155
|
|
68
156
|
|
@@ -175,85 +263,3 @@
|
|
175
263
|
|
176
264
|
|
177
265
|
```
|
178
|
-
|
179
|
-
以下エラー文です
|
180
|
-
|
181
|
-
Exception in main training loop: index 207 is out of bounds for axis 0 with size 5
|
182
|
-
|
183
|
-
Traceback (most recent call last):
|
184
|
-
|
185
|
-
File "/usr/local/lib/python3.6/dist-packages/chainer/training/trainer.py", line 343, in run
|
186
|
-
|
187
|
-
update()
|
188
|
-
|
189
|
-
File "/usr/local/lib/python3.6/dist-packages/chainer/training/updaters/standard_updater.py", line 240, in update
|
190
|
-
|
191
|
-
self.update_core()
|
192
|
-
|
193
|
-
File "/usr/local/lib/python3.6/dist-packages/chainer/training/updaters/standard_updater.py", line 253, in update_core
|
194
|
-
|
195
|
-
optimizer.update(loss_func, *in_arrays)
|
196
|
-
|
197
|
-
File "/usr/local/lib/python3.6/dist-packages/chainer/optimizer.py", line 874, in update
|
198
|
-
|
199
|
-
loss = lossfun(*args, **kwds)
|
200
|
-
|
201
|
-
File "/usr/local/lib/python3.6/dist-packages/chainer/link.py", line 287, in __call__
|
202
|
-
|
203
|
-
out = forward(*args, **kwargs)
|
204
|
-
|
205
|
-
File "/usr/local/lib/python3.6/dist-packages/chainer/links/model/classifier.py", line 144, in forward
|
206
|
-
|
207
|
-
self.loss = self.lossfun(self.y, t)
|
208
|
-
|
209
|
-
File "/usr/local/lib/python3.6/dist-packages/chainer/functions/loss/softmax_cross_entropy.py", line 556, in softmax_cross_entropy
|
210
|
-
|
211
|
-
loss, = func.apply((x, t))
|
212
|
-
|
213
|
-
File "/usr/local/lib/python3.6/dist-packages/chainer/function_node.py", line 334, in apply
|
214
|
-
|
215
|
-
outputs = self.forward(in_data)
|
216
|
-
|
217
|
-
File "/usr/local/lib/python3.6/dist-packages/chainer/function_node.py", line 592, in forward
|
218
|
-
|
219
|
-
return self.forward_cpu(inputs)
|
220
|
-
|
221
|
-
File "/usr/local/lib/python3.6/dist-packages/chainer/functions/loss/softmax_cross_entropy.py", line 162, in forward_cpu
|
222
|
-
|
223
|
-
log_p = log_yd[t.ravel(), numpy.arange(t.size)]
|
224
|
-
|
225
|
-
Will finalize trainer extensions and updater before reraising the exception.
|
226
|
-
|
227
|
-
---------------------------------------------------------------------------
|
228
|
-
|
229
|
-
IndexError Traceback (most recent call last)
|
230
|
-
|
231
|
-
<ipython-input-1-210692821ef6> in <module>()
|
232
|
-
|
233
|
-
81 trainer.extend(extensions.PlotReport(['main/loss'],'epoch',file_name='loss.png'))
|
234
|
-
|
235
|
-
82 trainer.extend(extensions.PlotReport(['main/accuracy'],'epoch',file_name='accuracy.png'))
|
236
|
-
|
237
|
-
---> 83 trainer.run()
|
238
|
-
|
239
|
-
84
|
240
|
-
|
241
|
-
85 serializer.save_npz("mymodel.npz",model)
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
/usr/local/lib/python3.6/dist-packages/chainer/functions/loss/softmax_cross_entropy.py in forward_cpu(self, inputs)
|
246
|
-
|
247
|
-
160 t_valid = t != self.ignore_label
|
248
|
-
|
249
|
-
161 t = t * t_valid
|
250
|
-
|
251
|
-
--> 162 log_p = log_yd[t.ravel(), numpy.arange(t.size)]
|
252
|
-
|
253
|
-
163
|
254
|
-
|
255
|
-
164 log_p *= t_valid.ravel()
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
IndexError: index 207 is out of bounds for axis 0 with size 5
|