Skip to content

Commit b011597

Browse files
authoredMay 5, 2020
Update yolo_utils.py
Added docstring
1 parent c8d80ba commit b011597

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed
 

‎yolo_utils.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
import cv2
12
import numpy as np
23
import os
3-
import cv2
44

55
import torch
66
import torch.nn as nn
77
import torch.nn.functional as F
8-
from torch.autograd import Variable
98

109

1110
def to_cpu(tensor):
1211
return tensor.detach().cpu()
1312

1413
def xywh2xyxy(x):
14+
''' Convert bounding box from [x, y, w, h] to [x1, y1, x2, y2]
15+
:param x: bounding boxes array
16+
:return: Converted bounding box array
17+
'''
1518
y = x.new(x.shape)
1619
y[..., 0] = x[..., 0] - x[..., 2] / 2
1720
y[..., 1] = x[..., 1] - x[..., 3] / 2
@@ -470,6 +473,10 @@ def save_darknet_weights(self, path, cutoff=-1):
470473
fp.close()
471474

472475
def prepare_yolo(model_dir):
476+
''' Download yolo model files and load the model weights
477+
:param model_dir: Directory path where to store yolo model weights and yolo model configuration file.
478+
:return: Yolo model after loading model weights
479+
'''
473480
cfg_file = os.path.join(model_dir, 'yolov3.cfg')
474481
if not os.path.exists(cfg_file):
475482
download_command = 'wget https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov3.cfg -O ' + cfg_file

0 commit comments

Comments
 (0)
Please sign in to comment.