Esempio n. 1
0
# checkpoint_path = '/home/user/Models/Experiment-4/BboxEqualL1L2/pth_files/bbox_464.16_464.16.pth'
checkpoint_path = '/home/user/Models/birds/Experiment-1/Blackout/pth_files/blackout_0.0_0.0.pth'

target_tensor = torch.tensor([35])
num_labels = 200

print('Running...')
transform = transforms.Compose([
    transforms.Resize((height, width)),
    transforms.ToTensor(),
    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])

bbox = BoundingBox(test_folder_path, images_text_file, bounding_box_file, height, width)
# show image and ground-truth bounding box
x1_gt, y1_gt, x2_gt, y2_gt = bbox.get_bbox_from_path(img_path)
orig_img = cv2.imread(img_path)
orig_img = cv2.resize(orig_img, (height, width))
orig_img = cv2.cvtColor(orig_img, cv2.COLOR_BGR2RGB)
cv2.rectangle(orig_img, (int(x1_gt), int(y1_gt)), (int(x2_gt), int(y2_gt)), (0, 255, 0), 2)


model = models.resnet50(pretrained=False)
input_features = model.fc.in_features
model.fc = nn.Linear(input_features, num_labels)

checkpoint = torch.load(checkpoint_path, map_location='cpu')
model.load_state_dict(checkpoint)
model.eval()

criterion = nn.CrossEntropyLoss()