# Store the predictions for ind in range(num_images_chunk): if model_name == 'yolo' or model_name == 'tiny-yolo': boxes_pred = yolo_postprocess_net_out(net_out[ind], priors, classes, detection_threshold, nms_threshold) else: priors = pickle.load(open('prior_boxes_ssd300.pkl', 'rb')) real_num_classes = num_classes - 1 # Background is not included bbox_util = BBoxUtility(real_num_classes, priors=priors, nms_thresh=nms_threshold) boxes_pred = bbox_util.detection_out( net_out[ind], background_label_id=0, confidence_threshold=detection_threshold) current_img = images[ind] if 'yolo' in model_name: current_img = np.transpose(current_img, (1, 2, 0)) plt.imshow(current_img) currentAxis = plt.gca() # Compute number of predictions that match with GT with a minimum of 50% IoU for b in boxes_pred: pred_idx = np.argmax(b.probs) # Do not count as prediction if it is below the detection threshold or in the ignore list if (b.probs[pred_idx] < detection_threshold) or (pred_idx in ignore_class):
for i,img_path in enumerate(imfiles): img = image.load_img(img_path, target_size=(input_shape[0], input_shape[1])) img = image.img_to_array(img) img = img / 255. inputs.append(img.copy()) img_paths.append(img_path) if len(img_paths)%chunk_size == 0 or i+1 == len(imfiles): inputs = np.array(inputs) start_time = time.time() net_out = model.predict(inputs, batch_size=16, verbose=1) print ('{} images predicted in {:.5f} seconds. {:.5f} fps').format(len(inputs),time.time() - start_time,(len(inputs)/(time.time() - start_time))) total_fps = total_fps + len(inputs)/(time.time() - start_time) # predicted boxes results = bbox_util.detection_out(net_out) for i,img_path in enumerate(img_paths): # load ground truth boxes_true = [] label_path = img_path.replace('jpg','txt') gt = np.loadtxt(label_path) if len(gt.shape) == 1: gt = gt[np.newaxis,] for j in range(gt.shape[0]): bx = BoundBox(len(classes)) bx.probs[int(gt[j,0])] = 1. box = gt[j,:] bx.xmin = box[1] - box[3]/2 bx.ymin = box[2] - box[4]/2 bx.xmax = box[1] + box[3]/2 bx.ymax = box[2] + box[4]/2