dmtschulz commited on
Commit
7fd4b8e
·
1 Parent(s): 912af74

fix readme and config path

Browse files
Files changed (5) hide show
  1. README.md +3 -4
  2. app.py +1 -1
  3. app/main.py +1 -1
  4. src/model_config.py +6 -8
  5. src/train.py +1 -1
README.md CHANGED
@@ -34,10 +34,9 @@ pip install -r requirements.txt
34
  python src/train.py
35
  ```
36
  By default, the model will be saved to `models/autoencoder_mnist.pth`.
37
- Then in `main.py` set
38
- `MODEL_PATH = "models/autoencoder_mnist.pth"`
39
- and in `train.py` set
40
- `path = "models/autoencoder_mnist.pth"`
41
 
42
  ## 🎛️ Run the Gradio Frontend
43
  ```
 
34
  python src/train.py
35
  ```
36
  By default, the model will be saved to `models/autoencoder_mnist.pth`.
37
+
38
+ Then in `model_config.py` set
39
+ `model_path`.
 
40
 
41
  ## 🎛️ Run the Gradio Frontend
42
  ```
app.py CHANGED
@@ -18,7 +18,7 @@ def request_pydantic_schema(_: type, handler: GetCoreSchemaHandler):
18
  Request.__get_pydantic_core_schema__ = request_pydantic_schema
19
 
20
  device = set_device()
21
- model = load_model(use_local=False)
22
  model.eval()
23
 
24
  transform = T.Compose([
 
18
  Request.__get_pydantic_core_schema__ = request_pydantic_schema
19
 
20
  device = set_device()
21
+ model = load_model()
22
  model.eval()
23
 
24
  transform = T.Compose([
app/main.py CHANGED
@@ -22,7 +22,7 @@ app = FastAPI()
22
 
23
  device = set_device()
24
  log.info("Using device: %s", device)
25
- model = load_model(use_local=False)
26
  log.info("Model loaded. App is ready.")
27
 
28
  model.eval()
 
22
 
23
  device = set_device()
24
  log.info("Using device: %s", device)
25
+ model = load_model()
26
  log.info("Model loaded. App is ready.")
27
 
28
  model.eval()
src/model_config.py CHANGED
@@ -12,14 +12,12 @@ def set_device():
12
  return device
13
 
14
  # Load model
15
- def load_model(h: int = 32, use_local: bool = False):
16
- if use_local:
17
- model_path = "models/autoencoder_mnist.pth"
18
- else:
19
- model_path = hf_hub_download(
20
- repo_id="dmtschulz/anomaly-detection-model",
21
- filename="autoencoder_mnist.pth"
22
- )
23
 
24
  model = Autoencoder(h).to(DEVICE)
25
  state_dict = torch.load(model_path, map_location=DEVICE)
 
12
  return device
13
 
14
  # Load model
15
+ def load_model(h: int = 32):
16
+ # model_path = "models/autoencoder_mnist.pth" # Use local model
17
+ model_path = hf_hub_download(
18
+ repo_id="dmtschulz/anomaly-detection-model",
19
+ filename="autoencoder_mnist.pth"
20
+ )
 
 
21
 
22
  model = Autoencoder(h).to(DEVICE)
23
  state_dict = torch.load(model_path, map_location=DEVICE)
src/train.py CHANGED
@@ -9,7 +9,7 @@ from torch.utils.data import DataLoader, Subset
9
  from torchvision import transforms as T
10
  from torchvision.datasets import MNIST
11
  from torchvision.utils import save_image
12
- from model_config import set_device
13
  import logging
14
 
15
  logging.basicConfig(level=logging.INFO)
 
9
  from torchvision import transforms as T
10
  from torchvision.datasets import MNIST
11
  from torchvision.utils import save_image
12
+ from src.model_config import set_device
13
  import logging
14
 
15
  logging.basicConfig(level=logging.INFO)