-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
121 changed files
with
195 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import os | ||
from yaml import load | ||
from yaml import FullLoader | ||
from pathlib import Path | ||
from datetime import datetime | ||
from loguru import logger | ||
import shutil | ||
import sys | ||
|
||
file = Path(__file__).resolve() | ||
|
||
|
||
def load_class_names(classes_file): | ||
""" Загрузка названий классов из файла. """ | ||
with open(classes_file, 'r') as file: | ||
class_names = [line.strip() for line in file] | ||
return class_names | ||
|
||
|
||
def load_config(config_file): | ||
with open(config_file) as f: | ||
return load(f, Loader=FullLoader) | ||
|
||
|
||
def get_models(): | ||
path_config = Path(file.parents[1]) / 'config_models' / 'models.yaml' | ||
config = load_config(path_config) | ||
models = config['models_array'] | ||
return models | ||
|
||
|
||
def create_run_directory(model): | ||
current_file_path = Path(__file__).resolve() | ||
|
||
runs_directory = Path(current_file_path.parents[3]) / 'runs' | ||
if not os.path.exists(runs_directory): | ||
os.makedirs(runs_directory, exist_ok=True) | ||
|
||
runs_path = runs_directory / f"{str(datetime.now().strftime('%Y-%m-%d_%H-%M-%S'))}_{model}" | ||
os.makedirs(runs_path, exist_ok=True) | ||
return runs_path | ||
|
||
def get_data_path(ROOT, folder_name): | ||
DATA_PATH = Path(ROOT) / 'user_datasets' | ||
FOLDER_PATH = DATA_PATH / folder_name | ||
target_path = DATA_PATH / FOLDER_PATH.name | ||
try: | ||
if not Path(FOLDER_PATH).is_dir() or not any(Path(FOLDER_PATH).iterdir()): | ||
logger.error("The dataset folder is empty or does not exist.") | ||
sys.exit(0) | ||
|
||
if os.path.isdir(target_path) and FOLDER_PATH.parent.resolve() != DATA_PATH.resolve(): | ||
logger.error("The dataset folder is alredy exist.") | ||
sys.exit(0) | ||
|
||
if FOLDER_PATH.parent.resolve() != DATA_PATH.resolve(): | ||
logger.info(f"Copying a set of images to {DATA_PATH}") | ||
shutil.copytree(FOLDER_PATH, target_path, dirs_exist_ok=True) | ||
FOLDER_PATH = target_path | ||
|
||
except Exception as e: | ||
logger.error(f"An error has occurred: {e}") | ||
return FOLDER_PATH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from sklearn.preprocessing import MinMaxScaler | ||
from pathlib import Path | ||
import numpy as np | ||
from loguru import logger | ||
from pathlib import Path | ||
import cv2 | ||
import numpy as np | ||
file = Path(__file__).resolve() | ||
|
||
|
||
def gini_coefficient(labels): | ||
unique, counts = np.unique(labels, return_counts=True) | ||
class_counts = dict(zip(unique, counts)) | ||
total_examples = len(labels) | ||
gini = 0 | ||
for label in class_counts: | ||
label_prob = class_counts[label] / total_examples | ||
gini += label_prob * (1 - label_prob) | ||
return gini | ||
|
||
|
||
def get_image_size(image_path): | ||
image = cv2.imread(image_path) | ||
if image is not None: | ||
height, width, _ = image.shape | ||
return width, height | ||
return None | ||
|
||
|
||
def min_max_scaler(features): | ||
scaler = MinMaxScaler() | ||
features_normalized = np.exp(scaler.fit_transform(features)) | ||
features_normalized /= np.sum(features_normalized, axis=0) | ||
return features_normalized | ||
|
||
|
||
def get_average_fps(df, column, part_num): | ||
sorted_fps = np.sort(df[column]) | ||
num_parts = 5 | ||
part_size = len(sorted_fps) // num_parts | ||
if part_num < 1 or part_num > num_parts: | ||
return None | ||
start_idx = (num_parts - part_num) * part_size | ||
end_idx = (num_parts - part_num + 1) * part_size | ||
selected_values = sorted_fps[start_idx:end_idx] | ||
average_fps = np.mean(selected_values) | ||
return average_fps | ||
|
||
|
||
def get_average_map50(df, column, part_num): | ||
sorted_mAP50 = np.sort(df[column]) | ||
num_parts = 10 | ||
part_size = len(sorted_mAP50) // num_parts | ||
|
||
if part_num < 1 or part_num > num_parts: | ||
return None | ||
start_idx = (part_num - 1) * part_size | ||
end_idx = part_num * part_size if part_num < num_parts else len(sorted_mAP50) | ||
selected_values = sorted_mAP50[start_idx:end_idx] | ||
average_mAP50 = np.mean(selected_values) | ||
return average_mAP50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.