Skip to content

Commit

Permalink
👕Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurFDLR committed Jul 25, 2021
1 parent 8a38978 commit a81889d
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 127 deletions.
9 changes: 0 additions & 9 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion pose_classification_kit/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.1.4"
__version__ = "1.1.5"
48 changes: 26 additions & 22 deletions pose_classification_kit/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,21 @@
from .data_augmentation import dataAugmentation


def importBodyCSVDataset(testSplit):
def importBodyCSVDataset(testSplit: float, local_import: bool):
"""Import body dataset as numpy arrays from GitHub if available, or local dataset otherwise.
Args:
testSplit (float, optional): Percentage of the dataset reserved for testing. Defaults to 0.15. Must be between 0.0 and 1.0.
"""
assert 0.0 <= testSplit <= 1.0

datasetPath = DATASETS_PATH / "BodyPose_Dataset.csv"
datasetURL = "https://raw.githubusercontent.com/ArthurFDLR/pose-classification-kit/master/pose_classification_kit/datasets/BodyPose_Dataset.csv"

assert 0.0 <= testSplit <= 1.0

# Try to fetch the most recent dataset, load local file otherwise.
try:
dataset_df = pd.read_csv(datasetURL)
print("Dataset loaded from", datasetURL)
except:
assert datasetPath.is_file(), "No local dataset found."
if local_import:
dataset_df = pd.read_csv(datasetPath)
print("Dataset loaded from", str(datasetPath))
else:
dataset_df = pd.read_csv(datasetURL)

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


def bodyDataset(
testSplit: float = 0.15, shuffle: bool = True, bodyModel: BodyModel = BODY25
testSplit: float = 0.15,
shuffle: bool = True,
bodyModel: BodyModel = BODY25,
local_import: bool = False,
):
"""Return the dataset of body keypoints (see pose_classification_kit/datasets/BodyPose_Dataset.csv)
as numpy arrays.
Expand All @@ -72,6 +71,7 @@ def bodyDataset(
testSplit (float, optional): Percentage of the dataset reserved for testing. Defaults to 0.15. Must be between 0.0 and 1.0.
shuffle (bool, optional): Shuffle the whole dataset. Defaults to True.
bodyModel (BodyModel, optional): Select the keypoint format of the dataset. BODY25 or BODY18. Defaults to BODY25.
local_import (bool, optional): Choose to use local dataset or fetch online dataset (global repository). Default False.
Returns:
dict: {
Expand All @@ -85,7 +85,9 @@ def bodyDataset(
}
"""

x_train, x_test, y_train, y_test, labels = importBodyCSVDataset(testSplit)
x_train, x_test, y_train, y_test, labels = importBodyCSVDataset(
testSplit, local_import
)

# Shuffle in unison
if shuffle:
Expand Down Expand Up @@ -121,14 +123,20 @@ def bodyDataset(
}


def handDataset(testSplit: float = 0.15, shuffle: bool = True, handID: int = 0):
def handDataset(
testSplit: float = 0.15,
shuffle: bool = True,
handID: int = 0,
local_import: bool = False,
):
"""Return the dataset of hand keypoints (see pose_classification_kit/datasets/HandPose_Dataset.csv)
as numpy arrays.
Args:
testSplit (float, optional): Percent of the dataset reserved for testing. Defaults to 0.15. Must be between 0.0 and 1.0.
shuffle (bool, optional): Shuffle the whole dataset. Defaults to True.
handID (int, optional): Select hand side - 0:left, 1:right. Default to 0.
local_import (bool, optional): Choose to use local dataset or fetch online dataset (global repository). Default False.
Returns:
dict: {
Expand All @@ -141,19 +149,15 @@ def handDataset(testSplit: float = 0.15, shuffle: bool = True, handID: int = 0):
'labels': list of labels
}
"""
assert 0.0 <= testSplit <= 1.0

datasetPath = DATASETS_PATH / "HandPose_Dataset.csv"
datasetURL = "https://raw.githubusercontent.com/ArthurFDLR/pose-classification-kit/master/pose_classification_kit/datasets/HandPose_Dataset.csv"

assert 0.0 <= testSplit <= 1.0

# Try to fetch the most recent dataset, load local file otherwise.
try:
dataset_df = pd.read_csv(datasetURL)
print("Dataset loaded from", datasetURL)
except:
assert datasetPath.is_file(), "No local dataset found."
if local_import:
dataset_df = pd.read_csv(datasetPath)
print("Dataset loaded from", str(datasetPath))
else:
dataset_df = pd.read_csv(datasetURL)

hand_label = "right" if handID else "left"
handLabels_df = {
Expand Down
99 changes: 50 additions & 49 deletions pose_classification_kit/datasets/body_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,27 @@ def __init__(self, mapping, pairs) -> None:
"neck_y",
],
pairs=[
[(30,31), (26,27)],
[(26,27), (22,23)],
[(32,33), (28,29)],
[(28,29), (24,25)],
[(22,23), (24,25)],
[(10,11), (14,15)],
[(12,13), (16,17)],
[(14,15), (18,19)],
[(16,17), (20,21)],
[(2,3), (4,5)],
[(0,1), (2,3)],
[(0,1), (4,5)],
[(2,3), (6,7)],
[(4,5), (8,9)],
[(6,7), (10,11)],
[(8,9), (12,13)],
[(34,35), (0,1)],
[(34,35), (10,11)],
[(34,35), (12,13)],
[(34,35), (22,23)],
[(34,35), (24,25)],
[(30, 31), (26, 27)],
[(26, 27), (22, 23)],
[(32, 33), (28, 29)],
[(28, 29), (24, 25)],
[(22, 23), (24, 25)],
[(10, 11), (14, 15)],
[(12, 13), (16, 17)],
[(14, 15), (18, 19)],
[(16, 17), (20, 21)],
[(2, 3), (4, 5)],
[(0, 1), (2, 3)],
[(0, 1), (4, 5)],
[(2, 3), (6, 7)],
[(4, 5), (8, 9)],
[(6, 7), (10, 11)],
[(8, 9), (12, 13)],
[(34, 35), (0, 1)],
[(34, 35), (10, 11)],
[(34, 35), (12, 13)],
[(34, 35), (22, 23)],
[(34, 35), (24, 25)],
],
)

Expand Down Expand Up @@ -174,7 +174,7 @@ def __init__(self, mapping, pairs) -> None:
[11, 24],
],
)
''' #BODY25 annotated
""" #BODY25 annotated
pairs_annotated={
"Torso":[1, 8],
"Shoulder (right)":[1, 2],
Expand All @@ -201,7 +201,7 @@ def __init__(self, mapping, pairs) -> None:
"Toe (right)":[22, 23],
"Heel (right)":[11, 24],
}
'''
"""

BODY25_FLAT = BodyModel(
mapping=[
Expand Down Expand Up @@ -257,32 +257,32 @@ def __init__(self, mapping, pairs) -> None:
"right_heel_y",
],
pairs=[
[(2,3), (16,17)],
[(2,3), (4,5)],
[(2,3), (10,11)],
[(4,5), (6,7)],
[(6,7), (8,9)],
[(10,11), (12,13)],
[(12,13), (14,15)],
[(16,17), (18,19)],
[(18,19), (20,21)],
[(20,21), (22,23)],
[(16,17), (24,25)],
[(24,25), (26,27)],
[(26,27), (28,29)],
[(2,3), (0,1)],
[(0,1), (30,31)],
[(30,31), (34,35)],
[(0,1), (32,33)],
[(32,33), (36,37)],
[(4,5), (34,35)],
[(10,11), (36,37)],
[(28,29), (38,39)],
[(38,39), (40,41)],
[(28,29), (42,43)],
[(22,23), (44,45)],
[(44,45), (46,47)],
[(22,23), (48,49)],
[(2, 3), (16, 17)],
[(2, 3), (4, 5)],
[(2, 3), (10, 11)],
[(4, 5), (6, 7)],
[(6, 7), (8, 9)],
[(10, 11), (12, 13)],
[(12, 13), (14, 15)],
[(16, 17), (18, 19)],
[(18, 19), (20, 21)],
[(20, 21), (22, 23)],
[(16, 17), (24, 25)],
[(24, 25), (26, 27)],
[(26, 27), (28, 29)],
[(2, 3), (0, 1)],
[(0, 1), (30, 31)],
[(30, 31), (34, 35)],
[(0, 1), (32, 33)],
[(32, 33), (36, 37)],
[(4, 5), (34, 35)],
[(10, 11), (36, 37)],
[(28, 29), (38, 39)],
[(38, 39), (40, 41)],
[(28, 29), (42, 43)],
[(22, 23), (44, 45)],
[(44, 45), (46, 47)],
[(22, 23), (48, 49)],
],
)

Expand All @@ -291,6 +291,7 @@ def __init__(self, mapping, pairs) -> None:
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]
# fmt: on


def BODY25_to_BODY18(body25_keypoints: np.ndarray):
assert body25_keypoints.shape == 25
return body25_keypoints[BODY25_to_BODY18_indices]
10 changes: 5 additions & 5 deletions pose_classification_kit/datasets/data_augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ def dataAugmentation(
# Remove the points
if type(remove_rand_keypoints_nbr) != type(None):
if i in list_random_keypoints:
keypoint_x = 0.
keypoint_y = 0.
keypoint_x = 0.0
keypoint_y = 0.0
if type(remove_specific_keypoints) != type(None):
if i in remove_specific_keypoints:
keypoint_x = 0.
keypoint_y = 0.
keypoint_x = 0.0
keypoint_y = 0.0
# Add additionnal augmentation features
entry.append([keypoint_x, keypoint_y])

Expand All @@ -137,4 +137,4 @@ def dataAugmentation(
new_x = np.array(new_x)
new_y = np.array(new_y)

return (new_x,new_y)
return (new_x, new_y)
28 changes: 20 additions & 8 deletions pose_classification_kit/src/keypoints_analysis/body_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
from ..imports.openpose import op
from .dynamic_bar_graph_widget import BarGraphWidget
from .classifier_selection_widget import ClassifierSelectionWidget
from ...datasets.body_models import BODY18, BODY18_FLAT, BODY25, BODY25_FLAT, BODY25_to_BODY18_indices
from ...datasets.body_models import (
BODY18,
BODY18_FLAT,
BODY25,
BODY25_FLAT,
BODY25_to_BODY18_indices,
)

import numpy as np
from matplotlib.backends.backend_qt5agg import FigureCanvas
Expand Down Expand Up @@ -162,16 +168,18 @@ def updatePredictedClass(self, keypoints: np.ndarray):
title = ""
if type(keypoints) != type(None):
if self.modelClassifier is not None:

if self.currentBodyModel == BODY25:
inputData = keypoints[:2].T
elif self.currentBodyModel == BODY25_FLAT:
inputData = np.concatenate(keypoints[:2].T, axis=0)
elif self.currentBodyModel == BODY18:
inputData = keypoints.T[BODY25_to_BODY18_indices][:,:2]
inputData = keypoints.T[BODY25_to_BODY18_indices][:, :2]
elif self.currentBodyModel == BODY18_FLAT:
inputData = np.concatenate(keypoints.T[BODY25_to_BODY18_indices][:,:2], axis=0)

inputData = np.concatenate(
keypoints.T[BODY25_to_BODY18_indices][:, :2], axis=0
)

prediction = self.modelClassifier.predict(np.array([inputData]))[0]
self.currentPrediction = self.classOutputs[np.argmax(prediction)]
title = self.currentPrediction
Expand All @@ -187,10 +195,14 @@ def newModelLoaded(self, urlModel: str, modelInfo: dict, bodyID: int):
if bodyID == 2: # Check if classifier for body poses (not hands)
model = tf.keras.models.load_model(urlModel)
nbrClass = model.layers[-1].output_shape[1]
if modelInfo and modelInfo.get('labels') and len(modelInfo.get('labels')) == nbrClass:
classOutputs = modelInfo.get('labels')
if (
modelInfo
and modelInfo.get("labels")
and len(modelInfo.get("labels")) == nbrClass
):
classOutputs = modelInfo.get("labels")
else:
classOutputs = [str(i) for i in range(1,nbrClass+1)]
classOutputs = [str(i) for i in range(1, nbrClass + 1)]
self.setClassifierModel(model, classOutputs)

def getCurrentPrediction(self) -> str:
Expand Down
Loading

0 comments on commit a81889d

Please sign in to comment.