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

Darknet not defined #13

Open
berkantay opened this issue Dec 21, 2020 · 2 comments
Open

Darknet not defined #13

berkantay opened this issue Dec 21, 2020 · 2 comments

Comments

@berkantay
Copy link

when I run gen_wts code I get NameError: name 'Darknet' is not defined .

@tjuskyzhang
Copy link
Owner

You can try this branch: git clone -b u3_preview https://github.com/WongKinYiu/PyTorch_YOLOv4.git

@casper-hansen
Copy link

My gen_wts looks like this since the default one did not work for me. I placed it in the scaled yolov4 folder so it has access to the different files it's looking for.

import struct
import sys
from models.models import Darknet
from utils import *
import torch

model = Darknet('models/yolov4-weeds-tiny-3l.cfg', (416, 416))
weights = sys.argv[1]
device = 'cuda:0'
if weights.endswith('.pt'):  # pytorch format
    model.load_state_dict(torch.load(weights, map_location=device)['model'])
else:  # darknet format
    load_darknet_weights(model, weights)

f = open('yolo_tiny_best.wts', 'w')
f.write('{}\n'.format(len(model.state_dict().keys())))
for k, v in model.state_dict().items():
    vr = v.reshape(-1).cpu().numpy()
    f.write('{} {} '.format(k, len(vr)))
    for vv in vr:
        f.write(' ')
        f.write(struct.pack('>f',float(vv)).hex())
    f.write('\n')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants