def training_data_generator(coco, start_index, num_images, bounding_box_count, cell_width_px, cell_height_px, batch_size): img_ids = get_downloaded_ids() img_ids = list(filter(is_not_greyscale, img_ids))[:num_images] while 1: for img_id in img_ids: image_batch = np.empty((batch_size, 640, 640, 3), np.float) #hard code y_true_batch = np.empty((batch_size, 10, 10, 5), np.float) #hard code for i in range(batch_size): image = file_management.get_image(img_id) image = np.divide(image, 256, dtype=np.float32) try: image = pad_image(image, PADDED_SIZE) except Exception as e: print(id) raise e ground_truth = get_y_true(coco, bounding_box_count, cell_width_px, cell_height_px, img_id) image_batch[i, :, :, :] = image y_true_batch[i, :, :, :] = ground_truth yield (image_batch, y_true_batch)
def image_generator(image_ids, buffer_size=0): for id in image_ids: image = file_management.get_image(id) image = np.divide(image, 256, dtype=np.float32) try: image = pad_image(image, PADDED_SIZE) except Exception as e: print(id) raise e yield image
def plot_annotations(img_id, annotations, color='r'): img = get_image(img_id) fig, ax = plt.subplots() ax.imshow(img) for ann in annotations: rect_patch = patches.Rectangle((ann['bbox'][0], ann['bbox'][1]), ann['bbox'][2], ann['bbox'][3], linewidth=2, edgecolor=ann.get('color', color), facecolor='none') ax.add_patch(rect_patch) plt.show()
) args = vars(ap.parse_args()) # load the trained convolutional neural network print("[INFO] loading network...") # Load in the custom loss function get_custom_objects().update({"QueueTime_loss": QueueTime_loss}) model = load_model(args["model"]) img_ids = args["image_ids"] if args['all']: img_ids = filter(is_not_greyscale, get_downloaded_ids()) for img_id in img_ids: image = pad_image(get_image(img_id), PADDED_SIZE) image = np.expand_dims(image, axis=0) # classify the input image print("[INFO] classifying image...") y_pred = model.predict(image)[0] # post_pred = QueueTime_post_process(y_pred) post_pred = cnn_y_to_absolute(CELL_WIDTH, CELL_HEIGHT, y_pred) # filter out all scores below threshold: post_pred_filtered = list( filter(lambda ann: ann['score'] > 0.001, post_pred)) # Add color key: scores = [ann['score'] for ann in post_pred_filtered] normalize_score = lambda score: (score - min(scores)) / (max(scores) - min(
def is_not_greyscale(img_id): img = get_image(img_id) return img.ndim == 3