dmtschulz commited on
Commit
bd0f5e8
·
1 Parent(s): 0a7c53a

update model path

Browse files
Files changed (3) hide show
  1. app.py +1 -1
  2. requirements.txt +2 -1
  3. src/train.py +5 -2
app.py CHANGED
@@ -9,7 +9,7 @@ import matplotlib.pyplot as plt
9
  from src.train import load_model, loss_fn
10
 
11
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
12
- model = load_model("./models/autoencoder_mnist.pth")
13
  model.eval()
14
 
15
  transform = T.Compose([
 
9
  from src.train import load_model, loss_fn
10
 
11
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
12
+ model = load_model()
13
  model.eval()
14
 
15
  transform = T.Compose([
requirements.txt CHANGED
@@ -11,4 +11,5 @@ plotly
11
  scikit-learn
12
  tqdm
13
  python-multipart
14
- torchvision
 
 
11
  scikit-learn
12
  tqdm
13
  python-multipart
14
+ torchvision
15
+ huggingface_hub
src/train.py CHANGED
@@ -15,6 +15,8 @@ import logging
15
  logging.basicConfig(level=logging.INFO)
16
  log = logging.getLogger(__name__)
17
 
 
 
18
  # Device configuration
19
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
20
  log.info("Using device: %s", DEVICE)
@@ -85,10 +87,11 @@ def save_model(model, path):
85
 
86
 
87
  # Load model
88
- def load_model(path, h=32):
 
 
89
  model = Autoencoder(h).to(DEVICE)
90
  model.load_state_dict(torch.load(path, map_location=DEVICE))
91
- model.to(DEVICE)
92
  model.eval()
93
  log.info("Model loaded from %s", path)
94
  return model
 
15
  logging.basicConfig(level=logging.INFO)
16
  log = logging.getLogger(__name__)
17
 
18
+ from huggingface_hub import hf_hub_download
19
+
20
  # Device configuration
21
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
22
  log.info("Using device: %s", DEVICE)
 
87
 
88
 
89
  # Load model
90
+ def load_model(path=None, h=32):
91
+ if path is None or not os.path.exists(path):
92
+ path = hf_hub_download(repo_id="dmtschulz/anomaly-detection-model", filename="autoencoder_mnist.pth")
93
  model = Autoencoder(h).to(DEVICE)
94
  model.load_state_dict(torch.load(path, map_location=DEVICE))
 
95
  model.eval()
96
  log.info("Model loaded from %s", path)
97
  return model