Skip to content

Commit

Permalink
canceling training between one epoch and another
Browse files Browse the repository at this point in the history
  • Loading branch information
GusttavoOliveira committed May 11, 2024
1 parent a5349c1 commit 9250bf0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 8 additions & 5 deletions api/Neural_Network2.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,16 @@ def train_epoch(model, optimizer, scheduler, train_loader, criterion, curr_epoch
total += len(target)
num_iters += 1
if num_iters % 20 == 0:
with open('training_progress.json', 'w') as f:
progress = 100 * (curr_epoch + num_iters/len(train_loader)) / num_total_epochs
training_progress = {
with open('training_progress.json', 'r+') as f:
data = json.load(f)
progress = 100 * (curr_epoch + num_iters / len(train_loader)) / num_total_epochs
data.update({
'training_progress': progress,
'training_in_progress': True
}
json.dump(training_progress, f)
})
f.seek(0)
json.dump(data, f)
f.truncate()

return total_loss / total

Expand Down
10 changes: 10 additions & 0 deletions src/pages/train.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,16 @@ export default function Train() {
>
{isLoading ? "Carregando..." : "Treinar"}
</button>

{isLoading && (
<button
className="mt-3 bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded-lg"
onClick={handleCancelTraining}
disabled={isCancelling}
>
{isCancelling ? 'Cancelando...' : 'Cancelar Treinamento'}
</button>
)}
</div>
</div>
</>
Expand Down

0 comments on commit 9250bf0

Please sign in to comment.