コード例 #1
0
ファイル: train.py プロジェクト: michalnand/line_follower_rl
for net in range(nets_to_try):

    epoch_count     = 20
    learning_rates  = [0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.00001, 0.00001]

    model = Model(dataset.training.input_shape, dataset.training.output_shape[0])

    for epoch in range(epoch_count):
        
        batch_size  = 32 
        batch_count = (dataset.training.get_count()+batch_size) // batch_size

        learning_rate = learning_rates[epoch%len(learning_rates)]
        
        optimizer  = torch.optim.Adam(model.parameters(), lr= learning_rate, weight_decay=10**-6)  

        training_loss_sum = 0.0
        for batch_id in range(batch_count):
            training_x, training_y = dataset.training.get_batch(batch_size)

            training_x = training_x.to(model.device)
            training_y = training_y.to(model.device)

            predicted_y = model.forward(training_x)

            loss  = metrics.rms_loss(training_y, predicted_y)
 
            loss.backward()
            optimizer.step()
コード例 #2
0
epoch_count = 100
learning_rates = [
    0.001, 0.001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.00001,
    0.00001
]

model = Model(dataset.training.input_shape, dataset.training.output_shape[0])

for epoch in range(epoch_count):

    batch_size = 32
    batch_count = (dataset.training.get_count() + batch_size) // batch_size

    learning_rate = learning_rates[epoch % len(learning_rates)]

    optimizer = torch.optim.Adam(model.parameters(),
                                 lr=learning_rate,
                                 weight_decay=10**-6)

    training_loss_sum = 0.0
    for batch_id in range(batch_count):
        training_x, training_y = dataset.training.get_batch(batch_size)

        training_x = training_x.to(model.device)
        training_y = training_y.to(model.device)

        predicted_y = model.forward(training_x)

        loss = metrics.rms_loss(training_y, predicted_y)

        loss.backward()