Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update demo.py and darknet2pytorch.py #362

Merged
merged 3 commits into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from tool.utils import *
from tool.torch_utils import *
from tool.darknet2pytorch import Darknet
import torch
import argparse

"""hyper parameters"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tool/darknet2pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,12 @@ 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
elif activation == 'logistic':
model.add_module('sigmoid{0}'.format(conv_id), nn.Sigmoid())
else:
print("convalution havn't activate {}".format(activation))
print("No convolutional activation named {}".format(activation))

prev_filters = filters
out_filters.append(prev_filters)
Expand Down