pytorch == 1.9.0 gpu をインストールしたのですが、このエラー生じます。解決方法をどなたか、ご教示の程お願いします。
import torch import torch.nn as nn import torch.nn.functional as F import numpy as np # # 初期重みの関数 def init_weight(size): f = size[0] v = 1. / np.sqrt(f) return torch.tensor(np.random.uniform(low=v, high=v, size=size), dtype=torch.float) class ActorNetwork(nn.Module): def __init__(self, num_state, num_action, hidden1_size=400, hidden2_size=300, init_w=3e-3): super(ActorNetwork, self).__init__() # 各層を線形的に接続 self.fc1 = nn.Linear(num_state[0], hidden1_size) # 1層目の関数定義, 隠れ層400 self.fc2 = nn.Linear(hidden1_size, hidden2_size) # 2層目の関数定義, 隠れ層300 self.fc3 = nn.Linear(hidden2_size, num_action[0]) # 最終層 self.num_state = num_state # 状態変数 self.num_action = num_action # aciton関数 self.fc1.weight.data = init_weight(self.fc1.weight.data.size()) # 1層目の重み self.fc2.weight.data = init_weight(self.fc2.weight.data.size()) # 2層目の重み self.fc3.weight.data.unifrom_(-init_w, init_w) # 最後の層は初期重みの範囲内で重み付け def forward(self, x): h = F.relu(self.fc1(x)) h = F.relu(self.fc2(h)) y = torch.tanh(self.fc3(h)) return y # 評価関数 class CriticNetwork(nn.Module): def __init__(self, num_state, num_action, hidden1_size=400, hidden2_size=300, init_w=3e-6): super(CriticNetwork, self).__init__() self.fc1 = nn.Linear(num_state[0], hidden1_size) self.fc2 = nn.Linear(hidden1_size+num_action[0], hidden2_size) self.fc3 = nn.Linear(hidden2_size, 1) self.num_state = num_state self.num_action = num_action self.fc1.weight.data = init_weight(self.fc1.weight.data.size()) self.fc2.weight.data = init_weight(self.fc2.weight.data.size()) self.fc3.weight.data.unifrom_(-init_w, init_w) def forward(self, x, action): h = F.relu(self.fc1(x)) h = F.relu(self.fc2(torch.cat([h, action], dim=1))) y = self.fc3(h) return y
エラー文
Traceback
1 File "C:/Users/namae/PycharmProjects/pythonProject2/kansetu_2d/model_pendlum.py", line 2, in <module> 2 import torch.nn as nn 3 ModuleNotFoundError: No module named 'torch.nn'; 'torch' is not a package
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。