示例#1
0
def main():
    torch.manual_seed(args.seed)
    os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu_devices
    use_gpu = torch.cuda.is_available()

    sys.stdout = Logger(osp.join(args.save_dir, 'log_test.txt'))
    print("==========\nArgs:{}\n==========".format(args))

    if use_gpu:
        print("Currently using GPU {}".format(args.gpu_devices))
        cudnn.benchmark = True
        torch.cuda.manual_seed_all(args.seed)
    else:
        print("Currently using CPU (GPU is highly recommended)")
        
    print('Initializing image data manager')
    dm = DataManager(args, use_gpu)
    trainloader, testloader = dm.return_dataloaders()

    model = Model(scale_cls=args.scale_cls, num_classes=args.num_classes)
    # load the model
    checkpoint = torch.load(args.resume)
    model.load_state_dict(checkpoint['state_dict'])
    print("Loaded checkpoint from '{}'".format(args.resume))

    if use_gpu:
        model = model.cuda()

    test(model, testloader, use_gpu)
示例#2
0
                                          num_workers=1,
                                          shuffle=True,
                                          pin_memory=True)

device = torch.device('cuda:0')
model = Model()
model = model.to(device)
imsize = 256, 256

print(f"TestSize = {len(test)}")

for epoch in range(122):
    # TEST
    if epoch % 10 == 0 and epoch > 1:
        print(f"------ EPOCH {epoch} ------")
        model.load_state_dict(
            torch.load(models_path / f"model{epoch}.pth", map_location=device))

        model.eval()

        test_losses_AEE = []
        test_losses_percent_AEE = []

        with torch.no_grad():
            for i_batch, sample_batched in tqdm(enumerate(test_loader)):
                event_images, gt_flow = sample_batched
                event_mask = torch.sum(event_images[:, :2, ...], dim=1)
                event_images = event_images.to(device)

                flow = model.forward(event_images)

                flow = flow.cpu()
示例#3
0
from PIL import Image
from torchvision import transforms
from torch.nn import functional as F
import numpy as np
import cv2
import torch
from net import Model

model = Model(scale_cls=7, num_classes=8)
resume = '/home/lemon/few-shot/fewshot-CAN/ChengR/CAN_ResNet_5_5/temp_Gobal4/model_best.pth.tar'
checkpoint = torch.load(resume)
model.load_state_dict(checkpoint['state_dict'])

# final_convname = 'clasifier'

features_blobs = []


def hook_feature(module, input, output):
    features_blobs.append(output.data.cpu().numpy())


# model._modules.get(final_convname).register_forward_hook(hook_feature)
# print(model.state_dict())
# get the softmax weight
params = list(model.parameters())

weight_softmax = np.squeeze(params[-2].data.numpy())


def returnCAM(feature_conv, weight_softmax, class_idx):
示例#4
0
        outputfile = open(
            '/home/xulzee/Documents/IQA/output/TID2013/vr_jpeg_result.txt',
            'a+')
        outputfile.write(
            ('{} {:.7f} {:.7f}'.format(i, output_txt[0], label_txt[0])) +
            '\r\n')

    outputfile.close()


use_gpu = torch.cuda.is_available()
model = Model()
print('Model structure:', model)

if use_gpu:
    model = model.cuda()

model_weights_file = '/home/xulzee/Documents/IQA/output/TID2013/79-0.0015128param.pth'
model.load_state_dict(torch.load(model_weights_file))
print('load weights from', model_weights_file)

test_dataset = MyDataset(
    data_file='/home/xulzee/Documents/IQA/vr_jpeg.h5')  # test datasets
test_dataloader = DataLoader(dataset=test_dataset,
                             batch_size=1,
                             shuffle=False,
                             num_workers=0)

if __name__ == '__main__':
    test()