Clean rewrite with proper structure
Browse files- src/streamlit_app.py +4 -2
src/streamlit_app.py
CHANGED
|
@@ -7,12 +7,14 @@ from PIL import Image
|
|
| 7 |
from torchvision.transforms import v2
|
| 8 |
from torchvision.models import resnet18, ResNet18_Weights
|
| 9 |
|
| 10 |
-
@st.cache_resource
|
| 11 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
| 12 |
def load_model():
|
| 13 |
model = resnet18(weights=None)
|
| 14 |
model.fc = torch.nn.Linear(512, 2)
|
| 15 |
-
|
|
|
|
| 16 |
model.eval()
|
| 17 |
return model
|
| 18 |
|
|
|
|
| 7 |
from torchvision.transforms import v2
|
| 8 |
from torchvision.models import resnet18, ResNet18_Weights
|
| 9 |
|
|
|
|
| 10 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 11 |
+
|
| 12 |
+
@st.cache_resource
|
| 13 |
def load_model():
|
| 14 |
model = resnet18(weights=None)
|
| 15 |
model.fc = torch.nn.Linear(512, 2)
|
| 16 |
+
model_path = os.path.join(BASE_DIR, 'best_model.pth')
|
| 17 |
+
model.load_state_dict(torch.load(model_path, map_location='cpu', weights_only=True))
|
| 18 |
model.eval()
|
| 19 |
return model
|
| 20 |
|