MCPcopy
hub / github.com/eriklindernoren/PyTorch-YOLOv3 / load_model

Function load_model

pytorchyolo/models.py:320–344  ·  view source on GitHub ↗

Loads the yolo model from file. :param model_path: Path to model definition file (.cfg) :type model_path: str :param weights_path: Path to weights or checkpoint file (.weights or .pth) :type weights_path: str :return: Returns model :rtype: Darknet

(model_path, weights_path=None)

Source from the content-addressed store, hash-verified

318
319
320def load_model(model_path, weights_path=None):
321 """Loads the yolo model from file.
322
323 :param model_path: Path to model definition file (.cfg)
324 :type model_path: str
325 :param weights_path: Path to weights or checkpoint file (.weights or .pth)
326 :type weights_path: str
327 :return: Returns model
328 :rtype: Darknet
329 """
330 device = torch.device("cuda" if torch.cuda.is_available()
331 else "cpu") # Select device for inference
332 model = Darknet(model_path).to(device)
333
334 model.apply(weights_init_normal)
335
336 # If pretrained weights are specified, start from checkpoint or weight file
337 if weights_path:
338 if weights_path.endswith(".pth"):
339 # Load checkpoint weights
340 model.load_state_dict(torch.load(weights_path, map_location=device))
341 else:
342 # Load darknet weights
343 model.load_darknet_weights(weights_path)
344 return model

Callers 3

runFunction · 0.90
evaluate_model_fileFunction · 0.90
detect_directoryFunction · 0.90

Calls 2

DarknetClass · 0.85
load_darknet_weightsMethod · 0.80

Tested by 1

evaluate_model_fileFunction · 0.72