Example #1
0
    def __init__(self, n_epochs, lr):
        self.n_epochs = n_epochs
        self.lr = lr

        self.datasets, self.dataloaders = get_ds_loaders()
        self.model = CustomNet().to(device)
        self.criterion = torch.nn.CrossEntropyLoss()

        self.build_opt()
        self.vis = Visualizer()
Example #2
0
    def __init__(self, lr, n_epochs):
        self.criterion = nn.CrossEntropyLoss()
        self.n_epochs = n_epochs
        self.lr = lr

        self.build_net()
        self.build_opt()

        self.datasets, self.dataloaders = get_ds_loaders()

        self.vis = Visualizer()
Example #3
0
# Device configuration
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

resnet_origin = resnet18(pretrained=True)  # original ResNet
without_fc = nn.Sequential(*list(resnet_origin.children())[:-1]).to(
    device)  # removing last FC layer from ResNet
resnet_ft = torch.load(
    "../01_modify_last_FC_layer/ResNet18_CIFAR10_finetuned.pth",
    map_location='cpu')  # finetuning last FC layer with 10 classes

# print(resnet_origin)
# print(without_fc)
# print(resnet_ft)

datasets, dataloaders = get_ds_loaders()

for images, labels in dataloaders['train']:
    images = images.to(device)
    labels = labels.to(device)

    out1 = resnet_origin(images)
    print("ResNet original", out1.shape)  # 100, 1000

    out2 = without_fc(images)
    print("Without FC layer", out2.shape)  # 100, 512, 1, 1

    out3 = resnet_ft(images)
    print("Finetuned FC layer", out3.shape)  # 100, 10
    break
Example #4
0
    def __init__(self, ckpt_path):
        self.ckpt_path = ckpt_path
        self.datasets, self.dataloaders = get_ds_loaders()

        self.build_net()
        self.load_trained_model()