simba-uw-tf-dev 4.7.4__py3-none-any.whl → 4.7.6__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.

Potentially problematic release.


This version of simba-uw-tf-dev might be problematic. Click here for more details.

@@ -5,7 +5,7 @@ from typing import Union
5
5
 
6
6
  from simba.mixins.config_reader import ConfigReader
7
7
  from simba.utils.checks import check_if_filepath_list_is_empty
8
- from simba.utils.printing import SimbaTimer, stdout_success
8
+ from simba.utils.printing import SimbaTimer, stdout_information, stdout_success
9
9
  from simba.utils.read_write import get_fn_ext, read_df, write_df
10
10
 
11
11
 
@@ -43,7 +43,7 @@ class OutlierCorrectionSkipper(ConfigReader):
43
43
  save_path = os.path.join(self.outlier_corrected_dir, f"{video_name}.{self.file_type}")
44
44
  write_df(df=data_df, file_type=self.file_type, save_path=save_path)
45
45
  video_timer.stop_timer()
46
- print(f"Skipped outlier correction for video {video_name} (elapsed time {video_timer.elapsed_time_str}s)...")
46
+ stdout_information(msg=f"Skipped outlier correction for video {video_name} (Video {file_cnt+1}/{len(self.input_csv_paths)})", elapsed_time=video_timer.elapsed_time_str)
47
47
  self.timer.stop_timer()
48
48
  stdout_success(msg=f"Skipped outlier correction for {len(self.input_csv_paths)} files", elapsed_time=self.timer.elapsed_time_str)
49
49
 
@@ -17,7 +17,7 @@ from simba.utils.checks import (
17
17
  check_all_file_names_are_represented_in_video_log,
18
18
  check_filepaths_in_iterable_exist, check_int, check_str,
19
19
  check_valid_boolean, check_valid_dataframe, check_valid_dict)
20
- from simba.utils.data import terminate_cpu_pool
20
+ from simba.utils.data import get_cpu_pool, terminate_cpu_pool
21
21
  from simba.utils.enums import Formats
22
22
  from simba.utils.errors import InvalidInputError, NoSpecifiedOutputError
23
23
  from simba.utils.printing import SimbaTimer, stdout_success
@@ -149,6 +149,7 @@ class HeatMapperClfMultiprocess(ConfigReader, PlottingMixin):
149
149
  def run(self):
150
150
  print(f"Processing {len(self.data_paths)} video(s)...")
151
151
  check_all_file_names_are_represented_in_video_log(video_info_df=self.video_info_df, data_paths=self.data_paths)
152
+ pool = get_cpu_pool(core_cnt=self.core_cnt, source=self.__class__.__name__)
152
153
  for file_cnt, file_path in enumerate(self.data_paths):
153
154
  video_timer = SimbaTimer(start=True)
154
155
  _, self.video_name, _ = get_fn_ext(file_path)
@@ -173,7 +174,8 @@ class HeatMapperClfMultiprocess(ConfigReader, PlottingMixin):
173
174
  if len(np.unique(clf_data)) == 1:
174
175
  raise InvalidInputError(msg=f'Cannot plot heatmap for behavior {self.clf_name} in video {self.video_name}. The behavior is classified as {np.unique(clf_data)} in every single frame.')
175
176
  grid, aspect_ratio = GeometryMixin.bucket_img_into_grid_square(img_size=(self.width, self.height), bucket_grid_size_mm=self.bin_size, px_per_mm=self.px_per_mm, add_correction=False, verbose=False)
176
- clf_data = GeometryMixin().cumsum_bool_geometries(data=bp_data, geometries=grid, bool_data=clf_data, fps=self.fps, verbose=False)
177
+
178
+ clf_data = GeometryMixin().cumsum_bool_geometries(data=bp_data, geometries=grid, bool_data=clf_data, fps=self.fps, verbose=False, core_cnt=self.core_cnt, pool=pool)
177
179
  if self.max_scale == "auto":
178
180
  self.max_scale = max(1, self.__calculate_max_scale(clf_array=clf_data))
179
181
  if self.final_img_setting:
@@ -197,32 +199,29 @@ class HeatMapperClfMultiprocess(ConfigReader, PlottingMixin):
197
199
  frm_per_core_w_batch.append((batch_cnt, frm_range, frame_arrays[batch_cnt]))
198
200
  del frame_arrays
199
201
  print(f"Creating heatmaps, multiprocessing (chunksize: {self.multiprocess_chunksize}, cores: {self.core_cnt})...")
200
- with multiprocessing.Pool(self.core_cnt, maxtasksperchild=self.maxtasksperchild) as pool:
201
- constants = functools.partial(_heatmap_multiprocessor,
202
- video_setting=self.video_setting,
203
- frame_setting=self.frame_setting,
204
- style_attr=self.style_attr,
205
- fps=self.fps,
206
- video_temp_dir=self.temp_folder,
207
- frame_dir=self.frames_save_dir,
208
- max_scale=self.max_scale,
209
- aspect_ratio=aspect_ratio,
210
- clf_name=self.clf_name,
211
- size=(self.width, self.height),
212
- video_name=self.video_name,
213
- make_clf_heatmap_plot=self.make_clf_heatmap_plot)
214
-
215
- for cnt, batch in enumerate(pool.imap(constants, frm_per_core_w_batch, chunksize=self.multiprocess_chunksize)):
216
- print(f'Batch core {batch+1}/{self.core_cnt} complete (Video {self.video_name})... ')
217
- terminate_cpu_pool(pool=pool, force=False)
218
-
202
+ constants = functools.partial(_heatmap_multiprocessor,
203
+ video_setting=self.video_setting,
204
+ frame_setting=self.frame_setting,
205
+ style_attr=self.style_attr,
206
+ fps=self.fps,
207
+ video_temp_dir=self.temp_folder,
208
+ frame_dir=self.frames_save_dir,
209
+ max_scale=self.max_scale,
210
+ aspect_ratio=aspect_ratio,
211
+ clf_name=self.clf_name,
212
+ size=(self.width, self.height),
213
+ video_name=self.video_name,
214
+ make_clf_heatmap_plot=self.make_clf_heatmap_plot)
215
+
216
+
217
+ for cnt, batch in enumerate(pool.imap(constants, frm_per_core_w_batch, chunksize=self.multiprocess_chunksize)):
218
+ print(f'Batch core {batch+1}/{self.core_cnt} complete (Video {self.video_name})... ')
219
219
  if self.video_setting:
220
220
  print(f"Joining {self.video_name} multiprocessed video...")
221
221
  concatenate_videos_in_folder(in_folder=self.temp_folder, save_path=self.save_video_path)
222
-
223
222
  video_timer.stop_timer()
224
223
  print(f"Heatmap video {self.video_name} complete, (elapsed time: {video_timer.elapsed_time_str}s) ...")
225
-
224
+ terminate_cpu_pool(pool=pool, force=False, source=self.__class__.__name__)
226
225
  self.timer.stop_timer()
227
226
  stdout_success(msg=f"Heatmap visualizations for {len(self.data_paths)} video(s) created in {self.heatmap_clf_location_dir} directory", elapsed_time=self.timer.elapsed_time_str)
228
227
 
@@ -261,3 +260,26 @@ class HeatMapperClfMultiprocess(ConfigReader, PlottingMixin):
261
260
  # core_cnt=5,
262
261
  # files_found=['/Users/simon/Desktop/envs/troubleshooting/two_black_animals_14bp/project_folder/csv/machine_results/Together_1.csv'])
263
262
  # test.create_heatmaps()
263
+ # if __name__ == "__main__":
264
+ # x = HeatMapperClfMultiprocess(config_path=r"E:\troubleshooting\mitra_emergence\project_folder\project_config.ini",
265
+ # bodypart='nose',
266
+ # clf_name='GROOMING',
267
+ # style_attr={'palette': 'jet', 'shading': 'gouraud', 'bin_size': 25, 'max_scale': 'auto'},
268
+ # final_img_setting=True,
269
+ # video_setting=False,
270
+ # frame_setting=False,
271
+ # core_cnt=12,
272
+ # data_paths=[r"E:\troubleshooting\mitra_emergence\project_folder\csv\machine_results\Box1_180mISOcontrol_Females.csv"])
273
+ #
274
+ # x.run()
275
+
276
+ # def __init__(self,
277
+ # config_path: Union[str, os.PathLike],
278
+ # bodypart: str,
279
+ # clf_name: str,
280
+ # data_paths: List[str],
281
+ # style_attr: dict,
282
+ # final_img_setting: bool = True,
283
+ # video_setting: bool = False,
284
+ # frame_setting: bool = False,
285
+ # core_cnt: int = -1):
@@ -236,7 +236,8 @@ class PlotSklearnResultsSingleCore(ConfigReader, TrainModelMixin, PlottingMixin)
236
236
  self.add_spacer += 1
237
237
  if self.show_confidence:
238
238
  col_name = f'Probability_{clf_name}'
239
- conf_txt = f'{clf_name} CONFIDENCE {self.data_df.loc[frm_idx, col_name]}'
239
+ conf = round(self.data_df.loc[frm_idx, col_name], 4)
240
+ conf_txt = f'{clf_name} CONFIDENCE {conf:.4f}'
240
241
  self.frame = PlottingMixin().put_text(img=self.frame, text=conf_txt, pos=(TextOptions.BORDER_BUFFER_Y.value, ((self.video_meta_data["height"] - self.video_meta_data["height"]) + self.video_space_size * self.add_spacer)), font_size=self.video_font_size, font_thickness=self.video_text_thickness, font=self.font, text_bg_alpha=self.video_text_opacity, text_color_bg=self.text_bg_color, text_color=self.text_color)
241
242
  self.add_spacer += 1
242
243
  self.frame = PlottingMixin().put_text(img=self.frame, text="ENSEMBLE PREDICTION:", pos=(TextOptions.BORDER_BUFFER_Y.value, ((self.video_meta_data["height"] - self.video_meta_data["height"]) + self.video_space_size * self.add_spacer)), font_size=self.video_font_size, font_thickness=self.video_text_thickness, font=self.font, text_bg_alpha=self.video_text_opacity, text_color_bg=self.text_bg_color, text_color=self.text_color)