質問編集履歴

1

Stacktraceを追加しました

2020/10/27 16:52

投稿

TaichiTsujikawa
TaichiTsujikawa

スコア1

test CHANGED
File without changes
test CHANGED
@@ -164,10 +164,140 @@
164
164
 
165
165
 
166
166
 
167
+ ##以下出現したエラー
168
+
169
+ ---------------------------------------------------------------------------
170
+
171
+ RuntimeError Traceback (most recent call last)
172
+
173
+ <ipython-input-8-2396f00cf9e1> in <module>()
174
+
175
+ 3 earlystop_counter = 0
176
+
177
+ 4 for epoch in range(100):
178
+
179
+ ----> 5 train_loss = training(model, train_dataset, optimizer, loss_func)
180
+
181
+ 6 val_loss, val_acc = evaluation(model, val_dataset, loss_func)
182
+
183
+ 7
184
+
185
+
186
+
187
+ 6 frames
188
+
189
+ <ipython-input-6-33676f519731> in training(model, dataset, optimizer, loss_func)
190
+
191
+ 6 img = img.to("cuda")
192
+
193
+ 7 target = target.to("cuda")
194
+
195
+ ----> 8 pred = model(img)
196
+
197
+ 9 loss = loss_func(pred, target)
198
+
199
+ 10 losses.append(loss.item())
200
+
201
+
202
+
203
+ /usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
204
+
205
+ 720 result = self._slow_forward(*input, **kwargs)
206
+
207
+ 721 else:
208
+
209
+ --> 722 result = self.forward(*input, **kwargs)
210
+
211
+ 723 for hook in itertools.chain(
212
+
213
+ 724 _global_forward_hooks.values(),
214
+
215
+
216
+
217
+ /usr/local/lib/python3.6/dist-packages/torchvision/models/resnet.py in forward(self, x)
218
+
219
+ 218
220
+
221
+ 219 def forward(self, x):
222
+
223
+ --> 220 return self._forward_impl(x)
224
+
225
+ 221
226
+
227
+ 222
228
+
229
+
230
+
231
+ /usr/local/lib/python3.6/dist-packages/torchvision/models/resnet.py in _forward_impl(self, x)
232
+
233
+ 201 def _forward_impl(self, x):
234
+
235
+ 202 # See note [TorchScript super()]
236
+
237
+ --> 203 x = self.conv1(x)
238
+
239
+ 204 x = self.bn1(x)
240
+
241
+ 205 x = self.relu(x)
242
+
243
+
244
+
245
+ /usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
246
+
247
+ 720 result = self._slow_forward(*input, **kwargs)
248
+
249
+ 721 else:
250
+
251
+ --> 722 result = self.forward(*input, **kwargs)
252
+
253
+ 723 for hook in itertools.chain(
254
+
255
+ 724 _global_forward_hooks.values(),
256
+
257
+
258
+
259
+ /usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py in forward(self, input)
260
+
261
+ 417
262
+
263
+ 418 def forward(self, input: Tensor) -> Tensor:
264
+
265
+ --> 419 return self._conv_forward(input, self.weight)
266
+
267
+ 420
268
+
269
+ 421 class Conv3d(_ConvNd):
270
+
271
+
272
+
273
+ /usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py in _conv_forward(self, input, weight)
274
+
275
+ 414 _pair(0), self.dilation, self.groups)
276
+
277
+ 415 return F.conv2d(input, weight, self.bias, self.stride,
278
+
279
+ --> 416 self.padding, self.dilation, self.groups)
280
+
281
+ 417
282
+
283
+ 418 def forward(self, input: Tensor) -> Tensor:
284
+
285
+
286
+
287
+ RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same
288
+
289
+
290
+
167
291
  ```
168
292
 
169
293
 
170
294
 
171
295
  google colabを使ってpytorchを活用したresnet34の転移学習を上記のコードで行うとしたのですが、エラーが出てしました。どなたか解決策をご教授していただけますか?
172
296
 
297
+ 更新10/28
298
+
299
+
300
+
301
+
302
+
173
303
  ![イメージ説明](464bbe0207ba28e25e34ae3dd26bcd55.png)