From 8d9befdf28aca90d7ceb1b650cae83587dbaeeb3 Mon Sep 17 00:00:00 2001 From: sronilsson Date: Tue, 17 Sep 2024 17:54:21 +0000 Subject: [PATCH] cleaned --- .../yolo/geometries_to_annotations.py | 19 +++++++++------- simba/bounding_box_tools/yolo/model.py | 14 +++++++----- simba/data_processors/cuda/image.py | 6 +++-- simba/data_processors/cuda/utils.py | 8 ++++--- .../BORIS_appender.py | 22 +++++++++++++------ simba/utils/read_write.py | 5 +++-- 6 files changed, 47 insertions(+), 27 deletions(-) diff --git a/simba/bounding_box_tools/yolo/geometries_to_annotations.py b/simba/bounding_box_tools/yolo/geometries_to_annotations.py index c14f31ed9..38e572224 100644 --- a/simba/bounding_box_tools/yolo/geometries_to_annotations.py +++ b/simba/bounding_box_tools/yolo/geometries_to_annotations.py @@ -1,18 +1,21 @@ +import json import os -from typing import Optional, Union, Dict, Tuple -from pycocotools import mask +from datetime import datetime +from typing import Dict, Optional, Tuple, Union import cv2 -import json -from simba.utils.read_write import read_df, get_video_meta_data, read_frm_of_video import numpy as np -from simba.mixins.geometry_mixin import GeometryMixin +from pycocotools import mask from shapely.geometry import Polygon -from datetime import datetime -from simba.utils.checks import check_int, check_instance, check_valid_array -from simba.utils.enums import Formats from skimage.draw import polygon +from simba.mixins.geometry_mixin import GeometryMixin +from simba.utils.checks import check_instance, check_int, check_valid_array +from simba.utils.enums import Formats +from simba.utils.read_write import (get_video_meta_data, read_df, + read_frm_of_video) + + def geometry_to_rle(geometry: Union[np.ndarray, Polygon], img_size: Tuple[int, int]): """ Converts a geometry (polygon or NumPy array) into a Run-Length Encoding (RLE) mask, suitable for object detection or segmentation tasks. diff --git a/simba/bounding_box_tools/yolo/model.py b/simba/bounding_box_tools/yolo/model.py index c0c24c92a..4efd3b6ca 100644 --- a/simba/bounding_box_tools/yolo/model.py +++ b/simba/bounding_box_tools/yolo/model.py @@ -1,13 +1,17 @@ +import functools +import multiprocessing import os +from typing import Optional, Tuple, Union + import numpy as np +import pandas as pd import torch from ultralytics import YOLO -from typing import Union, Optional, Tuple -import multiprocessing -import pandas as pd -import functools + from simba.utils.enums import Defaults -from simba.utils.read_write import get_video_meta_data, read_img_batch_from_video_gpu, find_core_cnt +from simba.utils.read_write import (find_core_cnt, get_video_meta_data, + read_img_batch_from_video_gpu) + def fit_yolo(initial_weights: Union[str, os.PathLike], data: Union[str, os.PathLike], diff --git a/simba/data_processors/cuda/image.py b/simba/data_processors/cuda/image.py index c63ba8d89..4a2a5432c 100644 --- a/simba/data_processors/cuda/image.py +++ b/simba/data_processors/cuda/image.py @@ -21,6 +21,7 @@ import numpy as np from numba import cuda +from simba.data_processors.cuda.utils import _cuda_mse from simba.mixins.image_mixin import ImageMixin from simba.utils.checks import (check_file_exist_and_readable, check_float, check_if_dir_exists, @@ -29,12 +30,13 @@ check_nvidea_gpu_available, check_that_hhmmss_start_is_before_end, check_valid_array, check_valid_boolean) -from simba.data_processors.cuda.utils import _cuda_mse from simba.utils.data import find_frame_numbers_from_time_stamp from simba.utils.enums import Formats from simba.utils.errors import FFMPEGCodecGPUError, InvalidInputError from simba.utils.printing import SimbaTimer, stdout_success -from simba.utils.read_write import (check_if_hhmmss_timestamp_is_valid_part_of_video, get_fn_ext, get_video_meta_data, read_img_batch_from_video_gpu) +from simba.utils.read_write import ( + check_if_hhmmss_timestamp_is_valid_part_of_video, get_fn_ext, + get_video_meta_data, read_img_batch_from_video_gpu) PHOTOMETRIC = 'photometric' DIGITAL = 'digital' diff --git a/simba/data_processors/cuda/utils.py b/simba/data_processors/cuda/utils.py index e921fb475..a5d80fed5 100644 --- a/simba/data_processors/cuda/utils.py +++ b/simba/data_processors/cuda/utils.py @@ -1,7 +1,9 @@ -from typing import Tuple, Dict, Any -import numpy as np -from numba import cuda, guvectorize, float64 import math +from typing import Any, Dict, Tuple + +import numpy as np +from numba import cuda, float64, guvectorize + @cuda.jit(device=True) def _cuda_sum(x: np.ndarray): diff --git a/simba/third_party_label_appenders/BORIS_appender.py b/simba/third_party_label_appenders/BORIS_appender.py index 686e54a3a..a9a167eda 100644 --- a/simba/third_party_label_appenders/BORIS_appender.py +++ b/simba/third_party_label_appenders/BORIS_appender.py @@ -3,16 +3,24 @@ import glob import os from copy import deepcopy -import pandas as pd from typing import Union +import pandas as pd + from simba.mixins.config_reader import ConfigReader -from simba.third_party_label_appenders.tools import is_new_boris_version, read_boris_annotation_files -from simba.utils.checks import (check_if_dir_exists, check_if_filepath_list_is_empty) -from simba.utils.errors import (ThirdPartyAnnotationEventCountError, ThirdPartyAnnotationOverlapError, NoDataError) -from simba.utils.printing import stdout_success, SimbaTimer -from simba.utils.read_write import get_fn_ext, read_df, write_df, find_files_of_filetypes_in_directory -from simba.utils.warnings import (ThirdPartyAnnotationsInvalidFileFormatWarning, ThirdPartyAnnotationsOutsidePoseEstimationDataWarning) +from simba.third_party_label_appenders.tools import ( + is_new_boris_version, read_boris_annotation_files) +from simba.utils.checks import (check_if_dir_exists, + check_if_filepath_list_is_empty) +from simba.utils.errors import (NoDataError, + ThirdPartyAnnotationEventCountError, + ThirdPartyAnnotationOverlapError) +from simba.utils.printing import SimbaTimer, stdout_success +from simba.utils.read_write import (find_files_of_filetypes_in_directory, + get_fn_ext, read_df, write_df) +from simba.utils.warnings import ( + ThirdPartyAnnotationsInvalidFileFormatWarning, + ThirdPartyAnnotationsOutsidePoseEstimationDataWarning) BEHAVIOR = 'BEHAVIOR' class BorisAppender(ConfigReader): diff --git a/simba/utils/read_write.py b/simba/utils/read_write.py index 56375981e..0dc8e1176 100644 --- a/simba/utils/read_write.py +++ b/simba/utils/read_write.py @@ -52,8 +52,9 @@ ParametersFileError, PermissionError) from simba.utils.printing import SimbaTimer, stdout_success from simba.utils.warnings import ( - FileExistWarning, InvalidValueWarning, NoDataFoundWarning, - NoFileFoundWarning, ThirdPartyAnnotationsInvalidFileFormatWarning, FrameRangeWarning) + FileExistWarning, FrameRangeWarning, InvalidValueWarning, + NoDataFoundWarning, NoFileFoundWarning, + ThirdPartyAnnotationsInvalidFileFormatWarning) # from simba.utils.keyboard_listener import KeyboardListener