UnboundLocalError: local variable 'labels' referenced before assignment in PyTorch while doing X-Ray classification
I am trying to replicate this Kaggle notebook, using my data. I am not posting the whole code here, because it is huge.
Received an error, which cannot fix myself
----&gt; 2 model, history = run_fold(model, criterion, optimizer, scheduler, device=CFG.device, fold=0, num_epochs=CFG.num_epochs)

1 frames
&lt;ipython-input-63-1ac8b53f265b&gt; in train_model(model, criterion, optimizer, scheduler, num_epochs, 
dataloaders, dataset_sizes, device, fold)
 23             for inputs, classes in dataloaders[phase]:
 24                 inputs = inputs.to(CFG.device)
---&gt; 25                 labels = labels.to(CFG.device)
 26 
 27                 # forward

UnboundLocalError: local variable 'labels' referenced before assignment

My data structure looks the same as the notebook

I have checked similar questions, there are several of them, but this is more tech question how to fix this thing. Maybe something wrong with index? Appreciate any tips.

There is a typo in the for loop. It should be labels instead of classes:
# ...
for inputs, labels in dataloaders[phase]:
    inputs = inputs.to(CFG.device)
    labels = labels.to(CFG.device)
    # ...

