Jan-05-2019, 07:26 PM
(Jan-05-2019, 06:21 PM)stullis Wrote: Okay, let's track down the problem. Add a print() call to main to see what data is in c:
If the data in c is not what you expect, then review vis_util.visualize_boxes_and_labels_on_image_array() to see what it returns.
1234567891011def
main():
c
=
detected_objects_2()
(c)
for
value
in
c:
if
value
=
=
"turnLeft"
:
(
"Turn Left is working!!!"
)
elif
value
=
=
"turnRight"
:
(
"Turn Right is working!!!"
)
else
:
(
"NO DETECTION at all!!!"
)
I marked the added sides with as Added These with commenting. I only made some small edition to get result to be in my python file
visualization_utils.py function I made small edition
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
def visualize_boxes_and_labels_on_image_array( image, boxes, classes, scores, category_index, instance_masks = None , instance_boundaries = None , keypoints = None , use_normalized_coordinates = False , max_boxes_to_draw = 20 , min_score_thresh = . 5 , agnostic_mode = False , line_thickness = 4 , groundtruth_box_visualization_color = 'black' , skip_scores = False , skip_labels = False ): """Overlay labeled boxes on an image with formatted scores and label names. This function groups boxes that correspond to the same location and creates a display string for each detection and overlays these on the image. Note that this function modifies the image in place, and returns that same image. Args: image: uint8 numpy array with shape (img_height, img_width, 3) boxes: a numpy array of shape [N, 4] classes: a numpy array of shape [N]. Note that class indices are 1-based, and match the keys in the label map. scores: a numpy array of shape [N] or None. If scores=None, then this function assumes that the boxes to be plotted are groundtruth boxes and plot all boxes as black with no classes or scores. category_index: a dict containing category dictionaries (each holding category index `id` and category name `name`) keyed by category indices. instance_masks: a numpy array of shape [N, image_height, image_width] with values ranging between 0 and 1, can be None. instance_boundaries: a numpy array of shape [N, image_height, image_width] with values ranging between 0 and 1, can be None. keypoints: a numpy array of shape [N, num_keypoints, 2], can be None use_normalized_coordinates: whether boxes is to be interpreted as normalized coordinates or not. max_boxes_to_draw: maximum number of boxes to visualize. If None, draw all boxes. min_score_thresh: minimum score threshold for a box to be visualized agnostic_mode: boolean (default: False) controlling whether to evaluate in class-agnostic mode or not. This mode will display scores but ignore classes. line_thickness: integer (default: 4) controlling line width of the boxes. groundtruth_box_visualization_color: box color for visualizing groundtruth boxes skip_scores: whether to skip score when drawing a single detection skip_labels: whether to skip label when drawing a single detection Returns: uint8 numpy array with shape (img_height, img_width, 3) with overlaid boxes. """ # Create a display string (and color) for every box location, group any boxes # that correspond to the same location. box_to_display_str_map = collections.defaultdict( list ) box_to_color_map = collections.defaultdict( str ) box_to_instance_masks_map = {} box_to_instance_boundaries_map = {} box_to_keypoints_map = collections.defaultdict( list ) if not max_boxes_to_draw: max_boxes_to_draw = boxes.shape[ 0 ] for i in range ( min (max_boxes_to_draw, boxes.shape[ 0 ])): if scores is None or scores[i] > min_score_thresh: box = tuple (boxes[i].tolist()) if instance_masks is not None : box_to_instance_masks_map[box] = instance_masks[i] if instance_boundaries is not None : box_to_instance_boundaries_map[box] = instance_boundaries[i] if keypoints is not None : box_to_keypoints_map[box].extend(keypoints[i]) if scores is None : box_to_color_map[box] = groundtruth_box_visualization_color else : display_str = '' if not skip_labels: if not agnostic_mode: if classes[i] in category_index.keys(): class_name = category_index[classes[i]][ 'name' ] #Added These if class_name = = 'turnLeft' : print ( "Turn Left" ) if class_name = = 'turnRight' : print ( "Turn Right" ) else : class_name = 'N/A' display_str = str (class_name) if not skip_scores: if not display_str: display_str = '{}%' . format ( int ( 100 * scores[i])) else : display_str = '{}: {}%' . format (display_str, int ( 100 * scores[i])) box_to_display_str_map[box].append(display_str) if agnostic_mode: box_to_color_map[box] = 'DarkOrange' else : box_to_color_map[box] = STANDARD_COLORS[ classes[i] % len (STANDARD_COLORS)] # Draw all boxes onto image. for box, color in box_to_color_map.items(): ymin, xmin, ymax, xmax = box if instance_masks is not None : draw_mask_on_image_array( image, box_to_instance_masks_map[box], color = color ) if instance_boundaries is not None : draw_mask_on_image_array( image, box_to_instance_boundaries_map[box], color = 'red' , alpha = 1.0 ) draw_bounding_box_on_image_array( image, ymin, xmin, ymax, xmax, color = color, thickness = line_thickness, display_str_list = box_to_display_str_map[box], use_normalized_coordinates = use_normalized_coordinates) if keypoints is not None : draw_keypoints_on_image_array( image, box_to_keypoints_map[box], color = color, radius = line_thickness / 2 , use_normalized_coordinates = use_normalized_coordinates) return image, class_name # #Added These - class_name |
You can check the whole tensorflow models api file which is written in python already: Tensorflow Models API - Models Folder for Object Detection