Aditya
commited on
Commit
·
5b8727d
1
Parent(s):
6785c36
add comments
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ from huggingface_hub import hf_hub_download
|
|
| 7 |
|
| 8 |
backend = get_backend('ultralytics')
|
| 9 |
|
| 10 |
-
|
| 11 |
def use_models_hf():
|
| 12 |
model_repos = {
|
| 13 |
"Classification": {
|
|
@@ -34,30 +34,26 @@ def use_models_hf():
|
|
| 34 |
|
| 35 |
downloaded_models = {}
|
| 36 |
|
| 37 |
-
# Ensure main model directory exists
|
| 38 |
os.makedirs("model", exist_ok=True)
|
| 39 |
|
| 40 |
-
# Create all required subdirectories
|
| 41 |
for model_type, model_info in model_repos.items():
|
| 42 |
os.makedirs(model_info["local_dir"], exist_ok=True)
|
| 43 |
|
| 44 |
for model_type, model_info in model_repos.items():
|
| 45 |
target_path = os.path.join(model_info["local_dir"], model_info["filename"])
|
| 46 |
|
| 47 |
-
# Check if model already exists in target directory
|
| 48 |
if os.path.exists(target_path):
|
| 49 |
print(f"Model already exists at {target_path}")
|
| 50 |
downloaded_models[model_type] = target_path
|
| 51 |
continue
|
| 52 |
|
| 53 |
try:
|
| 54 |
-
# Download the model directly to the target directory
|
| 55 |
print(f"Downloading {model_type} model from Hugging Face...")
|
| 56 |
model_path = hf_hub_download(
|
| 57 |
repo_id=model_info["repo_id"],
|
| 58 |
filename=model_info["filename"],
|
| 59 |
-
local_dir=model_info["local_dir"],
|
| 60 |
-
local_dir_use_symlinks=False
|
| 61 |
)
|
| 62 |
|
| 63 |
downloaded_models[model_type] = model_path
|
|
@@ -74,11 +70,9 @@ def use_models_hf():
|
|
| 74 |
model_paths = use_models_hf()
|
| 75 |
|
| 76 |
|
| 77 |
-
# Initialize with Classification model
|
| 78 |
selected_model_name = "Classification"
|
| 79 |
backend.patch(model_paths[selected_model_name])
|
| 80 |
|
| 81 |
-
# Model type to display label mapping
|
| 82 |
MODEL_TYPE_LABELS = {
|
| 83 |
"Classification": "Person Classification",
|
| 84 |
"Detection": "Person Detection",
|
|
|
|
| 7 |
|
| 8 |
backend = get_backend('ultralytics')
|
| 9 |
|
| 10 |
+
# Make sure the models paths are defined wrt their tasks, it helps map task in backend
|
| 11 |
def use_models_hf():
|
| 12 |
model_repos = {
|
| 13 |
"Classification": {
|
|
|
|
| 34 |
|
| 35 |
downloaded_models = {}
|
| 36 |
|
|
|
|
| 37 |
os.makedirs("model", exist_ok=True)
|
| 38 |
|
|
|
|
| 39 |
for model_type, model_info in model_repos.items():
|
| 40 |
os.makedirs(model_info["local_dir"], exist_ok=True)
|
| 41 |
|
| 42 |
for model_type, model_info in model_repos.items():
|
| 43 |
target_path = os.path.join(model_info["local_dir"], model_info["filename"])
|
| 44 |
|
|
|
|
| 45 |
if os.path.exists(target_path):
|
| 46 |
print(f"Model already exists at {target_path}")
|
| 47 |
downloaded_models[model_type] = target_path
|
| 48 |
continue
|
| 49 |
|
| 50 |
try:
|
|
|
|
| 51 |
print(f"Downloading {model_type} model from Hugging Face...")
|
| 52 |
model_path = hf_hub_download(
|
| 53 |
repo_id=model_info["repo_id"],
|
| 54 |
filename=model_info["filename"],
|
| 55 |
+
local_dir=model_info["local_dir"],
|
| 56 |
+
local_dir_use_symlinks=False
|
| 57 |
)
|
| 58 |
|
| 59 |
downloaded_models[model_type] = model_path
|
|
|
|
| 70 |
model_paths = use_models_hf()
|
| 71 |
|
| 72 |
|
|
|
|
| 73 |
selected_model_name = "Classification"
|
| 74 |
backend.patch(model_paths[selected_model_name])
|
| 75 |
|
|
|
|
| 76 |
MODEL_TYPE_LABELS = {
|
| 77 |
"Classification": "Person Classification",
|
| 78 |
"Detection": "Person Detection",
|