From 3cc8db008b98a34b1f0b96cb231aebedba380038 Mon Sep 17 00:00:00 2001 From: Ayrton San Joaquin Date: Tue, 12 Jan 2021 18:46:20 +0800 Subject: [PATCH 1/2] fix linear activation warning --- tool/darknet2pytorch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tool/darknet2pytorch.py b/tool/darknet2pytorch.py index 265b20e4..7f16c181 100644 --- a/tool/darknet2pytorch.py +++ b/tool/darknet2pytorch.py @@ -264,8 +264,10 @@ def create_network(self, blocks): model.add_module('relu{0}'.format(conv_id), nn.ReLU(inplace=True)) elif activation == 'mish': model.add_module('mish{0}'.format(conv_id), Mish()) + elif activation == 'linear': + pass else: - print("convalution havn't activate {}".format(activation)) + print("No convolutional activation named {}".format(activation)) prev_filters = filters out_filters.append(prev_filters) From e88f0a1a1766cf092de2960595076ee4ddaf8fba Mon Sep 17 00:00:00 2001 From: Ayrton San Joaquin Date: Tue, 12 Jan 2021 18:52:24 +0800 Subject: [PATCH 2/2] add torch weights support --- demo.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/demo.py b/demo.py index a8988a59..53f696dd 100644 --- a/demo.py +++ b/demo.py @@ -17,6 +17,7 @@ from tool.utils import * from tool.torch_utils import * from tool.darknet2pytorch import Darknet +import torch import argparse """hyper parameters""" @@ -61,7 +62,10 @@ def detect_cv2_camera(cfgfile, weightfile): m = Darknet(cfgfile) m.print_network() - m.load_weights(weightfile) + if args.torch: + m.load_state_dict(torch.load(weightfile)) + else: + m.load_weights(weightfile) print('Loading weights from %s... Done!' % (weightfile)) if use_cuda: @@ -144,6 +148,8 @@ def get_args(): parser.add_argument('-imgfile', type=str, default='./data/mscoco2017/train2017/190109_180343_00154162.jpg', help='path of your image file.', dest='imgfile') + parser.add_argument('-torch', type=bool, default=false, + help='use torch weights') args = parser.parse_args() return args