From d0435c7d0c76934a9e35336053e1bba042c4751f Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 17 Oct 2022 13:10:26 +0200 Subject: [PATCH] fix: black formatting --- notebooks/demo/demo.ipynb | 32 +++++++------- notebooks/demo/load_human36m.ipynb | 22 +++++----- notebooks/demo/load_rat7m_dataset_demo.ipynb | 44 +++++++++++--------- notebooks/demo/static_loader_demo.ipynb | 4 +- notebooks/preprocess_rat7m.ipynb | 22 +++++----- propose/utils/reproducibility.py | 15 +++++-- setup.py | 8 +++- 7 files changed, 85 insertions(+), 62 deletions(-) diff --git a/notebooks/demo/demo.ipynb b/notebooks/demo/demo.ipynb index cf3f40b..5593e3c 100644 --- a/notebooks/demo/demo.ipynb +++ b/notebooks/demo/demo.ipynb @@ -30,8 +30,8 @@ "execution_count": 3, "outputs": [], "source": [ - "mocap_path = f'../../data/rat7m/mocap/mocap-s4-d1.mat'\n", - "vid_path = f'../../data/rat7m/movies/s4-d1/s4-d1-camera4-0.mp4'\n", + "mocap_path = f\"../../data/rat7m/mocap/mocap-s4-d1.mat\"\n", + "vid_path = f\"../../data/rat7m/movies/s4-d1/s4-d1-camera4-0.mp4\"\n", "\n", "vid = imageio.get_reader(vid_path)" ], @@ -77,7 +77,7 @@ "\n", "pose = pose[mask]\n", "\n", - "np.array(pose._edge('HeadF', 'HeadB'))" + "np.array(pose._edge(\"HeadF\", \"HeadB\"))" ], "metadata": { "collapsed": false, @@ -103,9 +103,9 @@ ], "source": [ "fig = plt.figure(figsize=(10, 10))\n", - "ax1 = fig.add_subplot(1, 1, 1, projection='3d')\n", + "ax1 = fig.add_subplot(1, 1, 1, projection=\"3d\")\n", "ax1.get_proj = lambda: np.dot(Axes3D.get_proj(ax1), np.diag([1, 1, 0.75, 1]))\n", - "ax1.view_init(30, 30)\n", + "ax1.view_init(30, 30)\n", "ax1.set_xlim(-400, -100)\n", "ax1.set_ylim(-300, 0)\n", "ax1.set_zlim(0, 100)\n", @@ -136,7 +136,7 @@ } ], "source": [ - "camera = cameras['Camera4']\n", + "camera = cameras[\"Camera4\"]\n", "pose2D = Rat7mPose(camera.proj2D(pose))\n", "\n", "frame_idx = camera.frames.squeeze()[mask][0]\n", @@ -169,7 +169,7 @@ ], "source": [ "cameras = load_cameras(mocap_path)\n", - "camera = cameras['Camera4']\n", + "camera = cameras[\"Camera4\"]\n", "camera.frames = camera.frames.squeeze()[mask]\n", "pose_idx = 0\n", "\n", @@ -183,16 +183,16 @@ "\n", "fig = plt.figure(figsize=(20, 10))\n", "\n", - "ax1 = fig.add_subplot(1, 2, 1, projection='3d')\n", + "ax1 = fig.add_subplot(1, 2, 1, projection=\"3d\")\n", "ax1.get_proj = lambda: np.dot(Axes3D.get_proj(ax1), np.diag([1, 1, 0.75, 1]))\n", - "ax1.view_init(30, 30)\n", + "ax1.view_init(30, 30)\n", "ax1.set_xlim(-400, -100)\n", "ax1.set_ylim(-300, 0)\n", "ax1.set_zlim(0, 100)\n", "\n", "ax2 = fig.add_subplot(1, 2, 2)\n", - "ax2.set_title('Camera 4')\n", - "plt.axis('off')\n", + "ax2.set_title(\"Camera 4\")\n", + "plt.axis(\"off\")\n", "\n", "img = ax2.imshow(im)\n", "animate1 = pose.animate(ax1)\n", @@ -200,6 +200,7 @@ "\n", "plt.close(fig)\n", "\n", + "\n", "def animate(i):\n", " frame_idx = camera.frames.squeeze()[pose_idx + i]\n", " im = vid.get_data(frame_idx)\n", @@ -209,14 +210,17 @@ " animate1(i)\n", " animate2(i)\n", "\n", + "\n", "ani = animation.FuncAnimation(fig, animate, frames=100)\n", "\n", - "Writer = animation.writers['ffmpeg']\n", - "writer = Writer(fps=30, metadata=dict(artist='Me'), bitrate=-1)\n", + "Writer = animation.writers[\"ffmpeg\"]\n", + "writer = Writer(fps=30, metadata=dict(artist=\"Me\"), bitrate=-1)\n", "\n", "pbar = tqdm(total=100, position=0)\n", "\n", - "ani.save('walk_cam_4_sub.mp4', writer=writer, progress_callback=lambda i, n: pbar.update(1))" + "ani.save(\n", + " \"walk_cam_4_sub.mp4\", writer=writer, progress_callback=lambda i, n: pbar.update(1)\n", + ")" ], "metadata": { "collapsed": false, diff --git a/notebooks/demo/load_human36m.ipynb b/notebooks/demo/load_human36m.ipynb index 9e5bb0a..8738abd 100644 --- a/notebooks/demo/load_human36m.ipynb +++ b/notebooks/demo/load_human36m.ipynb @@ -42,28 +42,28 @@ "path = \"/Users/paulpierzchlewicz/PycharmProjects/propose/data/human36m/Directions.60457274.cdf\"\n", "poses = load_poses(path)\n", "\n", - "poses /= poses.std() # Normalize poses\n", + "poses /= poses.std() # Normalize poses\n", "\n", "poses = Human36mPose(poses)\n", "\n", "pose = poses[200]\n", "\n", - "plt.style.use('default')\n", + "plt.style.use(\"default\")\n", "fig = plt.figure()\n", - "ax = fig.add_subplot(111, projection='3d')\n", - "ax.view_init(elev=15., azim=120)\n", - "poses[395].plot(ax=ax, alpha=.1)\n", - "poses[396].plot(ax=ax, alpha=.2)\n", - "poses[397].plot(ax=ax, alpha=.3)\n", - "poses[398].plot(ax=ax, alpha=.4)\n", - "poses[399].plot(ax=ax, alpha=.5)\n", + "ax = fig.add_subplot(111, projection=\"3d\")\n", + "ax.view_init(elev=15.0, azim=120)\n", + "poses[395].plot(ax=ax, alpha=0.1)\n", + "poses[396].plot(ax=ax, alpha=0.2)\n", + "poses[397].plot(ax=ax, alpha=0.3)\n", + "poses[398].plot(ax=ax, alpha=0.4)\n", + "poses[399].plot(ax=ax, alpha=0.5)\n", "poses[400].plot(ax=ax, alpha=1)\n", "\n", "ax.set_xlim(2, -2)\n", "ax.set_ylim(2, -2)\n", "ax.set_zlim(-2, 2)\n", "\n", - "ax.xaxis.pane.fill = False # Left pane\n", + "ax.xaxis.pane.fill = False # Left pane\n", "ax.yaxis.pane.fill = False\n", "ax.zaxis.pane.fill = False\n", "ax.grid(False)\n", @@ -88,7 +88,7 @@ "ax.set_yticks([])\n", "ax.set_zticks([])\n", "\n", - "plt.savefig('./human36m_pose.png', dpi=300)\n", + "plt.savefig(\"./human36m_pose.png\", dpi=300)\n", "\n", "plt.show()" ], diff --git a/notebooks/demo/load_rat7m_dataset_demo.ipynb b/notebooks/demo/load_rat7m_dataset_demo.ipynb index 6e58252..00e8a05 100644 --- a/notebooks/demo/load_rat7m_dataset_demo.ipynb +++ b/notebooks/demo/load_rat7m_dataset_demo.ipynb @@ -46,8 +46,8 @@ "execution_count": 7, "outputs": [], "source": [ - "dirname = '/Users/paulpierzchlewicz/PycharmProjects/propose/data/rat7m' # Choose this such that it points to your dataset\n", - "data_key = 's4-d1'" + "dirname = \"/Users/paulpierzchlewicz/PycharmProjects/propose/data/rat7m\" # Choose this such that it points to your dataset\n", + "data_key = \"s4-d1\"" ], "metadata": { "collapsed": false, @@ -61,17 +61,21 @@ "execution_count": 18, "outputs": [], "source": [ - "dataset = Rat7mDataset(dirname=dirname, data_key=data_key, transforms=[\n", - " tr.SwitchArmsElbows(),\n", - " tr.CropImageToPose(),\n", - " tr.RotatePoseToCamera(),\n", - " tr.CenterPose(),\n", - " tr.ScalePose(scale=0.03),\n", - " ScaleInputs(scale=0.1, multichannel=True, anti_aliasing=True),\n", - " tr.NormaliseImageScale(),\n", - " tr.ToGraph(),\n", - " ToTensor()\n", - "])" + "dataset = Rat7mDataset(\n", + " dirname=dirname,\n", + " data_key=data_key,\n", + " transforms=[\n", + " tr.SwitchArmsElbows(),\n", + " tr.CropImageToPose(),\n", + " tr.RotatePoseToCamera(),\n", + " tr.CenterPose(),\n", + " tr.ScalePose(scale=0.03),\n", + " ScaleInputs(scale=0.1, multichannel=True, anti_aliasing=True),\n", + " tr.NormaliseImageScale(),\n", + " tr.ToGraph(),\n", + " ToTensor(),\n", + " ],\n", + ")" ], "metadata": { "collapsed": false, @@ -103,25 +107,25 @@ "pose = Rat7mPose(pose_matrix.numpy())\n", "image = res.image\n", "\n", - "plt.style.use('default')\n", + "plt.style.use(\"default\")\n", "fig = plt.figure(figsize=(20, 10))\n", "ax1 = fig.add_subplot(1, 2, 1)\n", "\n", "ax1.imshow(image)\n", "\n", - "ax2 = fig.add_subplot(1, 2, 2, projection='3d')\n", + "ax2 = fig.add_subplot(1, 2, 2, projection=\"3d\")\n", "ax2.get_proj = lambda: np.dot(Axes3D.get_proj(ax2), np.diag([1, 1, 0.75, 1]))\n", - "ax2.view_init(45, 90)\n", + "ax2.view_init(45, 90)\n", "ax2.set_xlim(3, -3)\n", "ax2.set_ylim(3, -3)\n", "ax2.set_zlim(-1, 1)\n", - "ax2.set_xlabel('x')\n", - "ax2.set_ylabel('y')\n", - "ax2.set_zlabel('z')\n", + "ax2.set_xlabel(\"x\")\n", + "ax2.set_ylabel(\"y\")\n", + "ax2.set_zlabel(\"z\")\n", "ax2.set_zticks([])\n", "\n", "pose.plot(ax=ax2)\n", - "plt.show()\n" + "plt.show()" ], "metadata": { "collapsed": false, diff --git a/notebooks/demo/static_loader_demo.ipynb b/notebooks/demo/static_loader_demo.ipynb index 81ffd1a..83a259f 100644 --- a/notebooks/demo/static_loader_demo.ipynb +++ b/notebooks/demo/static_loader_demo.ipynb @@ -28,7 +28,7 @@ "execution_count": 18, "outputs": [], "source": [ - "dirname = '/Users/paulpierzchlewicz/PycharmProjects/propose/data/rat7m/s4-d1' # Choose this such that it points to your dataset" + "dirname = \"/Users/paulpierzchlewicz/PycharmProjects/propose/data/rat7m/s4-d1\" # Choose this such that it points to your dataset" ], "metadata": { "collapsed": false, @@ -66,7 +66,7 @@ } ], "source": [ - "for i in dataloaders['train']:\n", + "for i in dataloaders[\"train\"]:\n", " print(i.pose_matrix.shape)\n", " print(i.adjacency_matrix.shape)\n", " print(i.image.shape)\n", diff --git a/notebooks/preprocess_rat7m.ipynb b/notebooks/preprocess_rat7m.ipynb index 52ad0bf..d8e1952 100644 --- a/notebooks/preprocess_rat7m.ipynb +++ b/notebooks/preprocess_rat7m.ipynb @@ -34,9 +34,9 @@ "execution_count": 2, "outputs": [], "source": [ - "dirname = '/Users/paulpierzchlewicz/PycharmProjects/propose/data/rat7m' # Choose this such that it points to your dataset\n", - "data_key = 's4-d1'\n", - "mocap_path = f'{dirname}/mocap/mocap-{data_key}.mat'" + "dirname = \"/Users/paulpierzchlewicz/PycharmProjects/propose/data/rat7m\" # Choose this such that it points to your dataset\n", + "data_key = \"s4-d1\"\n", + "mocap_path = f\"{dirname}/mocap/mocap-{data_key}.mat\"" ], "metadata": { "collapsed": false, @@ -159,10 +159,10 @@ "source": [ "from pathlib import Path\n", "\n", - "pose_dir = Path(f'{dirname}/{data_key}/poses')\n", + "pose_dir = Path(f\"{dirname}/{data_key}/poses\")\n", "pose_dir.mkdir(parents=True, exist_ok=True)\n", "\n", - "pose_path = pose_dir / f'{data_key}.npy'\n", + "pose_path = pose_dir / f\"{data_key}.npy\"\n", "\n", "mocap.save(pose_path)" ], @@ -179,13 +179,14 @@ "outputs": [], "source": [ "import pickle\n", - "camera_dir = Path(f'{dirname}/{data_key}/cameras')\n", + "\n", + "camera_dir = Path(f\"{dirname}/{data_key}/cameras\")\n", "camera_dir.mkdir(parents=True, exist_ok=True)\n", "\n", - "camera_path = camera_dir / f'{data_key}.pickle'\n", + "camera_path = camera_dir / f\"{data_key}.pickle\"\n", "\n", - "with open(camera_path, 'wb') as f:\n", - " pickle.dump(cameras, f)\n" + "with open(camera_path, \"wb\") as f:\n", + " pickle.dump(cameras, f)" ], "metadata": { "collapsed": false, @@ -209,7 +210,8 @@ ], "source": [ "from pathlib import PurePath\n", - "PurePath('/Users/paulpierzchlewicz/PycharmProjects/propose/data/rat7m').name" + "\n", + "PurePath(\"/Users/paulpierzchlewicz/PycharmProjects/propose/data/rat7m\").name" ], "metadata": { "collapsed": false, diff --git a/propose/utils/reproducibility.py b/propose/utils/reproducibility.py index bb77aab..20b3475 100644 --- a/propose/utils/reproducibility.py +++ b/propose/utils/reproducibility.py @@ -31,17 +31,26 @@ def get_commit_hash() -> str: Returns the current commit hash shortend to 7 characters. """ - return subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).decode("utf-8").strip() + return ( + subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]) + .decode("utf-8") + .strip() + ) def check_uncommitted_changes() -> bool: """ Checks if there are uncommited changes. """ - uncommitted = subprocess.check_output(["git", "diff", "--name-only"]).decode("utf-8").strip() != "" + uncommitted = ( + subprocess.check_output(["git", "diff", "--name-only"]).decode("utf-8").strip() + != "" + ) if uncommitted: - warn("There are uncommitted changes in the repository. The current logged commit hash will not be correct.") + warn( + "There are uncommitted changes in the repository. The current logged commit hash will not be correct." + ) return uncommitted diff --git a/setup.py b/setup.py index 0abe4ce..5af7c3b 100644 --- a/setup.py +++ b/setup.py @@ -6,13 +6,17 @@ here = path.abspath(path.dirname(__file__)) -version = '0.0' +version = "0.0" def _get_version_hash(): """Talk to git and find out the tag/hash of our latest commit""" try: - return subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).decode("utf-8").strip() + return ( + subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]) + .decode("utf-8") + .strip() + ) except subprocess.CalledProcessError: print("Couldn't run git to get a version number for setup.py") return version