上側はうまくいくのですが
下側はうまくいきません
上と下で何が違うんですか?
わかる人教えてください
情報が足りなければいってください
pythoch 1.5
python3.7
ここはうまくいく x = torch.randn(1,256,25,25) print("aaaaaaa",x.shape) #結果 torch.Size([1, 256, 25, 25]) x=x.view(-1,1).T print(x.shape) #結果 torch.Size([1, 160000]) こっちはうまくいかない from torch.autograd import Variable class QNetwork(nn.Module): def __init__(self, num_inputs, num_outputs,device): super(QNetwork, self).__init__() 略 self.cnn4 = nn.ModuleList([ nn.Conv2d(64, 128, kernel_size=(3,3), padding=1), 略 nn.Conv2d(256, 256, kernel_size=(3,3), padding=1), nn.Conv2d(256, 256, kernel_size=(3,3), padding=1)]) self.free_net= nn.ModuleList([ nn.Linear(self.hidden_CNN, self.hidden_size1), nn.Linear(self.hidden_size1, self.hidden_size1), nn.Linear(self.hidden_size1, self.hidden_size1)]) def forward(self,inputs,net): 略 for conv in self.cnn4: x = conv(x) x=self.maxpool(x) print(x.shape) #結果torch.Size([1, 256, 25, 25]) x=x.view(-1,1).T for conv in self.free_net: x = conv(x) 略 device = 'cuda' if torch.cuda.is_available() else 'cpu' print(device) mainQN = QNetwork((3,400,400),2,device).to(device) optimizer = optim.Adam(mainQN.parameters(), lr=0.001) mainQN, optimizer = amp.initialize(mainQN, optimizer, opt_level="O1")#-------------- criterion = nn.MSELoss() mainQN.eval() print(mainQN.forward(np.random.rand(1,400,400,3),"v_net"))
出ているエラー
上 aaaaaaa torch.Size([1, 256, 25, 25]) torch.Size([1, 160000]) cuda 下 Defaults for this optimization level are: enabled : True opt_level : O1 cast_model_type : None patch_torch_functions : True keep_batchnorm_fp32 : None master_weights : None loss_scale : dynamic Processing user overrides (additional kwargs that are not None)... After processing overrides, optimization options are: enabled : True opt_level : O1 cast_model_type : None patch_torch_functions : True keep_batchnorm_fp32 : None master_weights : None loss_scale : dynamic torch.Size([1, 256, 25, 25]) --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-7-2bc285428330> in <module> 192 criterion = nn.MSELoss() 193 mainQN.eval() --> 194 print(mainQN.forward(np.random.rand(1,400,400,3),"v_net")) <ipython-input-7-2bc285428330> in forward(self, inputs, net) 155 156 print(x.shape) --> 157 x=x.view(-1,1).T 158 for conv in self.free_net: 159 x = conv(x) RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。