Spaces:
Build error
Build error
Download utils.py from UrielWerneck/EPI-Detector: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/UrielWerneck/EPI-Detector/resolve/main/utils.py
- Command line
-
hf download hf://spaces/UrielWerneck/EPI-Detector/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/UrielWerneck/EPI-Detector/resolve/main/utils.py
1.18 kB
| import ultralytics | |
| import os | |
| def load_yolo_models(path: str) -> dict: | |
| '''load all the yolo models from the specified path''' | |
| yolo_models = {} | |
| for model_name in os.listdir(path): | |
| formated_name = model_name.removesuffix('.pt') | |
| yolo_models[formated_name] = ultralytics.YOLO(f'./models/{model_name}') | |
| return yolo_models | |
| def save_csv_result(result: ultralytics.engine.results.Results, save_path: str): | |
| '''creates a csv file based on yolo results''' | |
| classes_map = result.names | |
| boxes = result.boxes | |
| classes_list = boxes.cls.int().tolist() | |
| confidence_list = [float(f'{conf:.2f}') for conf in boxes.conf.tolist()] | |
| # creating text | |
| file_text = ['class;confidence\n'] | |
| for class_id, conf in zip(classes_list, confidence_list): | |
| file_text.append(f'{classes_map[class_id]};{conf}\n') | |
| file_text[-1] = file_text[-1].removesuffix('\n') | |
| # saving text to file | |
| with open(save_path, 'w') as file: | |
| file.writelines(file_text) | |
| css = ''' | |
| #input_box, #output_box { | |
| height: 67vh !important; | |
| max-height: 67vh !important; | |
| } | |
| #title { | |
| text-align: center; | |
| font-size: 36px; | |
| text-weight: bold; | |
| } | |
| ''' |