Spaces:
Runtime error
Runtime error
Upload hubconf.py
Browse files- hubconf.py +37 -0
hubconf.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
dependencies = ["efficientnet_pytorch", "pretrainedmodels",
|
| 2 |
+
"timm", "torch", "torchvision"]
|
| 3 |
+
import torch
|
| 4 |
+
from utils.utils import Params
|
| 5 |
+
from backbone import HybridNetsBackbone
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def hybridnets(pretrained=True, compound_coef=3, device='cpu'):
|
| 11 |
+
"""Creates a HybridNets model
|
| 12 |
+
|
| 13 |
+
Arguments:
|
| 14 |
+
pretrained (bool): load pretrained weights into the model
|
| 15 |
+
compound_coef (int): compound coefficient of efficientnet backbone
|
| 16 |
+
device (str): 'cuda:0' or 'cpu'
|
| 17 |
+
|
| 18 |
+
Returns:
|
| 19 |
+
HybridNets model
|
| 20 |
+
"""
|
| 21 |
+
params = Params(os.path.join(Path(__file__).resolve().parent, "projects/bdd100k.yml"))
|
| 22 |
+
model = HybridNetsBackbone(num_classes=len(params.obj_list), compound_coef=compound_coef,
|
| 23 |
+
ratios=eval(params.anchors_ratios), scales=eval(params.anchors_scales),
|
| 24 |
+
seg_classes=len(params.seg_list))
|
| 25 |
+
if pretrained and compound_coef == 3:
|
| 26 |
+
weight_url = 'https://github.com/datvuthanh/HybridNets/releases/download/v1.0/hybridnets.pth'
|
| 27 |
+
model.load_state_dict(torch.hub.load_state_dict_from_url(weight_url, map_location=device))
|
| 28 |
+
model = model.to(device)
|
| 29 |
+
return model
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
model = hybridnets(device='cpu')
|
| 34 |
+
img = torch.rand(1, 3, 384, 640)
|
| 35 |
+
|
| 36 |
+
result = model(img)
|
| 37 |
+
print(result)
|