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

@@ -0,0 +1,9 @@
1
+ left_ear
2
+ right_ear
3
+ nose
4
+ left_side
5
+ right_side
6
+ tail_base
7
+ center
8
+ tail_center
9
+ tail_tip
@@ -1070,10 +1070,7 @@ class TrainModelMixin(object):
1070
1070
  MissingUserInputWarning(msg=f'Skipping {str(config.get("SML settings", "target_name_" + str(n + 1)))} classifier analysis: missing information (e.g., no discrimination threshold and/or minimum bout set in the project_config.ini',source=self.__class__.__name__)
1071
1071
 
1072
1072
  if len(model_dict.keys()) == 0:
1073
- raise NoDataError(
1074
- msg=f"There are no models with accurate data specified in the RUN MODELS menu. Specify the model information to SimBA RUN MODELS menu to use them to analyze videos",
1075
- source=self.get_model_info.__name__,
1076
- )
1073
+ raise NoDataError(msg=f"There are no models with accurate data specified in the RUN MODELS menu. Specify the model information to SimBA RUN MODELS menu to use them to analyze videos. PLease check the model paths, thresholds, and minimum bout lengths.", source=self.get_model_info.__name__)
1077
1074
  else:
1078
1075
  return model_dict
1079
1076
 
@@ -101,7 +101,7 @@ class InferenceBatch(TrainModelMixin, ConfigReader):
101
101
  video_timer.stop_timer()
102
102
  print(f"Predictions created for {file_name} (frame count: {len(in_df)}, elapsed time: {video_timer.elapsed_time_str}) ...")
103
103
  self.timer.stop_timer()
104
- stdout_success(msg=f"Machine predictions complete. Files saved in {self.save_dir} directory", elapsed_time=self.timer.elapsed_time_str, source=self.__class__.__name__)
104
+ stdout_success(msg=f"Machine predictions complete for {len(self.feature_file_paths)} file(s). Files saved in {self.save_dir} directory", elapsed_time=self.timer.elapsed_time_str, source=self.__class__.__name__)
105
105
 
106
106
  if __name__ == "__main__" and not hasattr(sys, 'ps1'):
107
107
  parser = argparse.ArgumentParser(description="Perform classifications according to rules defined in SImAB project_config.ini.")
@@ -117,12 +117,15 @@ class SimBA2Yolo:
117
117
  annotations, timer, body_part_headers = [], SimbaTimer(start=True), []
118
118
  for file_cnt, video_name in enumerate(self.data_w_video):
119
119
  data = read_df(file_path=self.data_paths[video_name], file_type=self.config.file_type)
120
+ data.columns = [x.lower() for x in list(data.columns)]
121
+ bp_header_names = [x.lower() for x in self.config.bp_headers]
120
122
  check_valid_dataframe(df=data, source=f'{self.__class__.__name__} {self.data_paths[video_name]}', valid_dtypes=Formats.NUMERIC_DTYPES.value)
121
123
  video_path = self.video_paths[video_name]
122
124
  check_video_and_data_frm_count_align(video=video_path, data=data, name=self.data_paths[video_name], raise_error=True)
123
125
  p_data = data[data.columns[list(data.columns.str.endswith('_p'))]]
124
126
  data = data.loc[:, ~data.columns.str.endswith('_p')].reset_index(drop=True)
125
127
  data = data.iloc[(p_data[(p_data > self.threshold).all(axis=1)].index)]
128
+ data = data[[x for x in bp_header_names if not x.endswith('_p')]]
126
129
  body_part_headers = data.columns
127
130
  data['video'], frm_cnt = video_name, len(data)
128
131
  if self.sample_size is None:
@@ -155,7 +158,7 @@ class SimBA2Yolo:
155
158
  if frm_idx in train_idx:
156
159
  img_save_path, lbl_save_path = os.path.join(self.img_train_dir, f'{file_name}.png'), os.path.join(self.lbl_train_dir, f'{file_name}.txt')
157
160
  else:
158
- img_save_path, lbl_save_path = os.path.join(self.img_train_dir, f'{file_name}.png'), os.path.join(self.lb_val_dir, f'{file_name}.txt')
161
+ img_save_path, lbl_save_path = os.path.join(self.img_val_dir, f'{file_name}.png'), os.path.join(self.lb_val_dir, f'{file_name}.txt')
159
162
  img = read_frm_of_video(video_path=vid_path, frame_index=frm_idx, greyscale=self.greyscale, clahe=self.clahe)
160
163
  img_h, img_w = img.shape[0], img.shape[1]
161
164
  keypoints_with_id = {}
@@ -181,8 +184,8 @@ class SimBA2Yolo:
181
184
  timer.stop_timer()
182
185
  stdout_success(msg=f'YOLO formated data saved in {self.save_dir} directory', source=self.__class__.__name__, elapsed_time=timer.elapsed_time_str)
183
186
 
184
-
185
- # SAVE_DIR = r'D:\troubleshooting\mitra\mitra_yolo'
186
- # CONFIG_PATH = r"C:\troubleshooting\mitra\project_folder\project_config.ini"
187
- # runner = SimBA2Yolo(config_path=CONFIG_PATH, save_dir=SAVE_DIR, sample_size=10, verbose=True, names=('animal_1',))
187
+ #
188
+ # SAVE_DIR = r'E:\troubleshooting\mitra\yolo_0126\yolo_train_0126'
189
+ # CONFIG_PATH = r"E:\troubleshooting\mitra\project_folder\project_config.ini"
190
+ # runner = SimBA2Yolo(config_path=CONFIG_PATH, save_dir=SAVE_DIR, sample_size=50, verbose=True, names=('animal_1',), threshold=0.5)
188
191
  # runner.run()
@@ -8,7 +8,7 @@ from simba.mixins.config_reader import ConfigReader
8
8
  from simba.mixins.pop_up_mixin import PopUpMixin
9
9
  from simba.model.inference_batch import InferenceBatch
10
10
  from simba.ui.tkinter_functions import (CreateLabelFrameWithIcon, Entry_Box,
11
- FileSelect, SimbaButton, SimBADropDown,
11
+ FileSelect, SimbaButton, SimBASeperator,
12
12
  SimBALabel)
13
13
  from simba.utils.checks import (check_file_exist_and_readable, check_float,
14
14
  check_int)
@@ -31,34 +31,34 @@ class RunMachineModelsPopUp(PopUpMixin, ConfigReader):
31
31
  def __init__(self, config_path: Union[str, os.PathLike]):
32
32
  ConfigReader.__init__(self, config_path=config_path, read_video_info=False)
33
33
  PopUpMixin.__init__(self, title="SET MODEL PARAMETERS", icon='equation_small')
34
+ padx, self.config_path = (0, 25), config_path
34
35
  self.clf_table_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SETTINGS", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.SET_RUN_ML_PARAMETERS.value)
35
- clf_header = SimBALabel(parent=self.clf_table_frm, txt="CLASSIFIER", font=Formats.FONT_HEADER.value)
36
- mdl_path_header = SimBALabel(parent=self.clf_table_frm, txt="MODEL PATH (.SAV)", font=Formats.FONT_HEADER.value)
37
- threshold_header = SimBALabel(parent=self.clf_table_frm, txt="THRESHOLD (0.0 - 1.0)", font=Formats.FONT_HEADER.value)
38
- min_bout_header = SimBALabel(parent=self.clf_table_frm, txt="MINIMUM BOUT LENGTH (MS)", font=Formats.FONT_HEADER.value)
39
- clf_header.grid(row=0, column=0, sticky=W, padx=(0, 10))
40
- mdl_path_header.grid(row=0, column=1, sticky=NW)
41
- threshold_header.grid(row=0, column=2, sticky=NW)
42
- min_bout_header.grid(row=0, column=3, sticky=NW)
36
+ clf_header = SimBALabel(parent=self.clf_table_frm, txt="CLASSIFIER", font=Formats.FONT_HEADER.value, img='label')
37
+ mdl_path_header = SimBALabel(parent=self.clf_table_frm, txt="MODEL PATH (.SAV)", font=Formats.FONT_HEADER.value, img='file_type', justify='center')
38
+ threshold_header = SimBALabel(parent=self.clf_table_frm, txt="THRESHOLD (0.0 - 1.0)", font=Formats.FONT_HEADER.value, img='threshold', justify='center')
39
+ min_bout_header = SimBALabel(parent=self.clf_table_frm, txt="MINIMUM BOUT LENGTH (MS)", font=Formats.FONT_HEADER.value, img='timer_2', justify='center')
40
+ clf_header.grid(row=0, column=0, sticky=NW, padx=padx)
41
+ mdl_path_header.grid(row=0, column=1, sticky=NW, padx=padx)
42
+ threshold_header.grid(row=0, column=2, sticky=NW, padx=padx)
43
+ min_bout_header.grid(row=0, column=3, sticky=NW, padx=padx)
44
+
45
+ seperator = SimBASeperator(parent=self.clf_table_frm, color='grey', orient='horizontal', borderwidth=1)
46
+ seperator.grid(row=1, column=0, columnspan=4, rowspan=1, sticky="ew", pady=(0, 10))
43
47
 
44
48
  self.clf_data = {}
45
49
  for clf_cnt, clf_name in enumerate(self.clf_names):
46
50
  self.clf_data[clf_name] = {}
47
- SimBALabel(parent=self.clf_table_frm, txt=clf_name, font=Formats.FONT_REGULAR_ITALICS.value).grid(row=clf_cnt + 1, column=0, sticky=W, padx=(0, 10))
51
+ SimBALabel(parent=self.clf_table_frm, txt=clf_name, font=Formats.FONT_REGULAR_ITALICS.value).grid(row=clf_cnt + 2, column=0, sticky=W, padx=padx)
48
52
  mdl_path = read_config_entry(config=self.config, section=ConfigKey.SML_SETTINGS.value, option=f"model_path_{clf_cnt + 1}", default_value='Select model (.sav) file', data_type=Dtypes.STR.value)
49
53
  self.clf_data[clf_name][PATH] = FileSelect(self.clf_table_frm, title="Select model (.sav) file", initialdir=self.project_path, file_types=[("SimBA Classifier", "*.sav")], initial_path=mdl_path)
50
54
  threshold = read_config_entry(config=self.config, section=ConfigKey.THRESHOLD_SETTINGS.value, option=f"threshold_{clf_cnt + 1}", default_value='', data_type=Dtypes.STR.value)
51
- self.clf_data[clf_name][THRESHOLD] = Entry_Box(parent=self.clf_table_frm, fileDescription='', labelwidth=0, entry_box_width=20, value=threshold)
55
+ self.clf_data[clf_name][THRESHOLD] = Entry_Box(parent=self.clf_table_frm, fileDescription='', labelwidth=0, entry_box_width=20, value=threshold, justify='center')
52
56
  bout_length = read_config_entry(config=self.config, section=ConfigKey.MIN_BOUT_LENGTH.value, option=f"min_bout_{clf_cnt + 1}", default_value='', data_type=Dtypes.STR.value)
53
- self.clf_data[clf_name][MIN_BOUT] = Entry_Box(parent=self.clf_table_frm, fileDescription='', labelwidth=0, entry_box_width=20, value=bout_length)
54
- self.clf_data[clf_name][PATH].grid(row=clf_cnt + 1, column=1, sticky=NW, padx=(0, 5))
55
- self.clf_data[clf_name][THRESHOLD].grid(row=clf_cnt + 1, column=2, sticky=NW, padx=(0, 5))
56
- self.clf_data[clf_name][MIN_BOUT].grid(row=clf_cnt + 1, column=3, sticky=NW, padx=(0, 5))
57
+ self.clf_data[clf_name][MIN_BOUT] = Entry_Box(parent=self.clf_table_frm, fileDescription='', labelwidth=0, entry_box_width=20, value=bout_length, justify='center')
58
+ self.clf_data[clf_name][PATH].grid(row=clf_cnt + 2, column=1, sticky=NW, padx=padx)
59
+ self.clf_data[clf_name][THRESHOLD].grid(row=clf_cnt + 2, column=2, sticky=NW, padx=padx)
60
+ self.clf_data[clf_name][MIN_BOUT].grid(row=clf_cnt + 2, column=3, sticky=NW, padx=padx)
57
61
  self.clf_table_frm.grid(row=0, sticky=W, pady=5, padx=5)
58
- # self.runtime_settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="RUNTIME SETTINGS", icon_name='run', icon_link=Links.SET_RUN_ML_PARAMETERS.value)
59
- # self.core_cnt_dropdown = SimBADropDown(parent=self.runtime_settings_frm, dropdown_options=CORE_CNT_OPTIONS, label='CPU CORE COUNT:', label_width=30, dropdown_width=20, value=int(find_core_cnt()[0]/3))
60
- # self.runtime_settings_frm.grid(row=1, sticky=W, pady=5, padx=5)
61
- # self.core_cnt_dropdown.grid(row=0, sticky=W, pady=5, padx=5)
62
62
  run_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header=f"ANALYZE {len(self.feature_file_paths)} FILES(S)", icon_name='rocket')
63
63
  run_btn = SimbaButton(parent=run_frm, txt="RUN", img='rocket', txt_clr='red', font=Formats.FONT_REGULAR.value, hover_font=Formats.FONT_REGULAR.value, cmd=self.run)
64
64
  run_frm.grid(row=2, sticky=W, pady=5, padx=5)
@@ -95,7 +95,7 @@ class RunMachineModelsPopUp(PopUpMixin, ConfigReader):
95
95
  with open(self.config_path, "w") as f:
96
96
  self.config.write(f)
97
97
 
98
- stdout_success(msg="Model paths/settings saved in project_config.ini", source=self.__class__.__name__)
98
+ stdout_success(msg=f"Model paths/settings saved in project_config.ini ({self.config_path})", source=self.__class__.__name__)
99
99
 
100
100
  if len(self.feature_file_paths) == 0:
101
101
  raise NoDataError(msg=f'Cannot run machine model predictions: No data files found in {self.features_dir} directory', source=self.__class__.__name__)
@@ -103,4 +103,4 @@ class RunMachineModelsPopUp(PopUpMixin, ConfigReader):
103
103
  inferencer = InferenceBatch(config_path=self.config_path, features_dir=None, save_dir=None, minimum_bout_length=None)
104
104
  inferencer.run()
105
105
 
106
- #_ = RunMachineModelsPopUp(config_path=r"D:\troubleshooting\mitra\project_folder\project_config.ini")
106
+ #_ = RunMachineModelsPopUp(config_path=r"E:\troubleshooting\mitra_emergence\project_folder\project_config.ini")
@@ -63,7 +63,7 @@ class SimBA2YoloKeypointsPopUp(PopUpMixin):
63
63
  animal_names = list(config.animal_bp_dict.keys())
64
64
  bps = [x[:-2] for x in config.animal_bp_dict[animal_names[0]]['X_bps']]
65
65
  flip_idx = get_yolo_keypoint_flip_idx(x=bps)
66
- map_dict = {c: k for c, k in enumerate(animal_names)}
66
+ #map_dict = {c: k for c, k in enumerate(animal_names)}
67
67
  bp_id_idx = None
68
68
  if len(animal_names) > 1:
69
69
  bp_id_idx = get_yolo_keypoint_bp_id_idx(animal_bp_dict=config.animal_bp_dict)
@@ -85,7 +85,7 @@ class SimBA2YoloKeypointsPopUp(PopUpMixin):
85
85
  greyscale=grey,
86
86
  padding=padding,
87
87
  flip_idx=flip_idx,
88
- names=map_dict,
88
+ names=tuple(animal_names),
89
89
  sample_size=sample_size,
90
90
  bp_id_idx=bp_id_idx,
91
91
  clahe=clahe)
@@ -30,7 +30,7 @@ SMOOTHING_OPTIONS = ['None', 50, 100, 200, 300, 400, 500]
30
30
 
31
31
  YOLO_FORMATS = Options.VALID_YOLO_FORMATS.value + ['None']
32
32
  devices = ['CPU']
33
- THRESHOLD_OPTIONS = list(np.arange(0.1, 1.1, 0.1).astype(np.float32))
33
+ THRESHOLD_OPTIONS = list(np.arange(0.05, 1.05, 0.05).astype(np.float32))
34
34
 
35
35
  simba_dir = os.path.dirname(simba.__file__)
36
36
  YOLO_SCHEMATICS_DIR = os.path.join(simba_dir, Paths.YOLO_SCHEMATICS_DIR.value)
@@ -33,7 +33,7 @@ class YOLOPoseTrainPopUP(PopUpMixin):
33
33
  PopUpMixin.__init__(self, title="TRAIN YOLO POSE ESTIMATION MODEL", icon='ultralytics_2')
34
34
  settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SETTINGS", icon_name='settings')
35
35
  devices.extend([f'{x} : {y["model"]}' for x, y in gpus.items()])
36
- self.yolo_map_path = FileSelect(parent=settings_frm, fileDescription='YOLO MAP FILE (YAML):', lblwidth=35, entry_width=45, file_types=[("YOLO MODEL FILE", Options.ALL_YOLO_MODEL_FORMAT_STR_OPTIONS.value)], lbl_icon='file')
36
+ self.yolo_map_path = FileSelect(parent=settings_frm, fileDescription='YOLO MAP FILE (YAML):', lblwidth=35, entry_width=45, file_types=[("YOLO MODEL FILE", ".yaml")], lbl_icon='file')
37
37
  self.save_dir = FolderSelect(settings_frm, folderDescription="SAVE DIRECTORY:", lblwidth=35, entry_width=45, lbl_icon='save')
38
38
  self.weights_path = FileSelect(parent=settings_frm, fileDescription='INITIAL WEIGHT FILE (E.G., .PT):', lblwidth=35, entry_width=45, lbl_icon='file')
39
39