simba-uw-tf-dev 4.5.8__py3-none-any.whl → 4.7.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. simba/SimBA.py +2 -2
  2. simba/assets/.recent_projects.txt +1 -0
  3. simba/assets/icons/frames_2.png +0 -0
  4. simba/assets/lookups/tooptips.json +15 -1
  5. simba/data_processors/agg_clf_counter_mp.py +52 -53
  6. simba/data_processors/blob_location_computer.py +1 -1
  7. simba/data_processors/circling_detector.py +30 -13
  8. simba/data_processors/cuda/geometry.py +45 -27
  9. simba/data_processors/cuda/image.py +1648 -1598
  10. simba/data_processors/cuda/statistics.py +72 -26
  11. simba/data_processors/cuda/timeseries.py +1 -1
  12. simba/data_processors/cue_light_analyzer.py +5 -9
  13. simba/data_processors/egocentric_aligner.py +25 -7
  14. simba/data_processors/freezing_detector.py +55 -47
  15. simba/data_processors/kleinberg_calculator.py +61 -29
  16. simba/feature_extractors/feature_subsets.py +14 -7
  17. simba/feature_extractors/mitra_feature_extractor.py +2 -2
  18. simba/feature_extractors/straub_tail_analyzer.py +4 -6
  19. simba/labelling/standard_labeller.py +1 -1
  20. simba/mixins/config_reader.py +5 -2
  21. simba/mixins/geometry_mixin.py +22 -36
  22. simba/mixins/image_mixin.py +24 -28
  23. simba/mixins/plotting_mixin.py +28 -10
  24. simba/mixins/statistics_mixin.py +48 -11
  25. simba/mixins/timeseries_features_mixin.py +1 -1
  26. simba/mixins/train_model_mixin.py +67 -29
  27. simba/model/inference_batch.py +1 -1
  28. simba/model/yolo_seg_inference.py +3 -3
  29. simba/outlier_tools/skip_outlier_correction.py +1 -1
  30. simba/plotting/ROI_feature_visualizer_mp.py +3 -5
  31. simba/plotting/clf_validator_mp.py +4 -5
  32. simba/plotting/cue_light_visualizer.py +6 -7
  33. simba/plotting/directing_animals_visualizer_mp.py +2 -3
  34. simba/plotting/distance_plotter_mp.py +378 -378
  35. simba/plotting/frame_mergerer_ffmpeg.py +137 -196
  36. simba/plotting/gantt_creator.py +29 -10
  37. simba/plotting/gantt_creator_mp.py +96 -33
  38. simba/plotting/geometry_plotter.py +270 -272
  39. simba/plotting/heat_mapper_clf_mp.py +4 -6
  40. simba/plotting/heat_mapper_location_mp.py +2 -2
  41. simba/plotting/light_dark_box_plotter.py +2 -2
  42. simba/plotting/path_plotter_mp.py +26 -29
  43. simba/plotting/plot_clf_results_mp.py +455 -454
  44. simba/plotting/pose_plotter_mp.py +28 -29
  45. simba/plotting/probability_plot_creator_mp.py +288 -288
  46. simba/plotting/roi_plotter_mp.py +31 -31
  47. simba/plotting/single_run_model_validation_video_mp.py +427 -427
  48. simba/plotting/spontaneous_alternation_plotter.py +2 -3
  49. simba/plotting/yolo_pose_track_visualizer.py +32 -27
  50. simba/plotting/yolo_pose_visualizer.py +35 -36
  51. simba/plotting/yolo_seg_visualizer.py +2 -3
  52. simba/pose_importers/simba_blob_importer.py +3 -3
  53. simba/roi_tools/roi_aggregate_stats_mp.py +5 -4
  54. simba/roi_tools/roi_clf_calculator_mp.py +4 -4
  55. simba/sandbox/analyze_runtimes.py +30 -0
  56. simba/sandbox/cuda/egocentric_rotator.py +374 -0
  57. simba/sandbox/get_cpu_pool.py +5 -0
  58. simba/sandbox/proboscis_to_tip.py +28 -0
  59. simba/sandbox/test_directionality.py +47 -0
  60. simba/sandbox/test_nonstatic_directionality.py +27 -0
  61. simba/sandbox/test_pycharm_cuda.py +51 -0
  62. simba/sandbox/test_simba_install.py +41 -0
  63. simba/sandbox/test_static_directionality.py +26 -0
  64. simba/sandbox/test_static_directionality_2d.py +26 -0
  65. simba/sandbox/verify_env.py +42 -0
  66. simba/third_party_label_appenders/transform/coco_keypoints_to_yolo.py +3 -3
  67. simba/third_party_label_appenders/transform/coco_keypoints_to_yolo_bbox.py +2 -2
  68. simba/ui/pop_ups/clf_add_remove_print_pop_up.py +37 -30
  69. simba/ui/pop_ups/clf_plot_pop_up.py +2 -2
  70. simba/ui/pop_ups/egocentric_alignment_pop_up.py +20 -21
  71. simba/ui/pop_ups/fsttc_pop_up.py +27 -25
  72. simba/ui/pop_ups/gantt_pop_up.py +31 -6
  73. simba/ui/pop_ups/interpolate_pop_up.py +2 -4
  74. simba/ui/pop_ups/kleinberg_pop_up.py +39 -40
  75. simba/ui/pop_ups/multiple_videos_to_frames_popup.py +10 -11
  76. simba/ui/pop_ups/single_video_to_frames_popup.py +10 -10
  77. simba/ui/pop_ups/video_processing_pop_up.py +186 -174
  78. simba/ui/tkinter_functions.py +10 -1
  79. simba/utils/custom_feature_extractor.py +1 -1
  80. simba/utils/data.py +90 -14
  81. simba/utils/enums.py +1 -0
  82. simba/utils/errors.py +441 -440
  83. simba/utils/lookups.py +1203 -1203
  84. simba/utils/printing.py +124 -124
  85. simba/utils/read_write.py +3769 -3721
  86. simba/utils/yolo.py +10 -1
  87. simba/video_processors/blob_tracking_executor.py +2 -2
  88. simba/video_processors/clahe_ui.py +66 -23
  89. simba/video_processors/egocentric_video_rotator.py +46 -44
  90. simba/video_processors/multi_cropper.py +1 -1
  91. simba/video_processors/video_processing.py +5264 -5300
  92. simba/video_processors/videos_to_frames.py +43 -32
  93. {simba_uw_tf_dev-4.5.8.dist-info → simba_uw_tf_dev-4.7.1.dist-info}/METADATA +4 -3
  94. {simba_uw_tf_dev-4.5.8.dist-info → simba_uw_tf_dev-4.7.1.dist-info}/RECORD +98 -86
  95. {simba_uw_tf_dev-4.5.8.dist-info → simba_uw_tf_dev-4.7.1.dist-info}/LICENSE +0 -0
  96. {simba_uw_tf_dev-4.5.8.dist-info → simba_uw_tf_dev-4.7.1.dist-info}/WHEEL +0 -0
  97. {simba_uw_tf_dev-4.5.8.dist-info → simba_uw_tf_dev-4.7.1.dist-info}/entry_points.txt +0 -0
  98. {simba_uw_tf_dev-4.5.8.dist-info → simba_uw_tf_dev-4.7.1.dist-info}/top_level.txt +0 -0
@@ -6,16 +6,17 @@ except:
6
6
  from typing_extensions import Literal
7
7
 
8
8
  import functools
9
- import multiprocessing
10
9
  import os
10
+ from datetime import datetime
11
11
 
12
12
  import cv2
13
13
 
14
14
  from simba.utils.checks import (check_if_dir_exists, check_int, check_str,
15
15
  check_valid_boolean)
16
+ from simba.utils.data import get_cpu_pool, terminate_cpu_pool
16
17
  from simba.utils.printing import SimbaTimer, stdout_success
17
- from simba.utils.read_write import (find_core_cnt, get_video_meta_data,
18
- read_frm_of_video)
18
+ from simba.utils.read_write import (find_core_cnt, get_fn_ext,
19
+ get_video_meta_data, read_frm_of_video)
19
20
 
20
21
  JPEG, PNG, WEBP = 'jpeg', 'png', 'webp'
21
22
 
@@ -39,7 +40,7 @@ def _video_to_frms_helper(img_batch: Tuple[int, List[int]],
39
40
  else:
40
41
  save_path = os.path.join(save_dir, f'{frm_idx}.{img_format}')
41
42
  if verbose:
42
- print(f"Saving image {save_path} ...")
43
+ print(f"Saving image {save_path} ({frm_idx}/{video_meta_data['frame_count']})...")
43
44
  img = read_frm_of_video(video_path=cap, frame_index=frm_idx, greyscale=greyscale, clahe=clahe, black_and_white=black_and_white)
44
45
  if img_format == WEBP:
45
46
  cv2.imwrite(save_path, img, [cv2.IMWRITE_WEBP_QUALITY, quality])
@@ -50,7 +51,7 @@ def _video_to_frms_helper(img_batch: Tuple[int, List[int]],
50
51
  return batch_cnt
51
52
 
52
53
  def video_to_frames(video_path: Union[str, os.PathLike],
53
- save_dir: Union[str, os.PathLike],
54
+ save_dir: Optional[Union[str, os.PathLike]] = None,
54
55
  quality: Optional[int] = 95,
55
56
  img_format: Literal['png', 'webp'] = 'png',
56
57
  verbose: bool = True,
@@ -60,10 +61,16 @@ def video_to_frames(video_path: Union[str, os.PathLike],
60
61
  black_and_white: bool = False,
61
62
  include_video_name_in_filename: bool = True):
62
63
 
63
-
64
64
  """
65
65
  Extract all frames from a video file and save them as individual image files.
66
66
 
67
+ .. csv-table::
68
+ :header: EXPECTED RUNTIMES
69
+ :file: ../../docs/tables/video_to_frames.csv
70
+ :widths: 10, 45, 45
71
+ :align: center
72
+ :header-rows: 1
73
+
67
74
  .. note::
68
75
  Uses multiprocessing for faster frame extraction. Frames are saved with sequential numbering (0, 1, 2, ...).
69
76
 
@@ -80,8 +87,8 @@ def video_to_frames(video_path: Union[str, os.PathLike],
80
87
  :return: None. Frames are saved to disk in the specified directory.
81
88
 
82
89
  :example:
83
- >>> video_to_frames(video_path=r"C:\troubleshooting\SDS_pre_post\project_folder\videos\SDI100 x ALR2 post_d7.mp4",
84
- ... save_dir=r'C:\troubleshooting\SDS_pre_post\project_folder\videos\test',
90
+ >>> video_to_frames(video_path=r"C:/troubleshooting/SDS_pre_post/project_folder/videos/SDI100 x ALR2 post_d7.mp4",
91
+ ... save_dir=r'C:/troubleshooting/SDS_pre_post/project_folder/videos/test',
85
92
  ... black_and_white=False,
86
93
  ... verbose=True,
87
94
  ... img_format='webp',
@@ -90,7 +97,11 @@ def video_to_frames(video_path: Union[str, os.PathLike],
90
97
 
91
98
  timer = SimbaTimer(start=True)
92
99
  video_meta_data = get_video_meta_data(video_path=video_path)
93
- check_if_dir_exists(in_dir=save_dir, source=video_to_frames.__name__, raise_error=True)
100
+ if save_dir is not None:
101
+ check_if_dir_exists(in_dir=save_dir, source=video_to_frames.__name__, raise_error=True)
102
+ else:
103
+ save_dir = os.path.join(get_fn_ext(filepath=video_path)[0], f'{video_meta_data["video_name"]}_frames_{datetime.now().strftime("%Y%m%d%H%M%S")}')
104
+ os.makedirs(save_dir)
94
105
  check_valid_boolean(value=verbose, source=f'{video_to_frames.__name__} verbose')
95
106
  check_valid_boolean(value=clahe, source=f'{video_to_frames.__name__} clahe')
96
107
  check_valid_boolean(value=greyscale, source=f'{video_to_frames.__name__} greyscale')
@@ -98,35 +109,35 @@ def video_to_frames(video_path: Union[str, os.PathLike],
98
109
  check_valid_boolean(value=include_video_name_in_filename, source=f'{video_to_frames.__name__} include_video_name_in_filename')
99
110
  check_int(name=f'{video_to_frames.__name__} core_cnt', value=core_cnt, min_value=-1, unaccepted_vals=[0], raise_error=True)
100
111
  check_int(name=f'{video_to_frames.__name__} quality', value=quality, min_value=1, max_value=100, raise_error=True)
101
- core_cnt = find_core_cnt()[0] if core_cnt -1 or core_cnt > find_core_cnt()[0] else core_cnt
112
+ core_cnt = find_core_cnt()[0] if core_cnt == -1 or core_cnt > find_core_cnt()[0] else core_cnt
102
113
  check_str(name=f'{video_to_frames.__name__} img_format', value=img_format, options=('jpeg', 'png', 'webp'))
103
114
  frm_ids = list(range(0, video_meta_data['frame_count']))
104
115
  frm_ids = [frm_ids[i * len(frm_ids) // core_cnt: (i + 1) * len(frm_ids) // core_cnt] for i in range(core_cnt)]
105
116
  frm_ids = [(i, j) for i, j in enumerate(frm_ids)]
106
- with multiprocessing.Pool(core_cnt, maxtasksperchild=100) as pool:
107
- constants = functools.partial(_video_to_frms_helper,
108
- verbose=verbose,
109
- img_format=img_format,
110
- quality=quality,
111
- greyscale=greyscale,
112
- black_and_white=black_and_white,
113
- include_video_name_in_filename=include_video_name_in_filename,
114
- video_path=video_path,
115
- clahe=clahe,
116
- save_dir=save_dir)
117
- for cnt, batch_id in enumerate(pool.imap(constants, frm_ids, chunksize=1)):
118
- if verbose:
119
- print(f'Video frame batch {batch_id} (of {core_cnt}) complete...')
120
- pool.join()
121
- pool.terminate()
117
+ pool = get_cpu_pool(core_cnt=core_cnt, source=video_to_frames.__name__)
118
+ constants = functools.partial(_video_to_frms_helper,
119
+ verbose=verbose,
120
+ img_format=img_format,
121
+ quality=quality,
122
+ greyscale=greyscale,
123
+ black_and_white=black_and_white,
124
+ include_video_name_in_filename=include_video_name_in_filename,
125
+ video_path=video_path,
126
+ clahe=clahe,
127
+ save_dir=save_dir)
128
+ for cnt, batch_id in enumerate(pool.imap(constants, frm_ids, chunksize=1)):
129
+ if verbose:
130
+ print(f'Video frame batch {batch_id} (of {core_cnt}) complete...')
131
+
132
+ terminate_cpu_pool(pool=pool, force=True, source=video_to_frames.__name__)
122
133
  timer.stop_timer()
123
- if verbose:
124
- stdout_success(msg=f'All frames for video {video_path} saved in {save_dir}', elapsed_time=timer.elapsed_time_str)
134
+ if verbose: stdout_success(msg=f'All frames ({video_meta_data["frame_count"]}) for video {video_path} saved in {save_dir}', elapsed_time=timer.elapsed_time_str)
125
135
 
126
136
  # if __name__ == "__main__":
127
- # video_to_frames(video_path=r"C:\troubleshooting\SDS_pre_post\project_folder\videos\SDI100 x ALR2 post_d7.mp4",
128
- # save_dir=r'C:\troubleshooting\SDS_pre_post\project_folder\videos\test',
137
+ # video_to_frames(video_path=r"D:\troubleshooting\mitra\project_folder\videos\average_cpu_test\15min.mp4",
138
+ # save_dir=None,
129
139
  # black_and_white=False,
130
140
  # verbose=True,
131
- # img_format='webp',
132
- # clahe=True)
141
+ # img_format='png',
142
+ # clahe=False,
143
+ # core_cnt=18)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: simba-uw-tf-dev
3
- Version: 4.5.8
3
+ Version: 4.7.1
4
4
  Summary: Toolkit for computer classification and analysis of behaviors in experimental animals
5
5
  Home-page: https://github.com/sgoldenlab/simba
6
6
  Author: Simon Nilsson, Jia Jie Choong, Sophia Hwang
@@ -79,7 +79,7 @@ Requires-Dist: yellowbrick (==1.5.0) ; python_version >= "3.9"
79
79
  Requires-Dist: kaleido ; python_version >= "3.9"
80
80
  Requires-Dist: psutil ; python_version >= "3.9"
81
81
  Requires-Dist: h5py (==3.11.0) ; python_version >= "3.9"
82
- Requires-Dist: numba (==0.59.1) ; python_version >= "3.9"
82
+ Requires-Dist: numba (==0.63.1) ; python_version >= "3.9"
83
83
  Requires-Dist: numexpr (==2.10.0) ; python_version >= "3.9"
84
84
  Requires-Dist: statsmodels (==0.14.2) ; python_version >= "3.9"
85
85
  Requires-Dist: shap (==0.42.0) ; python_version >= "3.9"
@@ -138,11 +138,12 @@ Requires-Dist: numexpr (==2.10.0) ; (python_version >= "3.9") and extra == 'arm'
138
138
  Requires-Dist: statsmodels (==0.14.2) ; (python_version >= "3.9") and extra == 'arm'
139
139
  Requires-Dist: tables (==3.9.2) ; (python_version >= "3.9") and extra == 'arm'
140
140
  Provides-Extra: gpu
141
- Requires-Dist: cupy-cuda12x (==13.3.0) ; extra == 'gpu'
141
+ Requires-Dist: cupy-cuda12x (>=13.6.0) ; extra == 'gpu'
142
142
  Requires-Dist: shap (==0.46.1.dev78) ; extra == 'gpu'
143
143
  Requires-Dist: cuml-cu12 (==24.12.0) ; extra == 'gpu'
144
144
  Requires-Dist: torch (==2.5.0) ; extra == 'gpu'
145
145
  Requires-Dist: ultralytics (==8.3.156) ; extra == 'gpu'
146
+ Requires-Dist: nvidia-cuda-runtime-cu12 ; extra == 'gpu'
146
147
 
147
148
  # SimBA (Simple Behavioral Analysis)
148
149
  ![SimBA Splash](https://raw.githubusercontent.com/sgoldenlab/simba/master/docs/tutorials_rst/img/index/landing_page_1.png)