-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_evaluation.py
66 lines (51 loc) · 1.81 KB
/
test_evaluation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import numpy as np
from evaluation import EvaluationMetrics
from dataloader import ImageDataset
from panet import PanNet
import torch
from torch.utils.data import DataLoader
import pandas as pd
import pickle
csv_path = "/Users/aniruddha/Downloads/DL_info.csv"
Image_slices_dir = "/Users/aniruddha/Downloads/Test"
df = pd.read_csv(csv_path) # The DL_info.csv file path
df.sort_values("File_name", inplace=True)
df.drop_duplicates(subset="File_name",
keep=False, inplace=True)
new_df = df[df['Train_Val_Test'] == 3]
model = PanNet()
model.load_state_dict(torch.load('/Users/aniruddha/Downloads/panet_model_4.dms'))
eval1 = EvaluationMetrics()
map_scores_list = []
eval1 = EvaluationMetrics()
for i in range(1, 9):
batch_no = 0
train_dataset = ImageDataset(
root_dir="/Users/aniruddha/Downloads/Test", dataset_type=3)
# Set the new_df yourself
print("Original length is", len(new_df.index))
loop_df = new_df[new_df['Coarse_lesion_type'] == i]
train_dataset.df = loop_df
batch_size = 3
dataloader = DataLoader(dataset=train_dataset, batch_size=batch_size)
bbox_global = None
bbox_pred_global = None
print(len(dataloader))
start = True
count = 0
for batch in dataloader:
img = batch['image']
bbox = batch['lesions']
bbox_pred = model(img)
count += 1
if start:
bbox_global = bbox
bbox_pred_global = bbox_pred
start = False
else:
bbox_global = torch.cat((bbox_global, bbox), dim=0)
bbox_pred_global = torch.cat((bbox_pred_global, bbox_pred), dim=0)
print(count)
map_scores_list.append(eval1.mean_average_precision(
bbox=bbox_global, bbox_pred=bbox_pred_global))
pickle.dump(map_scores_list, open('map_scores_list.p','wb'))