Ejemplo n.º 1
0
# -*- coding: utf-8 -*-
import torch
import torch.nn as nn
from model.networkmodel import NetworkModel
from model.resnet import ResNet
from model.resnet import BasicBlock
import torch.optim as optim
from CTData import dataloader
import time
import numpy as np

if __name__ == "__main__":

    resnet18_model = ResNet(BasicBlock, [2, 2, 2, 2])
    resnet18_model.load_state_dict(
        torch.load("./weights/resnet18-5c106cde.pth"))
    model = NetworkModel(pretrained_net=resnet18_model, n_class=1)

    fcn_model = model.cuda()
    criterion = nn.BCELoss().cuda()
    # optimizer = optim.SGD(fcn_model.parameters(), lr=1e-2, momentum=0.7)

    optimizer = optim.Adam(fcn_model.parameters(), lr=1e-4)

    for epo in range(20):
        index = 0
        epo_loss = 0

        for item in dataloader:

            # time_end = time.time()
Ejemplo n.º 2
0
                                                transform=transform_test)
        num_classes = 100

    testloader = torch.utils.data.DataLoader(testset,
                                             batch_size=args.bs,
                                             shuffle=False,
                                             num_workers=2)

    # Model
    print('\n[Phase 2] : Model setup')
    print('| Building net type [' + args.net + ']...')
    if args.net == 'resnet34':
        net = ResNet(34, num_classes, 0.5)
    elif args.net == 'densenet':
        net = DenseNet3(100, num_classes, 12, 0.5, True, 0.2)
    elif args.net == 'vgg16':
        net = VGGNet(num_classes, 0.5, False, 2048, True)
    else:
        print('Error : Network should be either [ResNet34]')
        sys.exit(0)

    checkpoint = torch.load(args.model_path)
    net.load_state_dict(checkpoint['model'])
    net.to(device)

    avg = 0

    for i in range(10):
        avg += test(net, testloader)

    print(avg / 10)