Skip to content

Commit a81889d

Browse files
committed
👕Linting
1 parent 8a38978 commit a81889d

File tree

10 files changed

+127
-127
lines changed

10 files changed

+127
-127
lines changed

Makefile

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.1.4"
1+
__version__ = "1.1.5"

pose_classification_kit/datasets/__init__.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,21 @@
77
from .data_augmentation import dataAugmentation
88

99

10-
def importBodyCSVDataset(testSplit):
10+
def importBodyCSVDataset(testSplit: float, local_import: bool):
1111
"""Import body dataset as numpy arrays from GitHub if available, or local dataset otherwise.
1212
1313
Args:
1414
testSplit (float, optional): Percentage of the dataset reserved for testing. Defaults to 0.15. Must be between 0.0 and 1.0.
1515
"""
16+
assert 0.0 <= testSplit <= 1.0
17+
1618
datasetPath = DATASETS_PATH / "BodyPose_Dataset.csv"
1719
datasetURL = "https://raw.githubusercontent.com/ArthurFDLR/pose-classification-kit/master/pose_classification_kit/datasets/BodyPose_Dataset.csv"
1820

19-
assert 0.0 <= testSplit <= 1.0
20-
21-
# Try to fetch the most recent dataset, load local file otherwise.
22-
try:
23-
dataset_df = pd.read_csv(datasetURL)
24-
print("Dataset loaded from", datasetURL)
25-
except:
26-
assert datasetPath.is_file(), "No local dataset found."
21+
if local_import:
2722
dataset_df = pd.read_csv(datasetPath)
28-
print("Dataset loaded from", str(datasetPath))
23+
else:
24+
dataset_df = pd.read_csv(datasetURL)
2925

3026
bodyLabels_df = dataset_df.groupby("label")
3127
labels = list(dataset_df.label.unique())
@@ -63,7 +59,10 @@ def importBodyCSVDataset(testSplit):
6359

6460

6561
def bodyDataset(
66-
testSplit: float = 0.15, shuffle: bool = True, bodyModel: BodyModel = BODY25
62+
testSplit: float = 0.15,
63+
shuffle: bool = True,
64+
bodyModel: BodyModel = BODY25,
65+
local_import: bool = False,
6766
):
6867
"""Return the dataset of body keypoints (see pose_classification_kit/datasets/BodyPose_Dataset.csv)
6968
as numpy arrays.
@@ -72,6 +71,7 @@ def bodyDataset(
7271
testSplit (float, optional): Percentage of the dataset reserved for testing. Defaults to 0.15. Must be between 0.0 and 1.0.
7372
shuffle (bool, optional): Shuffle the whole dataset. Defaults to True.
7473
bodyModel (BodyModel, optional): Select the keypoint format of the dataset. BODY25 or BODY18. Defaults to BODY25.
74+
local_import (bool, optional): Choose to use local dataset or fetch online dataset (global repository). Default False.
7575
7676
Returns:
7777
dict: {
@@ -85,7 +85,9 @@ def bodyDataset(
8585
}
8686
"""
8787

88-
x_train, x_test, y_train, y_test, labels = importBodyCSVDataset(testSplit)
88+
x_train, x_test, y_train, y_test, labels = importBodyCSVDataset(
89+
testSplit, local_import
90+
)
8991

9092
# Shuffle in unison
9193
if shuffle:
@@ -121,14 +123,20 @@ def bodyDataset(
121123
}
122124

123125

124-
def handDataset(testSplit: float = 0.15, shuffle: bool = True, handID: int = 0):
126+
def handDataset(
127+
testSplit: float = 0.15,
128+
shuffle: bool = True,
129+
handID: int = 0,
130+
local_import: bool = False,
131+
):
125132
"""Return the dataset of hand keypoints (see pose_classification_kit/datasets/HandPose_Dataset.csv)
126133
as numpy arrays.
127134
128135
Args:
129136
testSplit (float, optional): Percent of the dataset reserved for testing. Defaults to 0.15. Must be between 0.0 and 1.0.
130137
shuffle (bool, optional): Shuffle the whole dataset. Defaults to True.
131138
handID (int, optional): Select hand side - 0:left, 1:right. Default to 0.
139+
local_import (bool, optional): Choose to use local dataset or fetch online dataset (global repository). Default False.
132140
133141
Returns:
134142
dict: {
@@ -141,19 +149,15 @@ def handDataset(testSplit: float = 0.15, shuffle: bool = True, handID: int = 0):
141149
'labels': list of labels
142150
}
143151
"""
152+
assert 0.0 <= testSplit <= 1.0
153+
144154
datasetPath = DATASETS_PATH / "HandPose_Dataset.csv"
145155
datasetURL = "https://raw.githubusercontent.com/ArthurFDLR/pose-classification-kit/master/pose_classification_kit/datasets/HandPose_Dataset.csv"
146156

147-
assert 0.0 <= testSplit <= 1.0
148-
149-
# Try to fetch the most recent dataset, load local file otherwise.
150-
try:
151-
dataset_df = pd.read_csv(datasetURL)
152-
print("Dataset loaded from", datasetURL)
153-
except:
154-
assert datasetPath.is_file(), "No local dataset found."
157+
if local_import:
155158
dataset_df = pd.read_csv(datasetPath)
156-
print("Dataset loaded from", str(datasetPath))
159+
else:
160+
dataset_df = pd.read_csv(datasetURL)
157161

158162
hand_label = "right" if handID else "left"
159163
handLabels_df = {

pose_classification_kit/datasets/body_models.py

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,27 @@ def __init__(self, mapping, pairs) -> None:
9393
"neck_y",
9494
],
9595
pairs=[
96-
[(30,31), (26,27)],
97-
[(26,27), (22,23)],
98-
[(32,33), (28,29)],
99-
[(28,29), (24,25)],
100-
[(22,23), (24,25)],
101-
[(10,11), (14,15)],
102-
[(12,13), (16,17)],
103-
[(14,15), (18,19)],
104-
[(16,17), (20,21)],
105-
[(2,3), (4,5)],
106-
[(0,1), (2,3)],
107-
[(0,1), (4,5)],
108-
[(2,3), (6,7)],
109-
[(4,5), (8,9)],
110-
[(6,7), (10,11)],
111-
[(8,9), (12,13)],
112-
[(34,35), (0,1)],
113-
[(34,35), (10,11)],
114-
[(34,35), (12,13)],
115-
[(34,35), (22,23)],
116-
[(34,35), (24,25)],
96+
[(30, 31), (26, 27)],
97+
[(26, 27), (22, 23)],
98+
[(32, 33), (28, 29)],
99+
[(28, 29), (24, 25)],
100+
[(22, 23), (24, 25)],
101+
[(10, 11), (14, 15)],
102+
[(12, 13), (16, 17)],
103+
[(14, 15), (18, 19)],
104+
[(16, 17), (20, 21)],
105+
[(2, 3), (4, 5)],
106+
[(0, 1), (2, 3)],
107+
[(0, 1), (4, 5)],
108+
[(2, 3), (6, 7)],
109+
[(4, 5), (8, 9)],
110+
[(6, 7), (10, 11)],
111+
[(8, 9), (12, 13)],
112+
[(34, 35), (0, 1)],
113+
[(34, 35), (10, 11)],
114+
[(34, 35), (12, 13)],
115+
[(34, 35), (22, 23)],
116+
[(34, 35), (24, 25)],
117117
],
118118
)
119119

@@ -174,7 +174,7 @@ def __init__(self, mapping, pairs) -> None:
174174
[11, 24],
175175
],
176176
)
177-
''' #BODY25 annotated
177+
""" #BODY25 annotated
178178
pairs_annotated={
179179
"Torso":[1, 8],
180180
"Shoulder (right)":[1, 2],
@@ -201,7 +201,7 @@ def __init__(self, mapping, pairs) -> None:
201201
"Toe (right)":[22, 23],
202202
"Heel (right)":[11, 24],
203203
}
204-
'''
204+
"""
205205

206206
BODY25_FLAT = BodyModel(
207207
mapping=[
@@ -257,32 +257,32 @@ def __init__(self, mapping, pairs) -> None:
257257
"right_heel_y",
258258
],
259259
pairs=[
260-
[(2,3), (16,17)],
261-
[(2,3), (4,5)],
262-
[(2,3), (10,11)],
263-
[(4,5), (6,7)],
264-
[(6,7), (8,9)],
265-
[(10,11), (12,13)],
266-
[(12,13), (14,15)],
267-
[(16,17), (18,19)],
268-
[(18,19), (20,21)],
269-
[(20,21), (22,23)],
270-
[(16,17), (24,25)],
271-
[(24,25), (26,27)],
272-
[(26,27), (28,29)],
273-
[(2,3), (0,1)],
274-
[(0,1), (30,31)],
275-
[(30,31), (34,35)],
276-
[(0,1), (32,33)],
277-
[(32,33), (36,37)],
278-
[(4,5), (34,35)],
279-
[(10,11), (36,37)],
280-
[(28,29), (38,39)],
281-
[(38,39), (40,41)],
282-
[(28,29), (42,43)],
283-
[(22,23), (44,45)],
284-
[(44,45), (46,47)],
285-
[(22,23), (48,49)],
260+
[(2, 3), (16, 17)],
261+
[(2, 3), (4, 5)],
262+
[(2, 3), (10, 11)],
263+
[(4, 5), (6, 7)],
264+
[(6, 7), (8, 9)],
265+
[(10, 11), (12, 13)],
266+
[(12, 13), (14, 15)],
267+
[(16, 17), (18, 19)],
268+
[(18, 19), (20, 21)],
269+
[(20, 21), (22, 23)],
270+
[(16, 17), (24, 25)],
271+
[(24, 25), (26, 27)],
272+
[(26, 27), (28, 29)],
273+
[(2, 3), (0, 1)],
274+
[(0, 1), (30, 31)],
275+
[(30, 31), (34, 35)],
276+
[(0, 1), (32, 33)],
277+
[(32, 33), (36, 37)],
278+
[(4, 5), (34, 35)],
279+
[(10, 11), (36, 37)],
280+
[(28, 29), (38, 39)],
281+
[(38, 39), (40, 41)],
282+
[(28, 29), (42, 43)],
283+
[(22, 23), (44, 45)],
284+
[(44, 45), (46, 47)],
285+
[(22, 23), (48, 49)],
286286
],
287287
)
288288

@@ -291,6 +291,7 @@ def __init__(self, mapping, pairs) -> None:
291291
BODY25flat_to_BODY18flat_indices = [0, 1, 32, 33, 30, 31, 36, 37, 34, 35, 10, 11, 4, 5, 12, 13, 6, 7, 14, 15, 8, 9, 24, 25, 18, 19, 26, 27, 20, 21, 28, 29, 22, 23, 2, 3]
292292
# fmt: on
293293

294+
294295
def BODY25_to_BODY18(body25_keypoints: np.ndarray):
295296
assert body25_keypoints.shape == 25
296297
return body25_keypoints[BODY25_to_BODY18_indices]

pose_classification_kit/datasets/data_augmentation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ def dataAugmentation(
116116
# Remove the points
117117
if type(remove_rand_keypoints_nbr) != type(None):
118118
if i in list_random_keypoints:
119-
keypoint_x = 0.
120-
keypoint_y = 0.
119+
keypoint_x = 0.0
120+
keypoint_y = 0.0
121121
if type(remove_specific_keypoints) != type(None):
122122
if i in remove_specific_keypoints:
123-
keypoint_x = 0.
124-
keypoint_y = 0.
123+
keypoint_x = 0.0
124+
keypoint_y = 0.0
125125
# Add additionnal augmentation features
126126
entry.append([keypoint_x, keypoint_y])
127127

@@ -137,4 +137,4 @@ def dataAugmentation(
137137
new_x = np.array(new_x)
138138
new_y = np.array(new_y)
139139

140-
return (new_x,new_y)
140+
return (new_x, new_y)

pose_classification_kit/src/keypoints_analysis/body_analysis.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
from ..imports.openpose import op
77
from .dynamic_bar_graph_widget import BarGraphWidget
88
from .classifier_selection_widget import ClassifierSelectionWidget
9-
from ...datasets.body_models import BODY18, BODY18_FLAT, BODY25, BODY25_FLAT, BODY25_to_BODY18_indices
9+
from ...datasets.body_models import (
10+
BODY18,
11+
BODY18_FLAT,
12+
BODY25,
13+
BODY25_FLAT,
14+
BODY25_to_BODY18_indices,
15+
)
1016

1117
import numpy as np
1218
from matplotlib.backends.backend_qt5agg import FigureCanvas
@@ -162,16 +168,18 @@ def updatePredictedClass(self, keypoints: np.ndarray):
162168
title = ""
163169
if type(keypoints) != type(None):
164170
if self.modelClassifier is not None:
165-
171+
166172
if self.currentBodyModel == BODY25:
167173
inputData = keypoints[:2].T
168174
elif self.currentBodyModel == BODY25_FLAT:
169175
inputData = np.concatenate(keypoints[:2].T, axis=0)
170176
elif self.currentBodyModel == BODY18:
171-
inputData = keypoints.T[BODY25_to_BODY18_indices][:,:2]
177+
inputData = keypoints.T[BODY25_to_BODY18_indices][:, :2]
172178
elif self.currentBodyModel == BODY18_FLAT:
173-
inputData = np.concatenate(keypoints.T[BODY25_to_BODY18_indices][:,:2], axis=0)
174-
179+
inputData = np.concatenate(
180+
keypoints.T[BODY25_to_BODY18_indices][:, :2], axis=0
181+
)
182+
175183
prediction = self.modelClassifier.predict(np.array([inputData]))[0]
176184
self.currentPrediction = self.classOutputs[np.argmax(prediction)]
177185
title = self.currentPrediction
@@ -187,10 +195,14 @@ def newModelLoaded(self, urlModel: str, modelInfo: dict, bodyID: int):
187195
if bodyID == 2: # Check if classifier for body poses (not hands)
188196
model = tf.keras.models.load_model(urlModel)
189197
nbrClass = model.layers[-1].output_shape[1]
190-
if modelInfo and modelInfo.get('labels') and len(modelInfo.get('labels')) == nbrClass:
191-
classOutputs = modelInfo.get('labels')
198+
if (
199+
modelInfo
200+
and modelInfo.get("labels")
201+
and len(modelInfo.get("labels")) == nbrClass
202+
):
203+
classOutputs = modelInfo.get("labels")
192204
else:
193-
classOutputs = [str(i) for i in range(1,nbrClass+1)]
205+
classOutputs = [str(i) for i in range(1, nbrClass + 1)]
194206
self.setClassifierModel(model, classOutputs)
195207

196208
def getCurrentPrediction(self) -> str:

0 commit comments

Comments
 (0)