Search code examples
pythonpytorchobject-detectiontorchtorchvision

AttributeError: module 'torch.optim.lr_scheduler' has no attribute 'LinearLR'


I'm trying to train my own object detection model with Pytorch. But im getting always this error. I tried to change the torch version but this doesn't helped.
My packages: torchvision-0.11.1 and torch-1.10.0

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-9e52b782b448> in <module>()
      4 for epoch in range(num_epochs):
      5     # training for one epoch
----> 6     train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq=10)
      7     # update the learning rate
      8     lr_scheduler.step()

/content/engine.py in train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq)
     21         warmup_iters = min(1000, len(data_loader) - 1)
     22 
---> 23         lr_scheduler = torch.optim.lr_scheduler.LinearLR(
     24             optimizer, start_factor=warmup_factor, total_iters=warmup_iters
     25         )

AttributeError: module 'torch.optim.lr_scheduler' has no attribute 'LinearLR'

Solution

  • LinearLR scheduler was only recently introduced (v1.10.0). Please make sure your pytorch version is up to date and try again.