Created
October 18, 2018 00:26
-
-
Save smoothdvd/3b6a2ceeb35e6ab004002ea8aa694c3d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
for image_path in TEST_IMAGE_PATHS: | |
image = Image.open(image_path) | |
# the array based representation of the image will be used later in order to prepare the | |
# result image with boxes and labels on it. | |
image_np = load_image_into_numpy_array(image) | |
# Expand dimensions since the model expects images to have shape: [1, None, None, 3] | |
image_np_expanded = np.expand_dims(image_np, axis=0) | |
# Actual detection. | |
output_dict = run_inference_for_single_image(image_np, detection_graph) | |
# Visualization of the results of a detection. | |
boxes = output_dict['detection_boxes'] | |
classes = output_dict['detection_classes'] | |
scores = output_dict['detection_scores'] | |
for i in range(boxes.shape[0]): | |
if scores is None or scores[i] > 0.5: | |
box = tuple(boxes[i].tolist()) | |
if classes[i] in category_index.keys(): | |
class_name = category_index[classes[i]]['name'] | |
if class_name == 'dog' or class_name == 'cat': | |
ymin, xmin, ymax, xmax = box | |
im_width, im_height = image.size | |
(left, right, top, bottom) = (xmin * im_width, xmax * im_width, | |
ymin * im_height, ymax * im_height) | |
cropped_image_np = image.crop((left, top, right, bottom)) | |
plt.figure(figsize=IMAGE_SIZE) | |
plt.imshow(cropped_image_np) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment