Spaces:
Build error
Build error
File size: 1,178 Bytes
ad73380 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 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;
}
''' |