Spaces:
Runtime error
Runtime error
yangfang236 commited on
Commit ·
4ef91dd
1
Parent(s): 530dd07
torch
Browse files- app.py +12 -2
- export.pkl +1 -1
app.py
CHANGED
|
@@ -6,7 +6,17 @@ import platform
|
|
| 6 |
plt = platform.system()
|
| 7 |
if plt == 'Windows': pathlib.PosixPath=pathlib.WindowsPath
|
| 8 |
from pathlib import Path
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# %% Untitled.ipynb 3
|
| 11 |
def predict(img):
|
| 12 |
labels=learn.dls.vocab
|
|
@@ -15,7 +25,7 @@ def predict(img):
|
|
| 15 |
return {labels[i]:float(probs[i]) for i in range (len(labels))}
|
| 16 |
|
| 17 |
# %% Untitled.ipynb 5
|
| 18 |
-
learn=
|
| 19 |
|
| 20 |
# %% Untitled.ipynb 8
|
| 21 |
examples = ["covid-19.jpg", "normal.jpg", "viral pneumonia.jpg"]
|
|
|
|
| 6 |
plt = platform.system()
|
| 7 |
if plt == 'Windows': pathlib.PosixPath=pathlib.WindowsPath
|
| 8 |
from pathlib import Path
|
| 9 |
+
import torch
|
| 10 |
+
def load_learner_safe(fname, map_location=None, pickle_module=None):
|
| 11 |
+
# This is to ensure it does not attempt to instantiate a WindowsPath
|
| 12 |
+
with open(fname, 'rb') as f:
|
| 13 |
+
# Load the model manually using torch.load and avoid WindowsPath instantiation
|
| 14 |
+
model1 = torch.load(f, map_location=map_location, pickle_module=pickle_module)
|
| 15 |
+
return model1
|
| 16 |
+
|
| 17 |
+
# Use this safe method to load the learner model
|
| 18 |
+
learn = load_learner_safe('export.pkl')
|
| 19 |
+
|
| 20 |
# %% Untitled.ipynb 3
|
| 21 |
def predict(img):
|
| 22 |
labels=learn.dls.vocab
|
|
|
|
| 25 |
return {labels[i]:float(probs[i]) for i in range (len(labels))}
|
| 26 |
|
| 27 |
# %% Untitled.ipynb 5
|
| 28 |
+
learn = load_learner_safe('export.pkl')
|
| 29 |
|
| 30 |
# %% Untitled.ipynb 8
|
| 31 |
examples = ["covid-19.jpg", "normal.jpg", "viral pneumonia.jpg"]
|
export.pkl
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 242096000
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:23e72cbae2206747d84c84e0250fb10b4653a9dc58599e581465c5e62111b87d
|
| 3 |
size 242096000
|