Skip to content

Instantly share code, notes, and snippets.

@monogenea
Created June 19, 2021 10:57
Show Gist options
  • Save monogenea/be8c7fba296acc6a0d86682248254639 to your computer and use it in GitHub Desktop.
Save monogenea/be8c7fba296acc6a0d86682248254639 to your computer and use it in GitHub Desktop.
#%% Load YOLOv3 COCO weights, configs and class IDs
# Import class names
with open('yolov3/coco.names', 'rt') as f:
classes = f.read().rstrip('\n').split('\n')
colors = np.random.randint(0, 255, (len(classes), 3))
# Give the configuration and weight files for the model and load the network using them
cfg = 'yolov3/yolov3.cfg'
weights = 'yolov3/yolov3.weights'
# Load model
model = cv2.dnn.readNetFromDarknet(cfg, weights)
# Extract names from output layers
layersNames = model.getLayerNames()
outputNames = [layersNames[i[0] - 1] for i in model.getUnconnectedOutLayers()]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment