Skip to content

Instantly share code, notes, and snippets.

@evergreenllc2020
Created January 11, 2020 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evergreenllc2020/dd4feca0b3f7393222935dbcacebaa57 to your computer and use it in GitHub Desktop.
Save evergreenllc2020/dd4feca0b3f7393222935dbcacebaa57 to your computer and use it in GitHub Desktop.
Object detection Model Training
# loop over the image paths
for imagePath in paths.list_images(args["class"]):
# extract the image ID from the image path and load the annotations file
imageID = imagePath[imagePath.rfind("/") + 1:].split("_")[1]
imageID = imageID.replace(".jpg", "")
p = "{}/annotation_{}.mat".format(args["annotations"], imageID)
annotations = loadmat(p)["box_coord"]
# loop over the annotations and add each annotation to the list of bounding
# boxes
bb = [dlib.rectangle(left=long(x), top=long(y), right=long(w), bottom=long(h))
for (y, h, x, w) in annotations]
boxes.append(bb)
# add the image to the list of images
images.append(io.imread(imagePath))
# train the object detector
print("[INFO] training detector...")
detector = dlib.train_simple_object_detector(images, boxes, options)
# dump the classifier to file
print("[INFO] dumping classifier to file...")
detector.save(args["output"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment