So i am trying to Run a neural network that tries to detect the YOGA style. I scrapped dataset from google for 13 diiferent YOGA positions. Here is my NN. Kindly help as i am getting this error
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn
dl = torch.utils.data.DataLoader(YogaPoseDataset('classifier_train_data2.csv', trn_tfms,
pose_id_to_name, pose_name_to_id),
bs,
shuffle=True)
model = resnet34(pretrained=True)
model.fc = nn.Linear(512, 14)
model_utils.freeze_all_layers(model)
model = model.to(device)
model.train()
n_epochs = 2
lr = 0.00001
loss_fn = torch.nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(model.parameters(), lr = lr)
print("Fine till here")
total_steps = 0
for e in range(n_epochs):
avg_batch_accuracy = []
for batch, labels in dl:
optimizer.zero_grad()
batch = batch.to(device)
labels = labels.to(device)
print(labels)
preds = model(batch)
print(preds)
loss = loss_fn(preds, labels)
loss.backward()
optimizer.step()
pred_labels = preds.argmax(dim=1)
total_steps +=1
batch_accuracy = (labels == pred_labels).float().mean()
avg_batch_accuracy.append(batch_accuracy.item())
model_utils.print_training_loss_summary(loss.item(), total_steps, e+1, n_epochs, len(dl))
print('avg batch accuracy:{:.2f}'.format(np.array(avg_batch_accuracy).mean()))