Hi, I still have a problem. When I run this code, I also get a nan error. Then I modified my code to the commented code, it worked. Why wasn’t the previous one working? Thank you in advance.
# Initialize and load Dataset
face_data = FaceAnnoDataset(root_dir=path, img_dir ='image', anno_dir='label', 
                            txtfile='image.txt', transform=transforms.Compose([
                                transforms.ToPILImage(),                                              
                                transforms.Resize((224,224)),
                                transforms.ToTensor(),
                                transforms.Normalize([0.2341, 0.2388, 0.2622], [0.2210, 0.2150, 0.2543])
                                ])
)

train_loader = DataLoader(face_data, batch_size=32, shuffle=False, pin_memory=True,
                         num_workers=2, collate_fn=collate_fn)


optimizer = optim.Adam(model.parameters(), lr=0.0001, betas=(0.9, 0.999), eps=1e-08, weight_decay=0, amsgrad=False)

step_lr_scheduler = lr_scheduler.StepLR(optimizer, step_size=20, gamma=0.85)
-----------------------This outputs a nan loss----------------------------------------------------------------------
model=DetectionNet()
train(model=model, train_loader=train_loader, criterion=loss_fn, optimizer=optimizer, scheduler=step_lr_scheduler, num_epochs=150)
----------------------------------------------------------------------------------------------------------------------------

The following works
#train(model=DetectionNet(), train_loader=train_loader, criterion=loss_fn, optimizer=optimizer, #scheduler=step_lr_scheduler, num_epochs=150)