I’m trying to add scheduler ReduceLRonPlateau, following instructions from documentation, but I get error “TypeError: step() missing 1 required positional argument: ‘metrics’” when I run it
Can you please tell me what should I pass to the optimizer?
learning_rate = 0.0001
num_epochs = 300
n_total_steps = len(train_loader)
criterion = nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.0001)
scheduler = ReduceLROnPlateau(optimizer, mode='min', factor=0.5, patience=15, threshold=0.00001)
for epoch in range(num_epochs):
for i, (images, shfl_labels, rot_labels) in enumerate(train_loader):
# Origin shape: image [batch size, 3, 224, 224]
# shfl_labels [batch size, 224, 224]
# rot_labels [batch size, 4, 4]
# Load data in GPU
images = images.to(device)
shfl_labels = shfl_labels.to(device)
rot_labels = rot_labels.to(device)
# Forward pass
shfl_output, rot_output = model(images)
loss_shfl = criterion(shfl_output, shfl_labels.long())
loss_rot = criterion(rot_output, rot_labels.long())
loss = loss_shfl + loss_rot
#Backward pass and optimize
optimizer.zero_grad()
loss.backward()
optimizer.step()
scheduler.step()