ImAMJayKIM commited on
Commit
b5ca7e6
·
verified ·
1 Parent(s): 6e5164d

Delete src/utils/.ipynb_checkpoints/checkpoint_manager-checkpoint.py

Browse files
src/utils/.ipynb_checkpoints/checkpoint_manager-checkpoint.py DELETED
@@ -1,59 +0,0 @@
1
- import os
2
- import torch
3
-
4
- def save_checkpoint(
5
- path,
6
- encoder,
7
- decoder,
8
- optimizer,
9
- epoch,
10
- train_loss,
11
- val_loss
12
- ):
13
- torch.save({
14
- "epoch": epoch,
15
- "encoder_state_dict": encoder.state_dict(),
16
- "decoder_state_dict": decoder.state_dict(),
17
- "optimizer_state_dict": optimizer.state_dict(),
18
- "train_loss": train_loss,
19
- "val_loss": val_loss
20
- }, path)
21
-
22
-
23
- def load_checkpoint(
24
- resume,
25
- best_path,
26
- encoder,
27
- decoder,
28
- optimizer,
29
- device
30
- ):
31
-
32
- if resume:
33
- print(f"Loading checkpoint: {best_path}")
34
-
35
- checkpoint = torch.load(
36
- best_path,
37
- map_location=device
38
- )
39
-
40
- encoder.load_state_dict(checkpoint["encoder_state_dict"])
41
-
42
- decoder.load_state_dict(checkpoint["decoder_state_dict"])
43
-
44
- optimizer.load_state_dict(checkpoint["optimizer_state_dict"])
45
-
46
- start_epoch = checkpoint["epoch"]
47
-
48
- best_val_loss = checkpoint["val_loss"]
49
-
50
- print(
51
- f"Resume from Epoch {start_epoch} | "
52
- f"Best Val Loss: {best_val_loss:.4f}"
53
- )
54
-
55
- return start_epoch, best_val_loss
56
- else:
57
- print(f"Resume: {resume}")
58
-
59
- return 0, float("inf")