-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
37 lines (28 loc) · 946 Bytes
/
Copy pathutils.py
File metadata and controls
37 lines (28 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
from compressai.zoo import models
from compressai.models import (
Cheng2020Anchor,
Cheng2020Attention,
FactorizedPrior,
JointAutoregressiveHierarchicalPriors,
MeanScaleHyperprior,
ScaleHyperprior,
)
from Network import *
from pathlib import Path
from typing import Dict, Tuple
from torch import Tensor
def DelfileList(path, filestarts='checkpoint_last'):
for root, dirs, files in os.walk(path):
for file in files:
if file.startswith(filestarts):
os.remove(os.path.join(root, file))
def load_checkpoint(filepath: Path) -> Dict[str, torch.Tensor]:
checkpoint = torch.load(filepath, map_location="cpu")
if "network" in checkpoint:
state_dict = checkpoint["network"]
elif "state_dict" in checkpoint:
state_dict = checkpoint["state_dict"]
else:
state_dict = checkpoint
return state_dict