waleedka / hiddenlayer

Neural network graphs and training metrics for PyTorch, Tensorflow, and Keras.
MIT License
1.79k stars 266 forks source link

run time error on yolov3 #37

Open tiru1930 opened 5 years ago

tiru1930 commented 5 years ago

File "getGraph.py", line 13, in graph = hl.build_graph(model, torch.zeros([1,3, 416, 416])).to(device) File "/home/tbaggu/Desktop/20-net-works/hiddenlayer/hiddenlayer/graph.py", line 143, in build_graph import_graph(g, model, args) File "/home/tbaggu/Desktop/20-net-works/hiddenlayer/hiddenlayer/pytorch_builder.py", line 70, in import_graph trace, out = torch.jit.get_trace_graph(model, args) File "/usr/local/lib/python3.5/dist-packages/torch/jit/init.py", line 77, in get_trace_graph return LegacyTracedModule(f)(*args, kwargs) File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 477, in call result = self.forward(*input, kwargs) File "/usr/local/lib/python3.5/dist-packages/torch/jit/init.py", line 109, in forward out = self.inner(trace_inputs) File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 475, in call result = self._slow_forward(input, kwargs) File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 465, in _slow_forward result = self.forward(*input, kwargs) File "/home/tbaggu/Desktop/20-net-works/yolov3/models.py", line 208, in forward x = module[0](x, img_size) File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 475, in call result = self._slow_forward(*input, *kwargs) File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 465, in _slow_forward result = self.forward(input, **kwargs) File "/home/tbaggu/Desktop/20-net-works/yolov3/models.py", line 127, in forward create_grids(self, img_size, (nx, ny), p.device) File "/home/tbaggu/Desktop/20-net-works/yolov3/models.py", line 253, in create_grids self.anchor_vec = self.anchors.to(device) / self.stride RuntimeError: Expected object of type torch.FloatTensor but found type torch.LongTensor for argument #2 'other

Network is taken from https://github.com/ultralytics/yolov3/blob/master/train.py

jveitchmichaelis commented 4 years ago

This works fine for me (using the latest versions of both repos)

data_config = parse_data_cfg(data_config_path)
model = Darknet(net_config_path, 416)
load_darknet_weights(model, weights)

transforms = [
    # Fold Conv, BN, RELU layers into one
    hl.transforms.Fold("Conv > BatchNorm > LeakyRelu", "ConvBnLeakyRelu", "Conv, Bn, LeakyRelu"),
    hl.transforms.Fold("ConvBnLeakyRelu > ConvBnLeakyRelu", "DoubleConv"),
    hl.transforms.Fold("DoubleConv > Add", "Shortcut", "Residual Block"),
    # Fold repeated blocks
    hl.transforms.FoldDuplicates(),
]

graph = hl.build_graph(model, torch.zeros(1,3,416,416), transforms=transforms)
graph = graph.build_dot()
graph.render("./yolov3", view=True, format='pdf')