エラーがなぜ起こっているのか全く分かりません
わかる方教えてください
試したこと
printしてみましたが原因は不明
バージョンは1.15だったはず
class Actor: def get_action(self, state, episode, targetQN): # [C]t+1での行動を返す # 徐々に最適行動のみをとる、ε-greedy法 epsilon = 0.001 + 0.9 / (1.0 + episode) if epsilon <= np.random.uniform(0, 1): retTargetQs = targetQN.forward(state)[0] action = np.argmax(retTargetQs) # 最大の報酬を返す行動を選択する else: action = np.random.choice([0, 1]) # ランダムに行動する return action device = 'cuda' if torch.cuda.is_available() else 'cpu' mainQN = Network().to(device) optimizer = optim.Adam(mainQN.parameters(), lr=learning_rate) criterion = nn.MSELoss() 略 def forward(self,x,device=device): x=torch.from_numpy(x).to(device) print(x) out = self.dence(x) return out
出ているエラー
tensor([[ 0.0463, 0.1505, 0.0006, -0.2480]], device='cuda:0', dtype=torch.float64) --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-32-24866278c093> in <module> 182 print(state[0, 0]) # カートのx位置を出力するならコメントはずす 183 --> 184 action = actor.get_action(state, episode, mainQN) 185 next_state, reward, done, info = env.step(action) 186 next_state = np.reshape(next_state, [1, 4]) <ipython-input-32-24866278c093> in get_action(self, state, episode, targetQN) 128 129 if epsilon <= np.random.uniform(0, 1): --> 130 retTargetQs = targetQN.forward(state)[0] 131 action = np.argmax(retTargetQs) # 最大の報酬を返す行動を選択する 132 <ipython-input-32-24866278c093> in forward(self, x, device) 45 x=torch.from_numpy(x).to(device) 46 print(x) ---> 47 out = self.dence(x) 48 49 return out ~\Anaconda3\envs\pyflan\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs) 548 result = self._slow_forward(*input, **kwargs) 549 else: --> 550 result = self.forward(*input, **kwargs) 551 for hook in self._forward_hooks.values(): 552 hook_result = hook(self, input, result) ~\Anaconda3\envs\pyflan\lib\site-packages\torch\nn\modules\container.py in forward(self, input) 98 def forward(self, input): 99 for module in self: --> 100 input = module(input) 101 return input 102 ~\Anaconda3\envs\pyflan\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs) 548 result = self._slow_forward(*input, **kwargs) 549 else: --> 550 result = self.forward(*input, **kwargs) 551 for hook in self._forward_hooks.values(): 552 hook_result = hook(self, input, result) ~\Anaconda3\envs\pyflan\lib\site-packages\torch\nn\modules\linear.py in forward(self, input) 85 86 def forward(self, input): ---> 87 return F.linear(input, self.weight, self.bias) 88 89 def extra_repr(self): ~\Anaconda3\envs\pyflan\lib\site-packages\torch\nn\functional.py in linear(input, weight, bias) 1608 if input.dim() == 2 and bias is not None: 1609 # fused op is marginally faster -> 1610 ret = torch.addmm(bias, input, weight.t()) 1611 else: 1612 output = input.matmul(weight.t()) RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #2 'mat1' in call to _th_addmm
あなたの回答
tips
プレビュー