mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-13 18:47:36 +03:00
Fully delete a model
This commit is contained in:
parent
d44340eca6
commit
36e811831e
@ -31,9 +31,10 @@ from frigate.api.defs.response.generic_response import GenericResponse
|
|||||||
from frigate.api.defs.tags import Tags
|
from frigate.api.defs.tags import Tags
|
||||||
from frigate.config import FrigateConfig
|
from frigate.config import FrigateConfig
|
||||||
from frigate.config.camera import DetectConfig
|
from frigate.config.camera import DetectConfig
|
||||||
from frigate.const import CLIPS_DIR, FACE_DIR
|
from frigate.const import CLIPS_DIR, FACE_DIR, MODEL_CACHE_DIR
|
||||||
from frigate.embeddings import EmbeddingsContext
|
from frigate.embeddings import EmbeddingsContext
|
||||||
from frigate.models import Event
|
from frigate.models import Event
|
||||||
|
from frigate.util.builtin import find_config_file, update_yaml_file_bulk
|
||||||
from frigate.util.classification import (
|
from frigate.util.classification import (
|
||||||
collect_object_classification_examples,
|
collect_object_classification_examples,
|
||||||
collect_state_classification_examples,
|
collect_state_classification_examples,
|
||||||
@ -828,12 +829,34 @@ def delete_classification_model(request: Request, name: str):
|
|||||||
status_code=404,
|
status_code=404,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Delete the classification model's data directory
|
# Delete the classification model's data directory in clips
|
||||||
model_dir = os.path.join(CLIPS_DIR, sanitize_filename(name))
|
data_dir = os.path.join(CLIPS_DIR, sanitize_filename(name))
|
||||||
|
if os.path.exists(data_dir):
|
||||||
|
shutil.rmtree(data_dir)
|
||||||
|
|
||||||
|
# Delete the classification model's files in model_cache
|
||||||
|
model_dir = os.path.join(MODEL_CACHE_DIR, sanitize_filename(name))
|
||||||
if os.path.exists(model_dir):
|
if os.path.exists(model_dir):
|
||||||
shutil.rmtree(model_dir)
|
shutil.rmtree(model_dir)
|
||||||
|
|
||||||
|
# Remove the model from the config file
|
||||||
|
config_file = find_config_file()
|
||||||
|
try:
|
||||||
|
# Setting value to empty string deletes the key
|
||||||
|
updates = {f"classification.custom.{name}": None}
|
||||||
|
update_yaml_file_bulk(config_file, updates)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error updating config file: {e}")
|
||||||
|
return JSONResponse(
|
||||||
|
content=(
|
||||||
|
{
|
||||||
|
"success": False,
|
||||||
|
"message": f"Failed to update config file: {str(e)}",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
status_code=500,
|
||||||
|
)
|
||||||
|
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content=(
|
content=(
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user