This article describes how to quickly build an image retrieval tool based on deep learning.
image_resize.pycan batch resize the images under a certain directory and save them to another directory. Tap
python ./visual_search/tools/image_resize.py -hin the terminal to view the instructions.
usage: image_resize.py [-h] [--input_data_dir INPUT_DATA_DIR] [--output_data_dir OUTPUT_DATA_DIR] [--width WIDTH] [--height HEIGHT] optional arguments: -h, --help show this help message and exit --input_data_dir INPUT_DATA_DIR Directory to put the input data. --output_data_dir OUTPUT_DATA_DIR Directory to put the output data. --width WIDTH Target image width. --height HEIGHT Target image height.
visual_search/myalexnet_feature.pyto extract the feature of each image in the library. This script will output two files: the feature of every image, and the full path of all images.
$ cd visual_search $ python myalexnet_feature.py -h usage: myalexnet_feature.py [-h] [--input_data_dir INPUT_DATA_DIR] [--output_feature_file OUTPUT_FEATURE_FILE] [--output_image_name_file OUTPUT_IMAGE_NAME_FILE] optional arguments: -h, --help show this help message and exit --input_data_dir INPUT_DATA_DIR Directory to put the input data. --output_feature_file OUTPUT_FEATURE_FILE Output features path. --output_image_name_file OUTPUT_IMAGE_NAME_FILE Output image names path.
visual_search/visual_search.py script, you can modify the path of the image feature and the path of the image name for retrieval. The input can be a local image or a picture url.
usage: visual_search.py [-h] [--img_file_path IMG_FILE_PATH] [--img_url IMG_URL] optional arguments: -h, --help show this help message and exit --img_file_path IMG_FILE_PATH Image file path. --img_url IMG_URL Image Url.
You will find several lines of images. Each line is a search record. The input image is the first one of each line. The input images of lines 2 to 5 are obtained by watermarking, rotating, cropping, and mirroring the original image.
In fact, this experimental project took less than a week of my spare time. According to the information I provided, I believe you can make your own image search tool based on deep learning in a short period of time.