Esempio n. 1
0
def im_detect(sess, net, im, timers, im_idx=None, nbr_gts=None):

  # Setup image blob
  blobs = {}
  blobs['data'], im_scales, blobs['im_shape_orig'] = get_image_blob(im)
  im_blob = blobs['data']
  blobs['im_info'] = np.array([im_blob.shape[1], im_blob.shape[2], im_scales[0]])

  # Run drl-RPN
  scores, pred_bboxes, timers, stats \
    = run_drl_rpn(sess, net, blobs, timers, 'test', cfg.DRL_RPN_TEST.BETA,
                  im_idx, nbr_gts)

  return scores, pred_bboxes, timers, stats
Esempio n. 2
0
def im_detect(sess, net, im, timers, im_idx=None, nbr_gts=None):
    # Setup image blob
    blobs = {}
    blobs['data'], im_scales, blobs['im_shape_orig'] = get_image_blob(im)
    im_blob = blobs['data']
    blobs['im_info'] = np.array(
        [im_blob.shape[1], im_blob.shape[2], im_scales[0]])

    # Run LRP-HAI
    scores, pred_bboxes, timers, stats \
        = run_LRP_HAI(sess, net, blobs, timers, 'test', cfg.LRP_HAI_TEST.BETA,
                      im_idx, nbr_gts, alpha=cfg.LRP_HAI.ALPHA)

    return scores, pred_bboxes, timers, stats
Esempio n. 3
0
def visualize(im, im_idx, boxes, show_text=True):

    # Setup image blob
    blob = {}
    blob['data'], im_scales, blob['im_shape_orig'] = get_image_blob(im)
    im_blob = blob['data']
    im_shape = blob['im_shape_orig']
    blob['im_info'] = np.array(
        [im_blob.shape[1], im_blob.shape[2], im_scales[0]])
    im_info = blob['im_info']

    # Make sure image in right range
    im = im_blob[0, :, :, :]
    im -= np.min(im)
    im /= np.max(im)
    im = resize(im, (im_shape[0], im_shape[1]), order=1, mode='reflect')

    # BGR --> RGB
    im = im[..., ::-1]

    # Produce final detections post-NMS
    cls_dets, names_and_coords = produce_trusted_boxes(boxes, thresh=0.70)

    # Show image
    fig, ax = plt.subplots(1)
    ax.imshow(im)

    # Draw all detection boxes
    for j in range(len(names_and_coords)):

        coords = names_and_coords[j]['coords']
        score = names_and_coords[j]['score']
        name = names_and_coords[j]['class_name']
        color = names_and_coords[j]['color']
        cls_det = cls_dets[j]

        # Show object category + confidence
        if show_text:
            ax.text(coords[0],
                    coords[1],
                    name + " " + str(score),
                    weight='bold',
                    color='black',
                    fontsize=8,
                    horizontalalignment='center',
                    verticalalignment='center',
                    bbox=dict(facecolor='white', edgecolor='white', pad=-0.1))

        # Show detection bounding boxes
        rect = patches.Rectangle((cls_det[0], cls_det[1]),
                                 cls_det[2] - cls_det[0],
                                 cls_det[3] - cls_det[1],
                                 linewidth=7,
                                 edgecolor=color,
                                 facecolor='none')
        ax.add_patch(rect)

    # Final save / close of figure
    im_name = 'im' + str(im_idx + 1) + '.jpg'
    plt.savefig('img-out-deepSORT/' + im_name)
    plt.close()

    # Display success message
    print("Saved image " + im_name + "!\n")