Skip to content

Commit

Permalink
Merge pull request #288 from tzukpolinsky/master
Browse files Browse the repository at this point in the history
changes for python 3.9 and python 3.10
  • Loading branch information
sronilsson authored Oct 22, 2023
2 parents bfe025d + c775ab5 commit 5943b7c
Show file tree
Hide file tree
Showing 18 changed files with 374 additions and 335 deletions.
33 changes: 17 additions & 16 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
Pillow == 5.4.1
Pillow
pyyaml == 5.3.1
shapely == 1.7
shapely == 1.8
dtreeviz == 0.8.1
eli5 == 0.10.1
graphviz == 0.11
imblearn == 0.0
imgaug == 0.4.0
imutils == 0.5.2
matplotlib == 3.0.3
numpy == 1.18.1
opencv-python == 3.4.5.20
pandas == 0.25.3
scikit-image == 0.14.2
scipy == 1.5.4
matplotlib >= 3.0.3
numpy
opencv-python == 3.4.16.59
pandas
scikit-image
scipy
seaborn == 0.9.0
scikit-learn == 0.22.2
scikit-learn
tabulate == 0.8.3
tqdm == 4.30.0
xgboost == 0.90
yellowbrick == 0.9.1
yellowbrick
dash == 1.14.0
dash_color_picker == 0.0.1
dash_core_components == 1.10.2
dash_colorscales == 0.0.4
dash_html_components == 1.0.3
h5py == 2.9.0
numba == 0.52.0
numexpr == 2.6.9
h5py
numba
numexpr
plotly == 4.9.0
statsmodels == 0.9.0
statsmodels
cefpython3 == 66.0
pyarrow == 6.0.1
shap == 0.35.0
h5py==2.9.0
tables==3.6.1
tables>=3.6.1
xlrd==1.2.0
trafaret==2.1.1
geos
ffmpeg-python
112 changes: 58 additions & 54 deletions simba/SimBA.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@
from simba.ui.pop_ups.movement_analysis_pop_up import MovementAnalysisPopUp
from simba.ui.pop_ups.movement_analysis_time_bins_pop_up import \
MovementAnalysisTimeBinsPopUp
from simba.ui.pop_ups.mutual_exclusivity_pop_up import MutualExclusivityPupUp
#from simba.ui.pop_ups.mutual_exclusivity_pop_up import MutualExclusivityPupUp
from simba.ui.pop_ups.outlier_settings_pop_up import OutlierSettingsPopUp
from simba.ui.pop_ups.path_plot_pop_up import PathPlotPopUp
from simba.ui.pop_ups.pose_bp_drop_pop_up import DropTrackingDataPopUp
from simba.ui.pop_ups.pose_reorganizer_pop_up import PoseReorganizerPopUp
from simba.ui.pop_ups.pup_retrieval_pop_up import PupRetrievalPopUp
from simba.ui.pop_ups.quick_path_plot_pop_up import QuickLineplotPopup
from simba.ui.pop_ups.remove_roi_features_pop_up import RemoveROIFeaturesPopUp
#from simba.ui.pop_ups.remove_roi_features_pop_up import RemoveROIFeaturesPopUp
from simba.ui.pop_ups.roi_analysis_pop_up import ROIAnalysisPopUp
from simba.ui.pop_ups.roi_analysis_time_bins_pop_up import \
ROIAnalysisTimeBinsPopUp
Expand All @@ -114,9 +114,9 @@
ClipVideoPopUp, ConcatenatingVideosPopUp, ConcatenatorPopUp,
ConvertVideoPopUp, CreateGIFPopUP, CropVideoPopUp, DownsampleVideoPopUp,
ExtractAllFramesPopUp, ExtractAnnotationFramesPopUp, ExtractSEQFramesPopUp,
ExtractSpecificFramesPopUp, GreyscaleSingleVideoPopUp,
ExtractSpecificFramesPopUp,
ImportFrameDirectoryPopUp, MergeFrames2VideoPopUp, MultiCropPopUp,
MultiShortenPopUp, SuperImposeFrameCountPopUp, VideoRotatorPopUp,
MultiShortenPopUp, VideoRotatorPopUp,
VideoTemporalJoinPopUp)
from simba.ui.pop_ups.visualize_pose_in_dir_pop_up import \
VisualizePoseInFolderPopUp
Expand All @@ -138,39 +138,41 @@

# from simba.unsupervised.unsupervised_ui import UnsupervisedGUI

sys.setrecursionlimit(10**6)
sys.setrecursionlimit(10 ** 6)
currentPlatform = platform.system()


class LoadProjectPopUp(object):
def __init__(self):
main_frm = Toplevel()
main_frm.minsize(300, 200)
main_frm.wm_title("Load SimBA project (project_config.ini file)")
self.main_frm = Toplevel()
self.main_frm.minsize(300, 200)
self.main_frm.wm_title("Load SimBA project (project_config.ini file)")

load_project_frm = CreateLabelFrameWithIcon(
parent=main_frm,
self.load_project_frm = CreateLabelFrameWithIcon(
parent=self.main_frm,
header="LOAD SIMBA PROJECT_CONFIG.INI",
icon_name=Keys.DOCUMENTATION.value,
icon_link=Links.LOAD_PROJECT.value,
)
self.selected_file = FileSelect(
load_project_frm, "Select file: ", title="Select project_config.ini file"
self.load_project_frm, "Select file: ", title="Select project_config.ini file"
)
load_project_btn = Button(
load_project_frm,
self.load_project_btn = Button(
self.load_project_frm,
text="LOAD PROJECT",
fg="blue",
command=lambda: self.launch_project(),
)

load_project_frm.grid(row=0, sticky=NW)
self.load_project_frm.grid(row=0, sticky=NW)
self.selected_file.grid(row=0, sticky=NW)
load_project_btn.grid(row=1, pady=10, sticky=NW)
self.load_project_btn.grid(row=1, pady=10, sticky=NW)

def launch_project(self):
check_file_exist_and_readable(file_path=self.selected_file.file_path)
_ = SimbaProjectPopUp(config_path=self.selected_file.file_path)
self.load_project_frm.destroy()
self.main_frm.destroy()


def wait_for_internet_connection(url):
Expand Down Expand Up @@ -578,14 +580,14 @@ def activate(box, *args):
config_path=self.config_path
),
)
remove_roi_features_from_feature_set = Button(
roi_feature_frm,
text="REMOVE ROI FEATURES FROM FEATURE SET",
fg="darkred",
command=lambda: RemoveROIFeaturesPopUp(
config_path=self.config_path, dataset="features_extracted"
),
)
# remove_roi_features_from_feature_set = Button(
# roi_feature_frm,
# text="REMOVE ROI FEATURES FROM FEATURE SET",
# fg="darkred",
# command=lambda: RemoveROIFeaturesPopUp(
# config_path=self.config_path, dataset="features_extracted"
# ),
# )

feature_tools_frm = LabelFrame(
tab5,
Expand Down Expand Up @@ -773,14 +775,14 @@ def activate(box, *args):
config_path=self.config_path
),
)
remove_roi_features_from_annotation_set = Button(
lbl_tools_frm,
text="Remove ROI features from label set",
fg="darkred",
command=lambda: RemoveROIFeaturesPopUp(
config_path=self.config_path, dataset="targets_inserted"
),
)
# remove_roi_features_from_annotation_set = Button(
# lbl_tools_frm,
# text="Remove ROI features from label set",
# fg="darkred",
# command=lambda: RemoveROIFeaturesPopUp(
# config_path=self.config_path, dataset="targets_inserted"
# ),
# )

label_trainmachinemodel = CreateLabelFrameWithIcon(
parent=tab8,
Expand Down Expand Up @@ -898,12 +900,12 @@ def activate(box, *args):
fg="green",
command=lambda: FSTTCPopUp(config_path=self.config_path),
)
mutual_exclusivity = Button(
label_runmachinemodel,
text="MUTUAL EXCLUSIVITY CORRECTION",
fg="green",
command=lambda: MutualExclusivityPupUp(config_path=self.config_path),
)
# mutual_exclusivity = Button(
# label_runmachinemodel,
# text="MUTUAL EXCLUSIVITY CORRECTION",
# fg="green",
# command=lambda: MutualExclusivityPupUp(config_path=self.config_path),
# )

label_machineresults = CreateLabelFrameWithIcon(
parent=tab9,
Expand Down Expand Up @@ -1126,7 +1128,7 @@ def activate(box, *args):
roi_feature_frm.grid(row=1, column=0, sticky=NW)
append_roi_features_by_animal.grid(row=0, column=0, sticky=NW)
append_roi_features_by_body_part.grid(row=1, column=0, sticky=NW)
remove_roi_features_from_feature_set.grid(row=2, column=0, sticky=NW)
#remove_roi_features_from_feature_set.grid(row=2, column=0, sticky=NW)

feature_tools_frm.grid(row=2, column=0, sticky=NW)
compute_feature_subset_btn.grid(row=0, column=0, sticky=NW)
Expand Down Expand Up @@ -1160,7 +1162,7 @@ def activate(box, *args):
lbl_tools_frm.grid(row=9, column=0, sticky=NW)
visualize_annotation_img_btn.grid(row=0, column=0, sticky=NW)
third_party_annotations_btn.grid(row=1, column=0, sticky=NW)
remove_roi_features_from_annotation_set.grid(row=2, column=0, sticky=NW)
#remove_roi_features_from_annotation_set.grid(row=2, column=0, sticky=NW)

label_trainmachinemodel.grid(row=6, sticky=W)
button_trainmachinesettings.grid(row=0, column=0, sticky=NW, padx=5)
Expand All @@ -1181,7 +1183,7 @@ def activate(box, *args):
button_runmachinemodel.grid(row=1, sticky=NW)
kleinberg_button.grid(row=2, sticky=NW)
fsttc_button.grid(row=3, sticky=NW)
mutual_exclusivity.grid(row=4, sticky=NW)
#mutual_exclusivity.grid(row=4, sticky=NW)

label_machineresults.grid(row=9, sticky=W, pady=5)
button_process_datalog.grid(row=2, column=0, sticky=W, padx=3)
Expand Down Expand Up @@ -1609,18 +1611,18 @@ def __init__(self):
image=self.menu_icons["clahe"]["img"],
command=CLAHEPopUp,
)
video_process_menu.add_command(
label="Superimpose frame numbers on video",
compound="left",
image=self.menu_icons["trash"]["img"],
command=lambda: SuperImposeFrameCountPopUp(),
)
video_process_menu.add_command(
label="Convert to grayscale",
compound="left",
image=self.menu_icons["grey"]["img"],
command=lambda: GreyscaleSingleVideoPopUp(),
)
# video_process_menu.add_command(
# label="Superimpose frame numbers on video",
# compound="left",
# image=self.menu_icons["trash"]["img"],
# command=lambda: SuperImposeFrameCountPopUp(),
# )
# video_process_menu.add_command(
# label="Convert to grayscale",
# compound="left",
# image=self.menu_icons["grey"]["img"],
# command=lambda: GreyscaleSingleVideoPopUp(),
# )
video_process_menu.add_command(
label="Merge frames to video",
compound="left",
Expand Down Expand Up @@ -1828,12 +1830,14 @@ def __init__(self):

if OS.PYTHON_VER.value != "3.6":
PythonVersionWarning(
msg=f"SimBA is not extensively tested beyond python 3.6. You are using python {OS.PYTHON_VER.value}. If you encounter errors in python>3.6, please report them on GitHub or Gitter and we will fix! (links in the help toolbar)"
msg=f"SimBA is not extensively tested beyond python 3.6. You are using python {OS.PYTHON_VER.value}. If you encounter errors in python>3.6, please report them on GitHub or Gitter and we will fix! (links in the help toolbar)",
source="python different than 3.6"
)

if not check_ffmpeg_available():
FFMpegNotFoundWarning(
msg='SimBA could not find a FFMPEG installation on computer (as evaluated by "ffmpeg" returning None). SimBA works best with FFMPEG and it is recommended to install it on your computer'
msg='SimBA could not find a FFMPEG installation on computer (as evaluated by "ffmpeg" returning None). SimBA works best with FFMPEG and it is recommended to install it on your computer',
source="ffmpeg checker"
)

def restart(self):
Expand Down
2 changes: 1 addition & 1 deletion simba/data_processors/agg_clf_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def save(self) -> None:
self.results_df = (
self.results_df[
self.results_df["Measure"].isin(
self.chosen_measures + self.video_meta_data
self.chosen_measures# + self.video_meta_data
)
]
.sort_values(by=["Video", "Classifier", "Measure"])
Expand Down
4 changes: 2 additions & 2 deletions simba/labelling/labelling_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(
self.frm_no, self.threshold_dict = 0, threshold_dict
self.setting = setting
self.play_video_script_path = os.path.join(
os.path.dirname(simba.__file__), "play_annotation_video.py"
os.path.dirname(simba.__file__), "labelling/play_annotation_video.py"
)
_, self.video_name, _ = get_fn_ext(filepath=file_path)
self.features_extracted_file_path = os.path.join(
Expand Down Expand Up @@ -394,7 +394,7 @@ def __read_frm(self, frm_number=None):
_, self.current_frm_npy = self.cap.read()
self.current_frm_npy = cv2.cvtColor(self.current_frm_npy, cv2.COLOR_RGB2BGR)
self.current_frm_pil = Image.fromarray(self.current_frm_npy)
self.current_frm_pil.thumbnail(self.max_frm_size, Image.ANTIALIAS)
self.current_frm_pil.thumbnail(self.max_frm_size, Image.LANCZOS)
self.current_frm_pil = ImageTk.PhotoImage(
master=self.main_window, image=self.current_frm_pil
)
Expand Down
10 changes: 5 additions & 5 deletions simba/mixins/pop_up_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ def __init__(
config_path: Optional[str] = None,
size: Tuple[int, int] = (400, 400),
):
self.main_frm = Toplevel()
self.main_frm.minsize(size[0], size[1])
self.main_frm.wm_title(title)
self.main_frm.lift()
self.main_frm = Canvas(hxtScrollbar(self.main_frm))
self.root = Toplevel()
self.root.minsize(size[0], size[1])
self.root.wm_title(title)
self.root.lift()
self.main_frm = Canvas(hxtScrollbar(self.root))
self.main_frm.pack(fill="both", expand=True)

self.palette_options = Options.PALETTE_OPTIONS.value
Expand Down
4 changes: 1 addition & 3 deletions simba/mixins/train_model_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,6 @@ def dviz_classification_visualization(
:parameter List[str] class_names: List of class names. E.g., ['Attack absent', 'Attack present']
:parameter str save_dir: Directory where to save output in csv file format.
"""

clf = tree.DecisionTreeClassifier(max_depth=5, random_state=666)
clf.fit(x_train, y_train)
try:
Expand Down Expand Up @@ -1291,8 +1290,7 @@ def clf_predict_proba(
else:
raise FeatureNumberMismatchError(
f"The model expects {clf_n_features} features. The data contains {len(x_df.columns)} features.",
source=self.__class__.__name__,
)
source=self.__class__.__name__)
p_vals = clf.predict_proba(x_df)
if p_vals.shape[1] != 2:
raise ClassifierInferenceError(
Expand Down
Loading

0 comments on commit 5943b7c

Please sign in to comment.