teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

Stacktraceを追加しました

2020/10/27 16:52

投稿

TaichiTsujikawa
TaichiTsujikawa

スコア1

title CHANGED
File without changes
body CHANGED
@@ -81,7 +81,72 @@
81
81
  scheduler.step()
82
82
  print(f"epoch {str(epoch).zfill(2)}\ttrain_loss: {train_loss}\tval_loss: {val_loss}\tval_acc: {val_acc}")
83
83
 
84
+ ##以下出現したエラー
85
+ ---------------------------------------------------------------------------
86
+ RuntimeError Traceback (most recent call last)
87
+ <ipython-input-8-2396f00cf9e1> in <module>()
88
+ 3 earlystop_counter = 0
89
+ 4 for epoch in range(100):
90
+ ----> 5 train_loss = training(model, train_dataset, optimizer, loss_func)
91
+ 6 val_loss, val_acc = evaluation(model, val_dataset, loss_func)
92
+ 7
93
+
94
+ 6 frames
95
+ <ipython-input-6-33676f519731> in training(model, dataset, optimizer, loss_func)
96
+ 6 img = img.to("cuda")
97
+ 7 target = target.to("cuda")
98
+ ----> 8 pred = model(img)
99
+ 9 loss = loss_func(pred, target)
100
+ 10 losses.append(loss.item())
101
+
102
+ /usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
103
+ 720 result = self._slow_forward(*input, **kwargs)
104
+ 721 else:
105
+ --> 722 result = self.forward(*input, **kwargs)
106
+ 723 for hook in itertools.chain(
107
+ 724 _global_forward_hooks.values(),
108
+
109
+ /usr/local/lib/python3.6/dist-packages/torchvision/models/resnet.py in forward(self, x)
110
+ 218
111
+ 219 def forward(self, x):
112
+ --> 220 return self._forward_impl(x)
113
+ 221
114
+ 222
115
+
116
+ /usr/local/lib/python3.6/dist-packages/torchvision/models/resnet.py in _forward_impl(self, x)
117
+ 201 def _forward_impl(self, x):
118
+ 202 # See note [TorchScript super()]
119
+ --> 203 x = self.conv1(x)
120
+ 204 x = self.bn1(x)
121
+ 205 x = self.relu(x)
122
+
123
+ /usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
124
+ 720 result = self._slow_forward(*input, **kwargs)
125
+ 721 else:
126
+ --> 722 result = self.forward(*input, **kwargs)
127
+ 723 for hook in itertools.chain(
128
+ 724 _global_forward_hooks.values(),
129
+
130
+ /usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py in forward(self, input)
131
+ 417
132
+ 418 def forward(self, input: Tensor) -> Tensor:
133
+ --> 419 return self._conv_forward(input, self.weight)
134
+ 420
135
+ 421 class Conv3d(_ConvNd):
136
+
137
+ /usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py in _conv_forward(self, input, weight)
138
+ 414 _pair(0), self.dilation, self.groups)
139
+ 415 return F.conv2d(input, weight, self.bias, self.stride,
140
+ --> 416 self.padding, self.dilation, self.groups)
141
+ 417
142
+ 418 def forward(self, input: Tensor) -> Tensor:
143
+
144
+ RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same
145
+
84
146
  ```
85
147
 
86
148
  google colabを使ってpytorchを活用したresnet34の転移学習を上記のコードで行うとしたのですが、エラーが出てしました。どなたか解決策をご教授していただけますか?
149
+ 更新10/28
150
+
151
+
87
152
  ![イメージ説明](464bbe0207ba28e25e34ae3dd26bcd55.png)