Skip to content

Commit 7520f73

Browse files
committed
style: reformat code using ruff
1 parent 825fce0 commit 7520f73

10 files changed

+151
-72
lines changed

aipose/models/yolov7/domain.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ def __init__(
4141
:param width: The width of the image.
4242
"""
4343
self.raw_keypoints = raw_keypoints
44-
self.raw_keypoints[
45-
YoloV7PoseKeypointsIndex.WIDTH.value
46-
] = self._convert_dimension(
47-
self.raw_keypoints[YoloV7PoseKeypointsIndex.WIDTH.value],
48-
width_prediction,
49-
width_original,
44+
self.raw_keypoints[YoloV7PoseKeypointsIndex.WIDTH.value] = (
45+
self._convert_dimension(
46+
self.raw_keypoints[YoloV7PoseKeypointsIndex.WIDTH.value],
47+
width_prediction,
48+
width_original,
49+
)
5050
)
51-
self.raw_keypoints[
52-
YoloV7PoseKeypointsIndex.HEIGHT.value
53-
] = self._convert_dimension(
54-
self.raw_keypoints[YoloV7PoseKeypointsIndex.HEIGHT.value],
55-
width_prediction,
56-
width_original,
51+
self.raw_keypoints[YoloV7PoseKeypointsIndex.HEIGHT.value] = (
52+
self._convert_dimension(
53+
self.raw_keypoints[YoloV7PoseKeypointsIndex.HEIGHT.value],
54+
width_prediction,
55+
width_original,
56+
)
5757
)
5858
self.raw_keypoints[
5959
YoloV7PoseKeypointsIndex.X.value : YoloV7PoseKeypointsIndex.Y.value + 1

notebooks/Improve pose detection.ipynb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@
194194
"source": [
195195
"image_normalized_mean = mean([i.body_keypoints[-1] for i in img_yolo_v7_keypoints])\n",
196196
"original_image_mean = mean([i.body_keypoints[-1] for i in image_yolo_v7_keypoints])\n",
197-
"corrected_image_mean = mean([i.body_keypoints[-1] for i in corrected_image_yolo_v7_keypoints])"
197+
"corrected_image_mean = mean(\n",
198+
" [i.body_keypoints[-1] for i in corrected_image_yolo_v7_keypoints]\n",
199+
")"
198200
]
199201
},
200202
{
@@ -219,15 +221,15 @@
219221
"\n",
220222
"plt.subplot(1, 3, 1)\n",
221223
"plt.imshow(image_normalized)\n",
222-
"plt.title(f'Normalized Image {round(image_normalized_mean, 4)}')\n",
224+
"plt.title(f\"Normalized Image {round(image_normalized_mean, 4)}\")\n",
223225
"\n",
224226
"plt.subplot(1, 3, 2)\n",
225227
"plt.imshow(original_image)\n",
226-
"plt.title(f'Original Image {round(original_image_mean, 4)}')\n",
228+
"plt.title(f\"Original Image {round(original_image_mean, 4)}\")\n",
227229
"\n",
228230
"plt.subplot(1, 3, 3)\n",
229231
"plt.imshow(corrected_image)\n",
230-
"plt.title(f'Corrected Image {round(corrected_image_mean, 4)}')\n",
232+
"plt.title(f\"Corrected Image {round(corrected_image_mean, 4)}\")\n",
231233
"\n",
232234
"plt.tight_layout()\n",
233235
"plt.show()"

notebooks/Pose_Classificator.ipynb

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"outputs": [],
99
"source": [
1010
"import warnings\n",
11-
"warnings.filterwarnings('ignore')\n",
11+
"\n",
12+
"warnings.filterwarnings(\"ignore\")\n",
1213
"import cv2\n",
1314
"from glob import glob\n",
1415
"import numpy as np\n",
@@ -43,16 +44,24 @@
4344
"outputs": [],
4445
"source": [
4546
"def plot_matrix(cm, classes, title):\n",
46-
" ax = sns.heatmap(cm, cmap=\"Blues\", annot=True, xticklabels=classes, yticklabels=classes, cbar=False)\n",
47-
" ax.set(title=title, xlabel=\"predicted label\", ylabel=\"true label\")\n",
47+
" ax = sns.heatmap(\n",
48+
" cm,\n",
49+
" cmap=\"Blues\",\n",
50+
" annot=True,\n",
51+
" xticklabels=classes,\n",
52+
" yticklabels=classes,\n",
53+
" cbar=False,\n",
54+
" )\n",
55+
" ax.set(title=title, xlabel=\"predicted label\", ylabel=\"true label\")\n",
56+
"\n",
4857
"\n",
4958
"def plot_images(imgs, titles=[], rows=2, columns=2):\n",
5059
" fig = plt.figure(figsize=(20, 10))\n",
5160
"\n",
5261
" for i, img in enumerate(imgs):\n",
53-
" fig.add_subplot(rows, columns, i+1)\n",
62+
" fig.add_subplot(rows, columns, i + 1)\n",
5463
" plt.imshow(img)\n",
55-
" plt.axis('off')\n",
64+
" plt.axis(\"off\")\n",
5665
" if i < len(titles):\n",
5766
" plt.title(titles[i])"
5867
]
@@ -194,13 +203,18 @@
194203
"source": [
195204
"model = YoloV7Pose()\n",
196205
"\n",
197-
"imgs = []\n",
206+
"imgs = []\n",
198207
"predictions = []\n",
199-
"for i, path in enumerate(glob('./poses/*.jpg')):\n",
208+
"for i, path in enumerate(glob(\"./poses/*.jpg\")):\n",
200209
" image: ndarray = cv2.imread(path)\n",
201210
" image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n",
202211
" yolo_v7_keypoints: List[YoloV7PoseKeypoints] = model(image)\n",
203-
" img = plot(image, np.array([value.raw_keypoints for value in yolo_v7_keypoints]), plot_image=False, return_img=True)\n",
212+
" img = plot(\n",
213+
" image,\n",
214+
" np.array([value.raw_keypoints for value in yolo_v7_keypoints]),\n",
215+
" plot_image=False,\n",
216+
" return_img=True,\n",
217+
" )\n",
204218
" imgs.append(img)\n",
205219
" predictions.append(yolo_v7_keypoints[0])"
206220
]
@@ -222,7 +236,26 @@
222236
"metadata": {},
223237
"outputs": [],
224238
"source": [
225-
"y = ['Sit', 'Other', 'Sit', 'Other', 'Other', 'Other', 'Other', 'Sit', 'Other', 'Other', 'Other', 'Sit', 'Sit', 'Other', 'Other', 'Sit', 'Other', 'Other', ]"
239+
"y = [\n",
240+
" \"Sit\",\n",
241+
" \"Other\",\n",
242+
" \"Sit\",\n",
243+
" \"Other\",\n",
244+
" \"Other\",\n",
245+
" \"Other\",\n",
246+
" \"Other\",\n",
247+
" \"Sit\",\n",
248+
" \"Other\",\n",
249+
" \"Other\",\n",
250+
" \"Other\",\n",
251+
" \"Sit\",\n",
252+
" \"Sit\",\n",
253+
" \"Other\",\n",
254+
" \"Other\",\n",
255+
" \"Sit\",\n",
256+
" \"Other\",\n",
257+
" \"Other\",\n",
258+
"]"
226259
]
227260
},
228261
{
@@ -256,7 +289,9 @@
256289
"metadata": {},
257290
"outputs": [],
258291
"source": [
259-
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)"
292+
"X_train, X_test, y_train, y_test = train_test_split(\n",
293+
" X, y, test_size=0.33, random_state=42\n",
294+
")"
260295
]
261296
},
262297
{
@@ -283,7 +318,7 @@
283318
}
284319
],
285320
"source": [
286-
"parameters = {'n_neighbors':[1, 2]}\n",
321+
"parameters = {\"n_neighbors\": [1, 2]}\n",
287322
"neigh = KNeighborsClassifier()\n",
288323
"clf = GridSearchCV(neigh, parameters)\n",
289324
"clf.fit(X_train, y_train)"
@@ -296,7 +331,9 @@
296331
"metadata": {},
297332
"outputs": [],
298333
"source": [
299-
"predictions_knn = clf.predict([prediction.get_points_normalize_by_bbox() for prediction in predictions])"
334+
"predictions_knn = clf.predict(\n",
335+
" [prediction.get_points_normalize_by_bbox() for prediction in predictions]\n",
336+
")"
300337
]
301338
},
302339
{
@@ -371,11 +408,7 @@
371408
],
372409
"source": [
373410
"ConfusionMatrixDisplay.from_estimator(\n",
374-
" clf,\n",
375-
" X_test,\n",
376-
" y_test,\n",
377-
" display_labels=['Sit', 'Other'],\n",
378-
" cmap=plt.cm.Blues\n",
411+
" clf, X_test, y_test, display_labels=[\"Sit\", \"Other\"], cmap=plt.cm.Blues\n",
379412
")"
380413
]
381414
},

notebooks/Yolo v7 bounding boxes.ipynb

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"import matplotlib.pyplot as plt\n",
1313
"import matplotlib.patches as patches\n",
1414
"from aipose.models.yolov7.domain import YoloV7Pose, YoloV7PoseKeypoints\n",
15+
"\n",
1516
"%matplotlib inline"
1617
]
1718
},
@@ -169,7 +170,7 @@
169170
}
170171
],
171172
"source": [
172-
"yolo_v7_keypoints_list :List[YoloV7PoseKeypoints] = model(image)"
173+
"yolo_v7_keypoints_list: List[YoloV7PoseKeypoints] = model(image)"
173174
]
174175
},
175176
{
@@ -197,10 +198,22 @@
197198
"for prediction in yolo_v7_keypoints_list:\n",
198199
" bounding_box = prediction.prediction_bounding_box_xyxy\n",
199200
" x, y = prediction.human_center\n",
200-
" xmin, xmax, ymin, ymax = bounding_box.xmin, bounding_box.xmax, bounding_box.ymin, bounding_box.ymax\n",
201-
" rect = patches.Rectangle((xmin, ymin), xmax - xmin, ymax - ymin, linewidth=1, edgecolor='r', facecolor='none')\n",
201+
" xmin, xmax, ymin, ymax = (\n",
202+
" bounding_box.xmin,\n",
203+
" bounding_box.xmax,\n",
204+
" bounding_box.ymin,\n",
205+
" bounding_box.ymax,\n",
206+
" )\n",
207+
" rect = patches.Rectangle(\n",
208+
" (xmin, ymin),\n",
209+
" xmax - xmin,\n",
210+
" ymax - ymin,\n",
211+
" linewidth=1,\n",
212+
" edgecolor=\"r\",\n",
213+
" facecolor=\"none\",\n",
214+
" )\n",
202215
" ax.add_patch(rect)\n",
203-
" ax.plot(x, y, marker='o', markersize=2, color='r')\n",
216+
" ax.plot(x, y, marker=\"o\", markersize=2, color=\"r\")\n",
204217
"\n",
205218
"plt.xlabel(\"X-axis\")\n",
206219
"plt.ylabel(\"Y-axis\")\n",
@@ -226,15 +239,23 @@
226239
}
227240
],
228241
"source": [
229-
"def draw_bounding_box_xywh(ax, bounding_box, color='r'):\n",
242+
"def draw_bounding_box_xywh(ax, bounding_box, color=\"r\"):\n",
230243
" x = bounding_box.x\n",
231244
" y = bounding_box.y\n",
232245
" width = bounding_box.width\n",
233246
" height = bounding_box.height\n",
234247
"\n",
235-
" rect = patches.Rectangle((x - width / 2, y - height / 2), width, height, linewidth=1, edgecolor=color, facecolor='none')\n",
248+
" rect = patches.Rectangle(\n",
249+
" (x - width / 2, y - height / 2),\n",
250+
" width,\n",
251+
" height,\n",
252+
" linewidth=1,\n",
253+
" edgecolor=color,\n",
254+
" facecolor=\"none\",\n",
255+
" )\n",
236256
" ax.add_patch(rect)\n",
237257
"\n",
258+
"\n",
238259
"predictions = yolo_v7_keypoints_list\n",
239260
"\n",
240261
"fig, ax = plt.subplots()\n",
@@ -243,13 +264,13 @@
243264
"\n",
244265
"for prediction in predictions:\n",
245266
" bounding_box = prediction.prediction_bounding_box_xywh\n",
246-
" draw_bounding_box_xywh(ax, bounding_box, color='r')\n",
267+
" draw_bounding_box_xywh(ax, bounding_box, color=\"r\")\n",
247268
"\n",
248269
"plt.xlabel(\"X-axis\")\n",
249270
"plt.ylabel(\"Y-axis\")\n",
250271
"plt.title(\"Bounding Box Examples\")\n",
251272
"\n",
252-
"plt.show()\n"
273+
"plt.show()"
253274
]
254275
}
255276
],

notebooks/custom manager.ipynb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"outputs": [],
2222
"source": [
2323
"class CustomManager(FrameManagerBase):\n",
24-
" def __init__(self, blur:Tuple[int]):\n",
24+
" def __init__(self, blur: Tuple[int]):\n",
2525
" self.blur = blur\n",
2626
"\n",
2727
" def frame_received(self, frame: ndarray) -> ndarray:\n",
@@ -35,13 +35,13 @@
3535
"metadata": {},
3636
"outputs": [],
3737
"source": [
38-
"process_webcam(CustomManager((20,20)))"
38+
"process_webcam(CustomManager((20, 20)))"
3939
]
4040
}
4141
],
4242
"metadata": {
4343
"kernelspec": {
44-
"display_name": "Python 3.10.7 ('.venv': pipenv)",
44+
"display_name": ".venv",
4545
"language": "python",
4646
"name": "python3"
4747
},
@@ -57,12 +57,7 @@
5757
"pygments_lexer": "ipython3",
5858
"version": "3.10.4"
5959
},
60-
"orig_nbformat": 4,
61-
"vscode": {
62-
"interpreter": {
63-
"hash": "9e906b8bce670891410964d9b40cd49b717f5bb944c17329acc0e9f63bf95cb2"
64-
}
65-
}
60+
"orig_nbformat": 4
6661
},
6762
"nbformat": 4,
6863
"nbformat_minor": 2

0 commit comments

Comments
 (0)