Пример #1
0
def train_model(real_model_folder):
    device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

    batch_size = 100
    # basic dataset holder
    mnist = MNIST(device, "flat")
    # creates the dataloader for pytorch
    train_loader = DataLoader(dataset=mnist.train,
                              batch_size=batch_size,
                              shuffle=True)
    validation_loader = DataLoader(dataset=mnist.validation,
                                   batch_size=batch_size,
                                   shuffle=False)
    test_loader = DataLoader(dataset=mnist.test,
                             batch_size=batch_size,
                             shuffle=False)

    real_model_param_path = os.path.join(model_path, real_model_folder,
                                         "PiReal.param.pickle")

    real_param = torch.load(real_model_param_path, map_location="cpu")
    logit_net = PiLogitTanh(real_param, DiscreteWeights.TERNARY)
    logit_net = logit_net.to(device)

    logit_net.train_model(train_loader, validation_loader, test_loader, 200,
                          "MNIST-Pi-Tanh-Ternary", True)
Пример #2
0
def train_model():
    device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

    # basic dataset holder
    mnist = MNIST(device, "2d")
    # creates the dataloader for pytorch
    batch_size = 100

    train_loader = DataLoader(dataset=mnist.train,
                              batch_size=batch_size,
                              shuffle=True)
    validation_loader = DataLoader(dataset=mnist.validation,
                                   batch_size=batch_size,
                                   shuffle=False)
    test_loader = DataLoader(dataset=mnist.test,
                             batch_size=batch_size,
                             shuffle=False)
    net = MnistAlternateDiscreteConv()
    net = net.to(device)

    num_epochs = 100
    # will save metrics and model to disk. returns the path to metrics and saved model
    return net.train_model(train_loader,
                           validation_loader,
                           test_loader,
                           num_epochs,
                           model_name="MNIST-conv-alt-conv")
Пример #3
0
def train_model(real_model_folder):
    device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

    batch_size = 100
    # basic dataset holder
    mnist = MNIST(device, "2d")
    # creates the dataloader for pytorch
    train_loader = DataLoader(dataset=mnist.train,
                              batch_size=batch_size,
                              shuffle=True)
    validation_loader = DataLoader(dataset=mnist.validation,
                                   batch_size=batch_size,
                                   shuffle=False)
    test_loader = DataLoader(dataset=mnist.test,
                             batch_size=batch_size,
                             shuffle=False)

    real_model_param_path = os.path.join(model_path, real_model_folder,
                                         "ConvReal.param.pickle")

    real_param = torch.load(real_model_param_path, map_location="cpu")
    logit_net = ConvLogitSign(real_param, DiscreteWeights.TERNARY)
    logit_net = logit_net.to(device)

    # evaluate first logit model before training, train and evaluate again

    logit_net.train_model(train_loader, validation_loader, test_loader, 200,
                          "MNIST-Conv-Ternary-Sign", True)
Пример #4
0
def train_model():
    device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

    # basic dataset holder
    mnist = MNIST(device, "flat")
    # creates the dataloader for pytorch
    batch_size = 100
    train_loader = DataLoader(dataset=mnist.train,
                              batch_size=batch_size,
                              shuffle=True)
    validation_loader = DataLoader(dataset=mnist.validation,
                                   batch_size=batch_size,
                                   shuffle=False)
    test_loader = DataLoader(dataset=mnist.test,
                             batch_size=batch_size,
                             shuffle=False)

    net = PiReal()
    net = net.to(device)

    num_epochs = 100
    # will save metrics and model to disk
    return net.train_model(train_loader,
                           validation_loader,
                           test_loader,
                           num_epochs,
                           model_name="MNIST-pi-real")
Пример #5
0
def train_model():
    device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

    # basic dataset holder
    mnist = MNIST(device, "2d")
    # creates the dataloader for pytorch
    batch_size = 100
    train_loader = DataLoader(dataset=mnist.train,
                              batch_size=batch_size,
                              shuffle=True)
    validation_loader = DataLoader(dataset=mnist.validation,
                                   batch_size=batch_size,
                                   shuffle=False)
    test_loader = DataLoader(dataset=mnist.test,
                             batch_size=batch_size,
                             shuffle=False)

    net = ConvForcedQuantization()
    net = net.to(device)
    num_epochs = 200

    net.train_model(train_loader, validation_loader, test_loader, num_epochs,
                    "MNIST-Conv-Forced-Quantization")