import torch.utils.data from utils.parser import get_parser_with_args from utils.helpers import get_test_loaders from tqdm import tqdm from sklearn.metrics import confusion_matrix parser, metadata = get_parser_with_args() opt = parser.parse_args() dev = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu') test_loader = get_test_loaders(opt) path = 'weights/cam32_e99.pt' # the path of the model model = torch.load(path) c_matrix = {'tn': 0, 'fp': 0, 'fn': 0, 'tp': 0} model.eval() with torch.no_grad(): tbar = tqdm(test_loader) for batch_img1, batch_img2, labels in tbar: batch_img1 = batch_img1.float().to(dev) batch_img2 = batch_img2.float().to(dev) labels = labels.long().to(dev) # Get predictions and calculate loss cd_preds = model(batch_img1, batch_img2) cd_preds = cd_preds[-1] _, cd_preds = torch.max(cd_preds, 1)
import torch.utils.data from utils.parser import get_parser_with_args from utils.helpers import get_test_loaders, initialize_metrics import os from tqdm import tqdm import cv2 if not os.path.exists('./output_img'): os.mkdir('./output_img') parser, metadata = get_parser_with_args() opt = parser.parse_args() dev = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu') test_loader = get_test_loaders(opt, batch_size=1) path = 'weights/snunet-32.pt' # the path of the model model = torch.load(path) model.eval() index_img = 0 test_metrics = initialize_metrics() with torch.no_grad(): tbar = tqdm(test_loader) for batch_img1, batch_img2, labels in tbar: batch_img1 = batch_img1.float().to(dev) batch_img2 = batch_img2.float().to(dev) labels = labels.long().to(dev)