chakshu12345 commited on
Commit
0b2f750
·
1 Parent(s): 1329cff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -16
app.py CHANGED
@@ -182,31 +182,19 @@ def train_main(train_loader, test_loader, num_epochs, optimizer, model, device='
182
  test_accs.append(test_acc)
183
  print('Epoch: {}, train loss: {:.4f}, test loss: {:.4f}, train accuracy: {:.2f}%, test accuracy: {:.2f}%'.format(epoch+1, train_loss, test_loss, train_acc, test_acc))
184
  print("Saving the model")
185
- torch.save(model, 'trained_model.pt')
186
  print("Model saved successfully")
187
  # save the results to a text file
188
 
189
  print("Saving training logs")
190
- with open("results.txt", "w") as f:
191
  for epoch in range(num_epochs):
192
  f.write("Epoch: {}, train loss: {:.4f}, test loss: {:.4f}, train accuracy: {:.2f}%, test accuracy: {:.2f}%\n".format(epoch+1, train_losses[epoch], test_losses[epoch], train_accs[epoch], test_accs[epoch]))
193
  print("Logs saved")
194
- # plot the loss and accuracy curves side by side
195
- fig, axs = plt.subplots(1, 2, figsize=(12, 4))
196
- axs[0].plot(train_losses, label='Train Loss')
197
- axs[0].plot(test_losses, label='Test Loss')
198
- axs[0].set_xlabel('Epoch')
199
- axs[0].set_ylabel('Loss')
200
- axs[0].legend()
201
- axs[1].plot(train_accs, label='Train Accuracy')
202
- axs[1].plot(test_accs, label='Test Accuracy')
203
- axs[1].set_xlabel('Epoch')
204
- axs[1].set_ylabel('Accuracy')
205
- axs[1].legend()
206
- plt.savefig('loss_and_accuracy.png')
207
 
208
 
209
- num_epochs=3
210
  train_main(train_loader, test_loader, num_epochs, optimizer, model, device)
211
 
212
 
 
182
  test_accs.append(test_acc)
183
  print('Epoch: {}, train loss: {:.4f}, test loss: {:.4f}, train accuracy: {:.2f}%, test accuracy: {:.2f}%'.format(epoch+1, train_loss, test_loss, train_acc, test_acc))
184
  print("Saving the model")
185
+ torch.save(model, './trained_model.pt')
186
  print("Model saved successfully")
187
  # save the results to a text file
188
 
189
  print("Saving training logs")
190
+ with open("./results.txt", "w") as f:
191
  for epoch in range(num_epochs):
192
  f.write("Epoch: {}, train loss: {:.4f}, test loss: {:.4f}, train accuracy: {:.2f}%, test accuracy: {:.2f}%\n".format(epoch+1, train_losses[epoch], test_losses[epoch], train_accs[epoch], test_accs[epoch]))
193
  print("Logs saved")
194
+
 
 
 
 
 
 
 
 
 
 
 
 
195
 
196
 
197
+ num_epochs=1
198
  train_main(train_loader, test_loader, num_epochs, optimizer, model, device)
199
 
200