Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Fixed Error - Checkpoint filename is invalid on Windows
Browse files Browse the repository at this point in the history
This commit fixed the error (Checkpoint filename is invalid on Windows) using strftime replacing the original one.
  • Loading branch information
mengxuez committed Nov 20, 2020
1 parent f9f1c9d commit 1c0a0f5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,16 +1136,20 @@ def train(

def save_model(model, model_name, dataset_name, **kwargs):
model_dir = "./checkpoints/" + model_name + "/" + dataset_name + "/"
"""
Using strftime in case it triggers exceptions on windows 10 system
"""
time_str = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
if not os.path.isdir(model_dir):
os.makedirs(model_dir, exist_ok=True)
if isinstance(model, torch.nn.Module):
filename = str(datetime.datetime.now()) + "_epoch{epoch}_{metric:.2f}".format(
filename = time_str + "_epoch{epoch}_{metric:.2f}".format(
**kwargs
)
tqdm.write("Saving neural network weights in {}".format(filename))
torch.save(model.state_dict(), model_dir + filename + ".pth")
else:
filename = str(datetime.datetime.now())
filename = time_str
tqdm.write("Saving model params in {}".format(filename))
joblib.dump(model, model_dir + filename + ".pkl")

Expand Down

0 comments on commit 1c0a0f5

Please sign in to comment.