Python 3.5, CUDA 9.0, cudnn 7.3.1 and other common packages listed in requirements.txt
.
pip install -r requirements.txt
python setup.py build_ext --inplace
download data from https://pjreddie.com/media/files/yolov2.weights
Make /bin directory from root and put the weights file into the bin. Please rename yolov2.weights to yolo.weights.
import cv2
from darkflow.net.build import TFNet
import matplotlib.pyplot as plt
# define the model options and run
options = {
'model': 'cfg/yolo.cfg',
'load': 'bin/yolo.weights',
'threshold': 0.3,
'gpu': 1.0
}
tfnet = TFNet(options)
# read the color image and covert to RGB
img = cv2.imread('dog.png', cv2.IMREAD_COLOR)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# use YOLO to predict the image
result = tfnet.return_predict(img)
img.shape
# pull out some info from the results
tl = (result[0]['topleft']['x'], result[0]['topleft']['y'])
br = (result[0]['bottomright']['x'], result[0]['bottomright']['y'])
label = result[0]['label']
# add the box and label and display it
img = cv2.rectangle(img, tl, br, (0, 255, 0), 7)
img = cv2.putText(img, label, tl, cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 0), 2)
plt.imshow(img)
plt.show()