def alternative_evaluation(input_path, output_path, n, log_step=1): device = torch.device( 'cuda') if torch.cuda.is_available() else torch.device('cpu') log = section_logger(0) dataset = AD20kFasterRCNN( '/home/dani/Documentos/Proyectos/Doctorado/Datasets/ADE20K/ADE20K_2016_07_26/ade20ktrain.csv', '/home/dani/Documentos/Proyectos/Doctorado/Datasets/ADE20K/ADE20K_2016_07_26/images/training', transforms=get_transform(train=True)) dataset_test = AD20kFasterRCNN( '/home/dani/Documentos/Proyectos/Doctorado/Datasets/ADE20K/ADE20K_2016_07_26/ade20ktest.csv', '/home/dani/Documentos/Proyectos/Doctorado/Datasets/ADE20K/ADE20K_2016_07_26/images/validation', transforms=get_transform(train=False), labels=dataset.labels, is_test=True) nlp = spacy.load("en_core_web_md") num_classes = len(dataset.labels) model = load_frcnn(input_path, num_classes, device) num_examples = 0 results = [] metaparameters = generate_metaparameters(10, METAPARAMETER_DEF, static=False) for id, objects in enumerate(dataset_test): image = objects[0].to(device) predictions = model([image]) if id % log_step == 0: log("Processing image [{}] with {} predictions and {} boxes". format(id, len(predictions[0]['boxes']), len(objects[1]['boxes']))) for meta_id in range(len(metaparameters['iou_threshold'])): iou_threshold = metaparameters['iou_threshold'][meta_id] nlp_threshold = metaparameters['iou_threshold'][meta_id] wnt_threshold = metaparameters['iou_threshold'][meta_id] partial_results = nlp_evaluation(id, objects, predictions[0], dataset.labels, nlp, iou_threshold=iou_threshold, nlp_threshold=nlp_threshold, wnt_threshold=wnt_threshold) results.append(partial_results) if num_examples < n: num_examples += 1 else: break results_df = pd.concat(results) results_df.to_csv(os.path.join(output_path, 'FRCNN_ad20k_evaluations.csv'))
def test_to_list(self): results = mt.generate_metaparameters(15, INTEGER_DEF_1, static=True) result_list = mt.to_list(results) self.assertEqual(len(result_list), 15) self.assertEqual(list(result_list[0].keys())[0], 'Integer1')
def test_static_generation(self): results = mt.generate_metaparameters(15, INTEGER_DEF_1, static=True) self.assertEqual(len(results['Integer1']), 15) self.assertEqual(sum([e == 5 for e in results['Integer1']]), 15)
def test_generate_multiple_numbers(self): results = mt.generate_metaparameters(10, SMALL_FLOAT_DEF_1) self.assertEqual(len(results['SmallFloat1']), 10)
def test_generate_smallfloats(self): results = mt.generate_metaparameters(1, SMALL_FLOAT_DEF_1) self.assertEqual(len(results['SmallFloat1']), 1) self.assertGreater(results['SmallFloat1'][0], np.power(10, -5.)) self.assertLess(results['SmallFloat1'][0], np.power(10, -1.))
def test_generate_integers(self): results = mt.generate_metaparameters(1, INTEGER_DEF_1) self.assertEqual(len(results['Integer1']), 1) self.assertGreater(results['Integer1'][0], 10) self.assertLess(results['Integer1'][0], 100)