Skip to content

Commit

Permalink
Black coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexEMG committed Apr 26, 2021
1 parent 44a9ac1 commit e2c8047
Show file tree
Hide file tree
Showing 58 changed files with 2,069 additions and 1,792 deletions.
1 change: 1 addition & 0 deletions deeplabcut/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

try:
import wx

mpl.use("WxAgg")
from deeplabcut import generate_training_dataset
from deeplabcut import refine_training_dataset
Expand Down
5 changes: 4 additions & 1 deletion deeplabcut/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""
try:
import wx

lite = False
except ModuleNotFoundError:
lite = True
Expand All @@ -20,4 +21,6 @@

deeplabcut.launch_dlc()
else:
print("You installed DLC lite, thus GUI's cannot be used. If you need GUI support please: pip install deeplabcut[gui]")
print(
"You installed DLC lite, thus GUI's cannot be used. If you need GUI support please: pip install deeplabcut[gui]"
)
12 changes: 9 additions & 3 deletions deeplabcut/generate_training_dataset/trainingsetmanipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ def cropimagesandlabels(
# moving old entry to _original, dropping it from video_set and update crop parameters
video_orig = sep.join((vidpath, vidname + videotype))
if video_orig not in cfg["video_sets_original"]:
cfg["video_sets_original"][video_orig] = cfg["video_sets"][video_orig]
cfg["video_sets_original"][video_orig] = cfg["video_sets"][
video_orig
]
cfg["video_sets"].pop(video_orig)
cfg["video_sets"][sep.join((vidpath, new_vidname + videotype))] = {
"crop": ", ".join(map(str, [0, temp_size[1], 0, temp_size[0]]))
Expand Down Expand Up @@ -461,7 +463,7 @@ def check_labels(
for folder in folders:
try:
DataCombined = pd.read_hdf(
os.path.join(str(folder), "CollectedData_" + cfg["scorer"] + ".h5"),
os.path.join(str(folder), "CollectedData_" + cfg["scorer"] + ".h5")
)
if cfg.get("multianimalproject", False):
color_by = "individual" if visualizeindividuals else "bodypart"
Expand Down Expand Up @@ -887,7 +889,11 @@ def create_training_dataset(
if net_type is None: # loading & linking pretrained models
net_type = cfg.get("default_net_type", "resnet_50")
else:
if "resnet" in net_type or "mobilenet" in net_type or "efficientnet" in net_type:
if (
"resnet" in net_type
or "mobilenet" in net_type
or "efficientnet" in net_type
):
pass
else:
raise ValueError("Invalid network type:", net_type)
Expand Down
6 changes: 1 addition & 5 deletions deeplabcut/gui/auxfun_drag.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ def on_press(self, event):
message = f"Do you want to remove the label {self.bodyParts}?"
if self.likelihood is not None:
message += " You cannot undo this step!"
msg = wx.MessageBox(
message,
"Remove!",
wx.YES_NO | wx.ICON_WARNING,
)
msg = wx.MessageBox(message, "Remove!", wx.YES_NO | wx.ICON_WARNING)
if msg == 2:
self.delete_data()

Expand Down
8 changes: 6 additions & 2 deletions deeplabcut/gui/create_training_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def __init__(self, parent, gui_size, cfg):
)
self.cropandlabel.Bind(wx.EVT_RADIOBOX, self.input_crop_size)
self.cropandlabel.SetSelection(0)
self.crop_text = wx.StaticBox(self, label="Crop settings (set to smaller than your input images)")
self.crop_text = wx.StaticBox(
self, label="Crop settings (set to smaller than your input images)"
)
self.crop_sizer = wx.StaticBoxSizer(self.crop_text, wx.VERTICAL)
self.crop_widgets = []
for name, val in [
Expand All @@ -171,7 +173,9 @@ def __init__(self, parent, gui_size, cfg):
self.hbox3.Add(self.userfeedback, 10, wx.EXPAND | wx.TOP | wx.BOTTOM, 5)

if config_file.get("multianimalproject", False):
print("more networks are available soon for maDLC, but currenlty this uses DLC-ResNet50 only")
print(
"more networks are available soon for maDLC, but currenlty this uses DLC-ResNet50 only"
)
self.model_comparison_choice = "No"
else:
self.model_comparison_choice = wx.RadioBox(
Expand Down
7 changes: 4 additions & 3 deletions deeplabcut/gui/frame_extraction_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def getColorIndices(self, img, bodyparts):
class MainFrame(BaseFrame):
def __init__(self, parent, config, slider_width=25):
super(MainFrame, self).__init__(
"DeepLabCut2.0 - Manual Frame Extraction", parent,
"DeepLabCut2.0 - Manual Frame Extraction", parent
)

###################################################################################################################################################
Expand Down Expand Up @@ -158,8 +158,9 @@ def __init__(self, parent, config, slider_width=25):
self.date = self.cfg["date"]
self.trainFraction = self.cfg["TrainingFraction"]
self.trainFraction = self.trainFraction[0]
self.videos = list(self.cfg.get("video_sets_original")
or self.cfg["video_sets"])
self.videos = list(
self.cfg.get("video_sets_original") or self.cfg["video_sets"]
)
self.bodyparts = self.cfg["bodyparts"]
self.colormap = plt.get_cmap(self.cfg["colormap"])
self.colormap = self.colormap.reversed()
Expand Down
4 changes: 1 addition & 3 deletions deeplabcut/gui/label_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def label_frames(
os.chdir(str(wd))
cfg = auxiliaryfunctions.read_config(config)
if cfg.get("multianimalproject", False) or multiple_individualsGUI:
from deeplabcut.gui import (
multiple_individuals_labeling_toolbox,
)
from deeplabcut.gui import multiple_individuals_labeling_toolbox

multiple_individuals_labeling_toolbox.show(config, config3d, sourceCam)
else:
Expand Down
23 changes: 11 additions & 12 deletions deeplabcut/gui/labeling_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def retrieveData_and_computeEpLines(self, img, imNum):
if self.sourceCam is None:
sourceCam = [
otherCam for otherCam in cams if cam not in otherCam
][0] #WHY?
][
0
] # WHY?
else:
sourceCam = self.sourceCam

Expand All @@ -80,11 +82,13 @@ def retrieveData_and_computeEpLines(self, img, imNum):

try:
dataFrame = pd.read_hdf(
os.path.join(sourceCam_path, "CollectedData_" + scorer + ".h5"),
os.path.join(sourceCam_path, "CollectedData_" + scorer + ".h5")
)
dataFrame.sort_index(inplace=True)
except IOError:
print("source camera images have not yet been labeled, or you have opened this folder in the wrong mode!")
print(
"source camera images have not yet been labeled, or you have opened this folder in the wrong mode!"
)
return None, None, None

# Find offset terms for drawing epipolar Lines
Expand Down Expand Up @@ -241,7 +245,7 @@ def clearBoxer(self):
class MainFrame(BaseFrame):
def __init__(self, parent, config, imtypes, config3d, sourceCam):
super(MainFrame, self).__init__(
"DeepLabCut2.0 - Labeling ToolBox", parent, imtypes,
"DeepLabCut2.0 - Labeling ToolBox", parent, imtypes
)

self.statusbar.SetStatusText(
Expand Down Expand Up @@ -370,9 +374,7 @@ def OnKeyPressed(self, event=None):
inv = self.axes.transData.inverted()
pos_rel = list(inv.transform(pos_abs))
y1, y2 = self.axes.get_ylim()
pos_rel[1] = (
y1 - pos_rel[1] + y2
) # Recall y-axis is inverted
pos_rel[1] = y1 - pos_rel[1] + y2 # Recall y-axis is inverted
i = np.nanargmin(
[self.calc_distance(*dp.point.center, *pos_rel) for dp in self.drs]
)
Expand Down Expand Up @@ -619,7 +621,7 @@ def browseDir(self, event):
# Reading the existing dataset,if already present
try:
self.dataFrame = pd.read_hdf(
os.path.join(self.dir, "CollectedData_" + self.scorer + ".h5"),
os.path.join(self.dir, "CollectedData_" + self.scorer + ".h5")
)
self.dataFrame.sort_index(inplace=True)
self.prev.Enable(True)
Expand Down Expand Up @@ -892,9 +894,7 @@ def plot(self, img):
)
]
self.axes.add_patch(circle[0])
self.dr = auxfun_drag.DraggablePoint(
circle[0], self.bodyparts[bpindex]
)
self.dr = auxfun_drag.DraggablePoint(circle[0], self.bodyparts[bpindex])
self.dr.connect()
self.dr.coords = MainFrame.getLabels(self, self.iter)[bpindex]
self.drs.append(self.dr)
Expand Down Expand Up @@ -952,7 +952,6 @@ def onChecked(self, event):
self.slider.Enable(False)



def show(config, config3d, sourceCam, imtypes=["*.png"]):
app = wx.App()
frame = MainFrame(None, config, imtypes, config3d, sourceCam).Show()
Expand Down
22 changes: 9 additions & 13 deletions deeplabcut/gui/multiple_individuals_labeling_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ def retrieveData_and_computeEpLines(self, img, imNum):

try:
dataFrame = pd.read_hdf(
os.path.join(sourceCam_path, "CollectedData_" + scorer + ".h5"),
os.path.join(sourceCam_path, "CollectedData_" + scorer + ".h5")
)
dataFrame.sort_index(inplace=True)
except IOError:
print("source camera images have not yet been labeled, or you have opened this folder in the wrong mode!")
print(
"source camera images have not yet been labeled, or you have opened this folder in the wrong mode!"
)
return None, None, None

# Find offset terms for drawing epipolar Lines
Expand Down Expand Up @@ -283,7 +285,7 @@ def clearBoxer(self):
class MainFrame(BaseFrame):
def __init__(self, parent, config, config3d, sourceCam):
super(MainFrame, self).__init__(
"DeepLabCut2.0 - Multiple Individuals Labeling ToolBox", parent,
"DeepLabCut2.0 - Multiple Individuals Labeling ToolBox", parent
)

self.statusbar.SetStatusText(
Expand Down Expand Up @@ -415,9 +417,7 @@ def OnKeyPressed(self, event=None):
inv = self.axes.transData.inverted()
pos_rel = list(inv.transform(pos_abs))
y1, y2 = self.axes.get_ylim()
pos_rel[1] = (
y1 - pos_rel[1] + y2
) # Recall y-axis is inverted
pos_rel[1] = y1 - pos_rel[1] + y2 # Recall y-axis is inverted
i = np.nanargmin(
[self.calc_distance(*dp.point.center, *pos_rel) for dp in self.drs]
)
Expand Down Expand Up @@ -789,7 +789,7 @@ def browseDir(self, event):
# Reading the existing dataset,if already present
try:
self.dataFrame = pd.read_hdf(
os.path.join(self.dir, "CollectedData_" + self.scorer + ".h5"),
os.path.join(self.dir, "CollectedData_" + self.scorer + ".h5")
)
# Handle data previously labeled on a different platform
sep = "/" if "/" in self.dataFrame.index[0] else "\\"
Expand Down Expand Up @@ -1205,9 +1205,7 @@ def plot(self, img):
)
self.axes.add_patch(circle)
self.dr = auxfun_drag.DraggablePoint(
circle,
self.uniquebodyparts[c],
individual_names=ind,
circle, self.uniquebodyparts[c], individual_names=ind
)
self.dr.connect()
self.dr.coords = image_points
Expand Down Expand Up @@ -1243,9 +1241,7 @@ def plot(self, img):
)
self.axes.add_patch(circle)
self.dr = auxfun_drag.DraggablePoint(
circle,
self.multibodyparts[c],
individual_names=ind,
circle, self.multibodyparts[c], individual_names=ind
)
self.dr.connect()
self.dr.coords = image_points
Expand Down
12 changes: 4 additions & 8 deletions deeplabcut/gui/multiple_individuals_refinement_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def drawplot(
self.axes.set_xlim(xlim)
self.axes.set_ylim(ylim)
self.figure.canvas.draw()
if not hasattr(self, 'toolbar'):
if not hasattr(self, "toolbar"):
self.toolbar = NavigationToolbar(self.canvas)
return (self.figure, self.axes, self.canvas, self.toolbar, self.ax)

Expand Down Expand Up @@ -137,9 +137,7 @@ def clearBoxer(self):

class MainFrame(BaseFrame):
def __init__(self, parent, config):
super(MainFrame, self).__init__(
"DeepLabCut - Refinement ToolBox", parent,
)
super(MainFrame, self).__init__("DeepLabCut - Refinement ToolBox", parent)
self.Bind(wx.EVT_CHAR_HOOK, self.OnKeyPressed)

###################################################################################################################################################
Expand Down Expand Up @@ -281,9 +279,7 @@ def OnKeyPressed(self, event=None):
inv = self.axes.transData.inverted()
pos_rel = list(inv.transform(pos_abs))
y1, y2 = self.axes.get_ylim()
pos_rel[1] = (
y1 - pos_rel[1] + y2
) # Recall y-axis is inverted
pos_rel[1] = y1 - pos_rel[1] + y2 # Recall y-axis is inverted
i = np.nanargmin(
[self.calc_distance(*dp.point.center, *pos_rel) for dp in self.drs]
)
Expand Down Expand Up @@ -810,7 +806,7 @@ def saveDataSet(self, event):
"A training dataset file is already found for this video. The refined machine labels are merged to this data!"
)
DataU1 = pd.read_hdf(
os.path.join(self.dir, "CollectedData_" + self.humanscorer + ".h5"),
os.path.join(self.dir, "CollectedData_" + self.humanscorer + ".h5")
)
# combine datasets Original Col. + corrected machinefiles:
DataCombined = pd.concat([self.Dataframe, DataU1])
Expand Down
2 changes: 1 addition & 1 deletion deeplabcut/gui/outlier_frame_extraction_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(
self, parent, config, video, shuffle, Dataframe, savelabeled, multianimal
):
super(MainFrame, self).__init__(
"DeepLabCut2.0 - Manual Outlier Frame Extraction", parent,
"DeepLabCut2.0 - Manual Outlier Frame Extraction", parent
)

###################################################################################################################################################
Expand Down
4 changes: 1 addition & 3 deletions deeplabcut/gui/refine_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def refine_labels(config, multianimal=False):

refinement.show(config)
else: # loading multianimal labeling GUI
from deeplabcut.gui import (
multiple_individuals_refinement_toolbox,
)
from deeplabcut.gui import multiple_individuals_refinement_toolbox

multiple_individuals_refinement_toolbox.show(config)

Expand Down
5 changes: 3 additions & 2 deletions deeplabcut/gui/refine_tracklets.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ def __init__(self, parent, gui_size, cfg):
hbox2, pos=(7, 0), flag=wx.EXPAND | wx.TOP | wx.LEFT | wx.RIGHT, border=10
)


self.inf_cfg_text = wx.Button(self, label="Edit inference_config.yaml")
sizer.Add(self.inf_cfg_text, pos=(10, 1), flag=wx.BOTTOM | wx.RIGHT, border=10)
self.inf_cfg_text.Bind(wx.EVT_BUTTON, self.edit_inf_config)
Expand All @@ -202,7 +201,9 @@ def __init__(self, parent, gui_size, cfg):
sizer.Add(self.reset, pos=(8, 1), flag=wx.BOTTOM | wx.RIGHT, border=10)
self.reset.Bind(wx.EVT_BUTTON, self.reset_refine_tracklets)

self.filter = wx.Button(self, label=" Step2: Filter Tracks (then you also get a CSV file!)")
self.filter = wx.Button(
self, label=" Step2: Filter Tracks (then you also get a CSV file!)"
)
sizer.Add(self.filter, pos=(8, 3), flag=wx.BOTTOM | wx.RIGHT, border=10)
self.filter.Bind(wx.EVT_BUTTON, self.filter_after_refinement)

Expand Down
16 changes: 5 additions & 11 deletions deeplabcut/gui/refinement.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def drawplot(
self.axes.set_xlim(xlim)
self.axes.set_ylim(ylim)
self.figure.canvas.draw()
if not hasattr(self, 'toolbar'):
if not hasattr(self, "toolbar"):
self.toolbar = NavigationToolbar(self.canvas)
return (self.figure, self.axes, self.canvas, self.toolbar)

Expand Down Expand Up @@ -145,9 +145,7 @@ def clearBoxer(self):

class MainFrame(BaseFrame):
def __init__(self, parent, config):
super(MainFrame, self).__init__(
"DeepLabCut2.0 - Refinement ToolBox", parent,
)
super(MainFrame, self).__init__("DeepLabCut2.0 - Refinement ToolBox", parent)
self.Bind(wx.EVT_CHAR_HOOK, self.OnKeyPressed)

###################################################################################################################################################
Expand Down Expand Up @@ -279,9 +277,7 @@ def OnKeyPressed(self, event=None):
inv = self.axes.transData.inverted()
pos_rel = list(inv.transform(pos_abs))
y1, y2 = self.axes.get_ylim()
pos_rel[1] = (
y1 - pos_rel[1] + y2
) # Recall y-axis is inverted
pos_rel[1] = y1 - pos_rel[1] + y2 # Recall y-axis is inverted
i = np.nanargmin(
[self.calc_distance(*dp.point.center, *pos_rel) for dp in self.drs]
)
Expand Down Expand Up @@ -739,7 +735,7 @@ def saveDataSet(self, event):
"A training dataset file is already found for this video. The refined machine labels are merged to this data!"
)
DataU1 = pd.read_hdf(
os.path.join(self.dir, "CollectedData_" + self.humanscorer + ".h5"),
os.path.join(self.dir, "CollectedData_" + self.humanscorer + ".h5")
)
# combine datasets Original Col. + corrected machinefiles:
DataCombined = pd.concat([self.Dataframe, DataU1])
Expand Down Expand Up @@ -886,9 +882,7 @@ def plot(self, im):

self.axes.add_patch(circle[0])
self.dr = auxfun_drag.DraggablePoint(
circle[0],
bp,
likelihood=self.likelihood
circle[0], bp, likelihood=self.likelihood
)
self.dr.connect()
self.dr.coords = MainFrame.getLabels(self, self.iter)[bpindex]
Expand Down
Loading

0 comments on commit e2c8047

Please sign in to comment.