Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,29 +39,27 @@ geolocator = Nominatim(user_agent="skin-dashboard", timeout = 10)
|
|
| 39 |
|
| 40 |
@st.cache_resource
|
| 41 |
def load_image_model(token: str):
|
| 42 |
-
# 1)
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
repo_id=MODEL_NAME,
|
| 47 |
-
use_auth_token=token,
|
| 48 |
-
cache_dir=cache_dir
|
| 49 |
)
|
| 50 |
|
| 51 |
-
# 2)
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
#
|
| 63 |
-
extractor = AutoFeatureExtractor.from_pretrained(local_dir)
|
| 64 |
-
model = AutoModelForImageClassification.from_pretrained(local_dir)
|
| 65 |
return pipeline(
|
| 66 |
"image-classification",
|
| 67 |
model=model,
|
|
|
|
| 39 |
|
| 40 |
@st.cache_resource
|
| 41 |
def load_image_model(token: str):
|
| 42 |
+
# 1) load the feature extractor from the Hub as usual
|
| 43 |
+
extractor = AutoFeatureExtractor.from_pretrained(
|
| 44 |
+
MODEL_NAME,
|
| 45 |
+
use_auth_token=token
|
|
|
|
|
|
|
|
|
|
| 46 |
)
|
| 47 |
|
| 48 |
+
# 2) manually create a ConvNextConfig with the right num_labels / id2label
|
| 49 |
+
config = ConvNextConfig(
|
| 50 |
+
num_labels=2,
|
| 51 |
+
id2label={0: "benign", 1: "malignant"},
|
| 52 |
+
label2id={"benign": 0, "malignant": 1}
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# 3) load the weights with that config override
|
| 56 |
+
model = AutoModelForImageClassification.from_pretrained(
|
| 57 |
+
MODEL_NAME,
|
| 58 |
+
config=config,
|
| 59 |
+
use_auth_token=token
|
| 60 |
+
)
|
| 61 |
|
| 62 |
+
# 4) build your pipeline
|
|
|
|
|
|
|
| 63 |
return pipeline(
|
| 64 |
"image-classification",
|
| 65 |
model=model,
|