- Aspect ratio needs to be maintained
- Trained for only one type of Object (Vim Dishwasher)
- Trained with just a few images 30 images of train and 5 images of test
- Environment - Windows 10, After all the Setup and Steps, It would take ~45 mins to develop for label, training, and testing
Data Set
- Custom Shelf and Vim dishwash Detection
Image Pre-requisites
- I resized data to 512 x 512 format to be consistent
- Place all images in train and test directory respectively before next steps
Label Training Data
- Img Lab Installation - Refer previous post
- Use Shift key to select rectangle
- Use Alt D to delete region
- Each tool has its own commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1 - Specify XML and image path | |
===================================== | |
E:\Code_Repo\dlib\tools\imglab\build\Release\imglab.exe -c E:\Code_Repo\dlib_obj_count\ShelfData\train\train.xml E:\Code_Repo\dlib_obj_count\ShelfData\train | |
Step 2 | |
======= | |
cd E:\Code_Repo\dlib_obj_count | |
Step 3 | |
======= | |
imglab.exe E:\Code_Repo\dlib_obj_count\ShelfData\train\train.xml |
Label Testing Data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1 | |
======== | |
E:\Code_Repo\dlib\tools\imglab\build\Release\imglab.exe -c E:\Code_Repo\dlib_obj_count\ShelfData\test\test.xml E:\Code_Repo\dlib_obj_count\ShelfData\test | |
Step 2 | |
====== | |
cd E:\Code_Repo\dlib_obj_count | |
Step 3 | |
====== | |
imglab.exe E:\Code_Repo\dlib_obj_count\ShelfData\test\test.xml |
Training Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Base code - https://gist.github.com/atotto/c1ccbfa44ee70a476816f6389834945e | |
#Minor changes for my requirements | |
import os | |
import sys | |
import dlib | |
options = dlib.simple_object_detector_training_options() | |
options.add_left_right_image_flips = False | |
options.C = 5 | |
options.num_threads = 2 | |
options.be_verbose = True | |
training_xml_path = r'E:\Code_Repo\dlib_obj_count\ShelfData\train\train.xml' | |
testing_xml_path = r'E:\Code_Repo\dlib_obj_count\ShelfData\test\test.xml' | |
dlib.train_simple_object_detector(training_xml_path, r'E:\Code_Repo\dlib_obj_count\ShelfData\detector.svm', options) | |
print("") | |
print("Training accuracy") | |
print(dlib.test_simple_object_detector(training_xml_path, r'E:\Code_Repo\dlib_obj_count\ShelfData\detector.svm')) | |
print("Testing accuracy") | |
print(dlib.test_simple_object_detector(testing_xml_path, r'E:\Code_Repo\dlib_obj_count\ShelfData\detector.svm')) | |
Test Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dlib | |
import cv2 | |
detector = dlib.simple_object_detector(r'E:\Code_Repo\dlib_obj_count\ShelfData\detector.svm') | |
filepath = r'E:\Code_Repo\dlib_obj_count\ShelfData\test\25.png' | |
img = cv2.imread(filepath,1) | |
dets = detector(img) | |
for d in dets: | |
cv2.rectangle(img, (d.left(), d.top()), (d.right(), d.bottom()), (0, 0, 255), 2) | |
# Display the resulting frame | |
cv2.imshow("frame",img) | |
cv2.waitKey(0) | |
# When everything done, release the capture | |
cv2.destroyAllWindows() |
Result
No comments:
Post a Comment