lombardata
commited on
Commit
•
27522fe
1
Parent(s):
ddf8f93
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,6 @@ import numpy as np
|
|
9 |
|
10 |
# DEFINE MODEL NAME
|
11 |
model_name = "DinoVdeau_Aina-large-2024_06_12-batch-size32_epochs150_freeze"
|
12 |
-
#model_name = "dinov2-large-2024_01_24-with_data_aug_batch-size32_epochs93_freeze"
|
13 |
checkpoint_name = "lombardata/" + model_name
|
14 |
|
15 |
# Load the model configuration and create the model
|
@@ -47,12 +46,6 @@ model.to(device)
|
|
47 |
def sigmoid(_outputs):
|
48 |
return 1.0 / (1.0 + np.exp(-_outputs))
|
49 |
|
50 |
-
def download_thresholds(repo_id, filename):
|
51 |
-
threshold_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
52 |
-
with open(threshold_path, 'r') as threshold_file:
|
53 |
-
thresholds = json.load(threshold_file)
|
54 |
-
return thresholds
|
55 |
-
|
56 |
def predict(image, slider_threshold=0.5, fixed_thresholds=None):
|
57 |
# Preprocess the image
|
58 |
processor = AutoImageProcessor.from_pretrained(checkpoint_name)
|
@@ -75,12 +68,9 @@ def predict(image, slider_threshold=0.5, fixed_thresholds=None):
|
|
75 |
|
76 |
return slider_results, fixed_threshold_labels_str
|
77 |
|
78 |
-
def predict_wrapper(image, slider_threshold=0.5):
|
79 |
-
# Download thresholds from the model repository
|
80 |
-
thresholds = download_thresholds(checkpoint_name, "threshold.json")
|
81 |
-
|
82 |
# Get predictions from the predict function using both the slider and fixed thresholds
|
83 |
-
slider_results, fixed_threshold_results = predict(image, slider_threshold
|
84 |
|
85 |
# Return both sets of predictions for Gradio outputs
|
86 |
return slider_results, fixed_threshold_results
|
|
|
9 |
|
10 |
# DEFINE MODEL NAME
|
11 |
model_name = "DinoVdeau_Aina-large-2024_06_12-batch-size32_epochs150_freeze"
|
|
|
12 |
checkpoint_name = "lombardata/" + model_name
|
13 |
|
14 |
# Load the model configuration and create the model
|
|
|
46 |
def sigmoid(_outputs):
|
47 |
return 1.0 / (1.0 + np.exp(-_outputs))
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
def predict(image, slider_threshold=0.5, fixed_thresholds=None):
|
50 |
# Preprocess the image
|
51 |
processor = AutoImageProcessor.from_pretrained(checkpoint_name)
|
|
|
68 |
|
69 |
return slider_results, fixed_threshold_labels_str
|
70 |
|
71 |
+
def predict_wrapper(image, slider_threshold=0.5):
|
|
|
|
|
|
|
72 |
# Get predictions from the predict function using both the slider and fixed thresholds
|
73 |
+
slider_results, fixed_threshold_results = predict(image, slider_threshold)
|
74 |
|
75 |
# Return both sets of predictions for Gradio outputs
|
76 |
return slider_results, fixed_threshold_results
|