PyTorch-YOLOv3 icon indicating copy to clipboard operation
PyTorch-YOLOv3 copied to clipboard

There is some problems when read network structures with torchsummary.

Open JeasonUESTC opened this issue 6 years ago • 2 comments

Summary is not a problem, because other networks can be read, and it is possible that a problem with this network code caused an error.

AttributeError Traceback (most recent call last) in () 3 # Set up model 4 model = Darknet(opt.model_def, img_size=opt.img_size).to(device) ----> 5 summary(model, (3, 416, 416))

E:\Program Files\anaconda\lib\site-packages\torchsummary\torchsummary.py in summary(model, input_size, batch_size, device) 70 # make a forward pass 71 # print(x.shape) ---> 72 model(*x) 73 74 # remove these hooks

E:\Program Files\anaconda\lib\site-packages\torch\nn\modules\module.py in call(self, *input, **kwargs) 491 result = self._slow_forward(*input, **kwargs) 492 else: --> 493 result = self.forward(*input, **kwargs) 494 for hook in self._forward_hooks.values(): 495 hook_result = hook(self, input, result)

F:\Pytorch\nut检测\eriklindernoren-PyTorch-YOLOv3\models.py in forward(self, x, targets) 258 x = layer_outputs[-1] + layer_outputs[layer_i] 259 elif module_def["type"] == "yolo": --> 260 x, layer_loss = module[0](x, targets, img_dim) 261 loss += layer_loss 262 yolo_outputs.append(x)

E:\Program Files\anaconda\lib\site-packages\torch\nn\modules\module.py in call(self, *input, **kwargs) 493 result = self.forward(*input, **kwargs) 494 for hook in self._forward_hooks.values(): --> 495 hook_result = hook(self, input, result) 496 if hook_result is not None: 497 raise RuntimeError(

E:\Program Files\anaconda\lib\site-packages\torchsummary\torchsummary.py in hook(module, input, output) 21 if isinstance(output, (list, tuple)): 22 summary[m_key]["output_shape"] = [ ---> 23 [-1] + list(o.size())[1:] for o in output 24 ] 25 else:

E:\Program Files\anaconda\lib\site-packages\torchsummary\torchsummary.py in (.0) 21 if isinstance(output, (list, tuple)): 22 summary[m_key]["output_shape"] = [ ---> 23 [-1] + list(o.size())[1:] for o in output 24 ] 25 else:

AttributeError: 'int' object has no attribute 'size'

Can you give me a hand?

JeasonUESTC avatar Jun 21 '19 14:06 JeasonUESTC

Hello, have you solved this issue? I have the same problem with you!

Narutoluffykid avatar Jul 02 '20 03:07 Narutoluffykid

The problem comes from the YOLOLayer.forward returning both an output tensor and a loss value

You should modify YOLOLayer.forward to return only the output tensor, not the loss value. I added a YOLOLayer.get_current_loss function to support this

marijnl avatar Jul 29 '20 12:07 marijnl