def inference(model, dataset, limit):
    'Run detection on images in the given directory.'
    if (not os.path.exists(RESULTS_DIR)):
        os.makedirs(RESULTS_DIR)
    time_dir = '{:%Y%m%dT%H%M%S}'.format(datetime.datetime.now())
    time_dir = os.path.join(RESULTS_DIR, time_dir)
    os.makedirs(time_dir)
    for image_id in dataset.image_ids[:limit]:
        image = dataset.load_image(image_id)
        r = model.detect([image], verbose=0)[0]
        source_id = dataset.image_info[image_id]['id']
        if (len(r['class_ids']) > 0):
            print('[*] {}th image has {} instance(s).'.format(image_id, len(r['class_ids'])))
            visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'], dataset.class_names, r['scores'], show_bbox=True, show_mask=True, title='Predictions')
            plt.savefig('{}/{}'.format(time_dir, dataset.image_info[image_id]['id']))
            plt.close()
        else:
            plt.imshow(image)
            plt.savefig('{}/noinstance_{}'.format(time_dir, dataset.image_info[image_id]['id']))
            print('[*] {}th image have no instance.'.format(image_id))
            plt.close()
Run detection on images in the given directory.
def inference(model, dataset, limit):
    
    if (not os.path.exists(RESULTS_DIR)):
        os.makedirs(RESULTS_DIR)
    time_dir = '{:%Y%m%dT%H%M%S}'.format(datetime.datetime.now())
    time_dir = os.path.join(RESULTS_DIR, time_dir)
    os.makedirs(time_dir)
    for image_id in dataset.image_ids[:limit]:
        image = dataset.load_image(image_id)
        r = model.detect([image], verbose=0)[0]
        source_id = dataset.image_info[image_id]['id']
        if (len(r['class_ids']) > 0):
            print('[*] {}th image has {} instance(s).'.format(image_id, len(r['class_ids'])))
            visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'], dataset.class_names, r['scores'], show_bbox=True, show_mask=True, title='Predictions')
            plt.savefig('{}/{}'.format(time_dir, dataset.image_info[image_id]['id']))
            plt.close()
        else:
            plt.imshow(image)
            plt.savefig('{}/noinstance_{}'.format(time_dir, dataset.image_info[image_id]['id']))
            print('[*] {}th image have no instance.'.format(image_id))
            plt.close()