Skip to content

Commit

Permalink
shap
Browse files Browse the repository at this point in the history
  • Loading branch information
sronilsson committed Oct 23, 2024
1 parent 741fc08 commit acbeaa3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions simba/mixins/circular_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,9 +1019,9 @@ def circular_range(data: np.ndarray) -> float:
:rtype: np.ndarray
:example:
>>> CircularStatisticsMixin().circular_range([350, 20, 60, 100])
>>> CircularStatisticsMixin().circular_range(np.ndarray([350, 20, 60, 100]))
>>> 110.0
>>> CircularStatisticsMixin().circular_range([110, 20, 60, 100])
>>> CircularStatisticsMixin().circular_range(np.ndarray([110, 20, 60, 100]))
>>> 90.0
"""

Expand Down
4 changes: 2 additions & 2 deletions simba/mixins/timeseries_features_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,11 +864,11 @@ def sliding_variance(data: np.ndarray, window_sizes: np.ndarray, sample_rate: in

@staticmethod
@njit(
"(float32[:], float64[:], int64, types.ListType(types.unicode_type))",
"(float32[:], float64[:], float64, types.ListType(types.unicode_type))",
fastmath=True,
cache=True,
)
def sliding_descriptive_statistics(data: np.ndarray, window_sizes: np.ndarray, sample_rate: int, statistics: Literal["var", "max", "min", "std", "median", "mean", "mad", "sum", "mac", "rms", "absenergy"]) -> np.ndarray:
def sliding_descriptive_statistics(data: np.ndarray, window_sizes: np.ndarray, sample_rate: float, statistics: Literal["var", "max", "min", "std", "median", "mean", "mad", "sum", "mac", "rms", "absenergy"]) -> np.ndarray:
"""
Jitted compute of descriptive statistics over sliding windows in 1D data array.
Expand Down
4 changes: 2 additions & 2 deletions simba/plotting/pose_plotter_mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ def run(self):
circle_size=video_circle_size,
video_save_dir=self.temp_folder)
for cnt, result in enumerate(pool.imap(constants, pose_lst, chunksize=self.config.multiprocess_chunksize)):
print(f"Image {max(len(pose_df), obs_per_split*(cnt+1))}/{len(pose_df)}, Video {file_cnt+1}/{len(list(self.data.keys()))}...")
print(f"Image {min(len(pose_df), obs_per_split*(cnt+1))}/{len(pose_df)}, Video {file_cnt+1}/{len(list(self.data.keys()))}...")
pool.terminate()
pool.join()
print(f"Joining {video_name} multi-processed video...")
concatenate_videos_in_folder(in_folder=self.temp_folder, save_path=save_video_path, remove_splits=True, gpu=self.gpu)
concatenate_videos_in_folder(in_folder=self.temp_folder, save_path=save_video_path, remove_splits=True, gpu=False)
video_timer.stop_timer()
stdout_success(msg=f"Pose video {video_name} complete and saved at {save_video_path}", elapsed_time=video_timer.elapsed_time_str, source=self.__class__.__name__)
self.config.timer.stop_timer()
Expand Down
40 changes: 20 additions & 20 deletions simba/third_party_label_appenders/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import cv2
import numpy as np
from pycocotools import mask
#from pycocotools import mask
from shapely.geometry import Polygon
from skimage.draw import polygon

Expand All @@ -27,25 +27,25 @@
from simba.utils.printing import SimbaTimer, stdout_success


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.
:param geometry: The geometry to be converted into an RLE. It can be either a shapely Polygon or a (n, 2) np.ndarray with vertices.
:param img_size: A tuple `(height, width)` representing the size of the image in which the geometry is to be encoded. This defines the dimensions of the output binary mask.
:return:
"""
check_instance(source=geometry_to_rle.__name__, instance=geometry, accepted_types=(Polygon, np.ndarray))
if isinstance(geometry, (Polygon,)):
geometry = geometry.exterior.coords
else:
check_valid_array(data=geometry, source=geometry_to_rle.__name__, accepted_ndims=[(2,)], accepted_dtypes=Formats.NUMERIC_DTYPES.value)
binary_mask = np.zeros(img_size, dtype=np.uint8)
rr, cc = polygon(geometry[:, 0].flatten(), geometry[:, 1].flatten(), img_size)
binary_mask[rr, cc] = 1
rle = mask.encode(np.asfortranarray(binary_mask))
rle['counts'] = rle['counts'].decode('utf-8')
return rle
# 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.
#
# :param geometry: The geometry to be converted into an RLE. It can be either a shapely Polygon or a (n, 2) np.ndarray with vertices.
# :param img_size: A tuple `(height, width)` representing the size of the image in which the geometry is to be encoded. This defines the dimensions of the output binary mask.
# :return:
# """
# check_instance(source=geometry_to_rle.__name__, instance=geometry, accepted_types=(Polygon, np.ndarray))
# if isinstance(geometry, (Polygon,)):
# geometry = geometry.exterior.coords
# else:
# check_valid_array(data=geometry, source=geometry_to_rle.__name__, accepted_ndims=[(2,)], accepted_dtypes=Formats.NUMERIC_DTYPES.value)
# binary_mask = np.zeros(img_size, dtype=np.uint8)
# rr, cc = polygon(geometry[:, 0].flatten(), geometry[:, 1].flatten(), img_size)
# binary_mask[rr, cc] = 1
# rle = mask.encode(np.asfortranarray(binary_mask))
# rle['counts'] = rle['counts'].decode('utf-8')
# return rle

def geometries_to_coco(geometries: Dict[str, np.ndarray],
video_path: Union[str, os.PathLike],
Expand Down
2 changes: 1 addition & 1 deletion simba/third_party_label_appenders/third_party_appender.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ThirdPartyLabelAppender(ConfigReader):
`Third-party import tutorials <https://github.com/sgoldenlab/simba/blob/master/docs/third_party_annot.md>`__.
`BENTO: expected input <https://github.com/sgoldenlab/simba/blob/master/misc/bento_example.annot`__.
`BORIS: expected input <https://github.com/sgoldenlab/simba/blob/master/misc/boris_example.csv>`__..
`BORIS: expected input <https://github.com/sgoldenlab/simba/blob/master/misc/boris_example.csv>`__.
`DEEPETHOGRAM: expected input <https://github.com/sgoldenlab/simba/blob/master/misc/deep_ethogram_labels.csv>`__.
`ETHOVISION: expected input <https://github.com/sgoldenlab/simba/blob/master/misc/ethovision_example.xlsx>`__.
`OBSERVER: expected input I <https://github.com/sgoldenlab/simba/blob/master/misc/Observer_example_1.xlsx>`__.
Expand Down

0 comments on commit acbeaa3

Please sign in to comment.