def main(args=None): if len(sys.argv) is 3: model_path = str(sys.argv[1]) dataset_path = str(sys.argv[2]) else: print( "Pass model path and dataset path in respectively as command line argument" ) exit() from generators.pascal import PascalVocGenerator from model import efficientdet import os os.environ['CUDA_VISIBLE_DEVICES'] = '0' phi = 4 weighted_bifpn = False common_args = { 'batch_size': 1, 'phi': phi, } test_generator = PascalVocGenerator(dataset_path, 'test', shuffle_groups=False, skip_truncated=False, skip_difficult=True, **common_args) model_path = model_path input_shape = (test_generator.image_size, test_generator.image_size) anchors = test_generator.anchors num_classes = test_generator.num_classes() model, prediction_model = efficientdet(phi=phi, num_classes=num_classes, weighted_bifpn=weighted_bifpn) prediction_model.load_weights(model_path, by_name=True) average_precisions = evaluate(test_generator, prediction_model, visualize=False) # compute per class average precision total_instances = [] precisions = [] for label, (average_precision, num_annotations) in average_precisions.items(): print('{:.0f} instances of class'.format(num_annotations), test_generator.label_to_name(label), 'with average precision: {:.4f}'.format(average_precision)) total_instances.append(num_annotations) precisions.append(average_precision) mean_ap = sum(precisions) / sum(x > 0 for x in total_instances) print('mAP: {:.4f}'.format(mean_ap))
} test_generator = PascalVocGenerator('datasets/VOC2007', 'test', shuffle_groups=False, skip_truncated=False, skip_difficult=True, **common_args) model_path = 'checkpoints/2019-12-03/pascal_05_0.6283_1.1975_0.8029.h5' input_shape = (test_generator.image_size, test_generator.image_size) anchors = test_generator.anchors num_classes = test_generator.num_classes() model, prediction_model = efficientdet(phi=phi, num_classes=num_classes, weighted_bifpn=weighted_bifpn) prediction_model.load_weights(model_path, by_name=True) average_precisions = evaluate(test_generator, prediction_model, visualize=False) # compute per class average precision total_instances = [] precisions = [] for label, (average_precision, num_annotations) in average_precisions.items(): print('{:.0f} instances of class'.format(num_annotations), test_generator.label_to_name(label), 'with average precision: {:.4f}'.format(average_precision)) total_instances.append(num_annotations) precisions.append(average_precision) mean_ap = sum(precisions) / sum(x > 0 for x in total_instances) print('mAP: {:.4f}'.format(mean_ap))
weighted_bifpn = False common_args = { 'batch_size': 1, 'phi': phi, } test_generator = PascalVocGenerator( 'datasets/VOC2007', 'test', shuffle_groups=False, skip_truncated=False, skip_difficult=True, **common_args ) model_path = 'checkpoints/2019-12-03/pascal_05_0.6283_1.1975_0.8029.h5' input_shape = (test_generator.image_size, test_generator.image_size) anchors = test_generator.anchors num_classes = test_generator.num_classes() model, prediction_model = efficientdet(phi=phi, num_classes=num_classes, weighted_bifpn=weighted_bifpn) prediction_model.load_weights(model_path, by_name=True) average_precisions = evaluate(test_generator, prediction_model, visualize=False) # compute per class average precision total_instances = [] precisions = [] for label, (average_precision, num_annotations) in average_precisions.items(): print('{:.0f} instances of class'.format(num_annotations), test_generator.label_to_name(label), 'with average precision: {:.4f}'.format(average_precision)) total_instances.append(num_annotations) precisions.append(average_precision) mean_ap = sum(precisions) / sum(x > 0 for x in total_instances) print('mAP: {:.4f}'.format(mean_ap))