Simple wrapper functions for Google Object Detection API.
- Download the repository
- Create a 'detection_model_zoo' directory in the extracted repository file
- Download model from Tensorflow detection model zoo
- Copy the downloaded model into 'detection_model_zoo' directory
- Create a file containing the urls of images to be analyzed. This wrapper supports both .csv and .json extensions. (Click link for example format)
- Check the Jupyter notebook for further instructions and examples
- Download the repository
- Select the model to use from Tensorflow detection model zoo
- Create a file containing the urls of images to be analyzed. This wrapper supports both .csv and .json extensions. (Click link for example format)
- Run detect_cm.py in command line with
--downloaded False
. Check below section for more detail
python detect_cm.py --model-name MODEL_NAME --url-file URL_FILE --extension EXTENSION --downloaded DOWNLOADED --do-rescale DO_RESCALE
Example:
python detect_cm.py --model-name faster_rcnn_inception_resnet_v2_atrous_coco_11_06_2017 --url-file Imagenet_sample_images --extension .json --downloaded True --do-rescale False
--model-name
: Name of the model to use. No Default--url-file
: Name of the url file without .json extension. No Default--extension
: Url file file type, .json or .csv. Default: .csv--downloaded
: Indicate whether you have already downloaded model .tar file or not. Wrapper will automatically create 'detection_model_zoo' directory and download model file if set to False. Default: False--do-rescale
: Indicate whether you want to rescale the images or not. Default: False
--width-threshold
: If rescale is set to True, all the images with width size over width threshold will be rescaled to fit width threshold. Default: 500--json-output-file
: Name of the json output file to dump results. Default: output.json--n-threads
: Number of threads to use. Default: 64--visualize
: Indicate whether you want to visualize the results. Default: False--labels
: Path to the label file. Default: object_detection/data/mscoco_label_map.pbtxt
Run python detect_cm.py --help
to see a list of all options.
Successful execution will create a .json file which contains the results of object detection. Contents of the .json file can be read into a dictionary of numpy arrarys with json2dict function in helpers.py. For additional functions for visualization or modification of the results of object detection, look into helpers.py.
- Import detect.py
- Run
detect.object_detect(...)
- The object_detect() function takes the same arguments as command line execution. Look into detect.py for more details
If the execution is successful, the function will return a dictionary of numpy arrays containing the object detection results and create a .json file which contains the results of object detection. Contents of the .json file can be read into a dictionary of numpy arrarys with json2dict function in helpers.py. For additional functions for visualization or modification of the results of object detection, look into helpers.py.
Example:
import detect
model_name = 'faster_rcnn_inception_resnet_v2_atrous_coco_11_06_2017'
url_file = 'Imagenet_sample_images'
extension = '.csv'
downloaded = True
do_rescale = True
width_threshold = 1000
visualize = True
res = detect.object_detect(model_name=model_name, url_file=url_file, extension=extension, downloaded=downloaded, do_rescale=do_rescale, width_threshold=width_thresholdm visualize=visualize)
- Check the function docstring in helpers.py for more info
- .proto files have already been compiled with Protobuf compiler (Protoc)
- This code has been tested with Tensorflow 1.1 on Windows 10
- Original link for Google Tensorflow Object Detection API
- Protobuf compiler download link
- Python 3.5.x
- Tensorflow-gpu >= 1.1
- Scikit-image
- Matplotlib
- Pandas
- Numpy
- 2017/07/04 : Added image rescale function. For some reason, rescaling drops the recognition accuracy by a significant amount, so using this is not recommended until resolved.