コード例 #1
0
def train_and_evaluate():
    # Just for measure the performance of the sentiment analysis model
    net = SoundMLP()
    net.to(config['device'])
    train_loader, test_loader = get_train_loaders()
    train_model(net, train_loader, epochs=30, lr=0.0001)
    eval_network(net, test_loader)
コード例 #2
0
def train_and_evaluate():
    net = get_pretrained_mobile_net(pretrained=True)
    net.to(config['device'])
    train_loader, test_loader, deploy_loader = get_oasis_dataset_loaders()

    for i in range(10):
        print(i * 5)
        train_model(net, train_loader, epochs=5, lr=0.0001, train_type='image')
        eval_network(net, test_loader, train_type='image')
コード例 #3
0
def validate_saved_model():
    train_loader = get_deploy_loaders()

    model = SoundMLP()
    model.to(config['device'])
    model.load_neural_model("models/mlp.model")
    model.load_neural_space_statistics("models/space_statistics.pickle")

    eval_network(model, train_loader)

    print("Mean = ", model.mean)
    print("Std = ", model.std)
コード例 #4
0
def train_and_evaluate():
    net = NeuralTranslator()
    net.to(config['device'])
    train_loader, test_loader = get_train_loaders(n_clusters=10,
                                                  seed=1,
                                                  n_sub_classes=10)

    train_model(net,
                train_loader,
                epochs=200,
                lr=0.001,
                train_type='translator')
    eval_network(net, train_loader, train_type='translator')
    eval_network(net, test_loader, train_type='translator')
コード例 #5
0
def train_custom_id(imagenet_ids, i):
    train_loader = get_deploy_loaders(ids=imagenet_ids[i], n_sub_classes=10)

    net = NeuralTranslator()
    net.to(config['device'])

    train_model(net,
                train_loader,
                epochs=200,
                lr=0.001,
                train_type='translator')
    eval_network(net, train_loader, train_type='translator')
    torch.save(net.state_dict(),
               "models/neural_translator_custom_" + str(i) + ".model")

    net = NeuralTranslator()
    net.to(config['device'])
    net.load_state_dict(
        torch.load("models/neural_translator_custom_" + str(i) + ".model"))
    eval_network(net, train_loader, train_type='translator')
コード例 #6
0
def train_deploy(seed=1):
    train_loader = get_deploy_loaders(n_clusters=10,
                                      seed=seed,
                                      n_sub_classes=10)

    net = NeuralTranslator()
    net.to(config['device'])

    train_model(net,
                train_loader,
                epochs=200,
                lr=0.001,
                train_type='translator')
    eval_network(net, train_loader, train_type='translator')
    torch.save(net.state_dict(),
               "models/neural_translator_" + str(seed) + ".model")

    net = NeuralTranslator()
    net.to(config['device'])
    net.load_state_dict(
        torch.load("models/neural_translator_" + str(seed) + ".model"))
    eval_network(net, train_loader, train_type='translator')
コード例 #7
0
def train_deploy():
    train_loader, test_loader, deploy_loader = get_oasis_dataset_loaders()

    net = get_pretrained_mobile_net(pretrained=True)
    net.to(config['device'])

    train_model(net, deploy_loader, epochs=50, lr=0.0001, train_type='image')
    eval_network(net, test_loader, train_type='image')
    train_model(net, deploy_loader, epochs=10, lr=0.00001, train_type='image')
    eval_network(net, test_loader, train_type='image')
    torch.save(net.state_dict(), "models/image_sentiment.model")

    model = get_pretrained_mobile_net(pretrained=True)
    model.to(config['device'])
    model.load_state_dict(torch.load("models/image_sentiment.model"))
    eval_network(model, test_loader, train_type='image')
コード例 #8
0
def train_deploy():
    train_loader = get_deploy_loaders()

    net = SoundMLP()
    net.to(config['device'])

    train_model(net, train_loader, epochs=30, lr=0.0001)
    eval_network(net, train_loader)
    train_model(net, train_loader, epochs=20, lr=0.00001)
    eval_network(net, train_loader)

    torch.save(net.state_dict(), "models/mlp.model")

    model = SoundMLP()
    model.to(config['device'])
    model.load_state_dict(torch.load("models/mlp.model"))

    eval_network(model, train_loader)