Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
451 additions
and
707 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,69 @@ | ||
## Dependencies | ||
|
||
***Note: All instructions were tested on Ubuntu 18.04.3.*** | ||
*Note: this was tested on Ubuntu 18.04.3.* | ||
|
||
Anaconda is the easiest way to install the dependencies. If you don't have it installed yet, open a Bash shell and install Miniconda as follows: | ||
### All-in-one script | ||
|
||
On a freshly installed Ubuntu 18.04, just run: | ||
|
||
```bash | ||
./install_dependencies.sh | ||
``` | ||
|
||
This should take care of everything. | ||
|
||
---- | ||
### Step-by-step explanation | ||
|
||
[Anaconda](https://anaconda.com) is the simplest way to install most of the dependencies. If you don't have it installed yet, open a Bash shell and install Miniconda as follows: | ||
|
||
```bash | ||
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh | ||
bash ./Miniconda3-latest-Linux-x86_64.sh | ||
eval "$($HOME/miniconda3/bin/conda shell.bash hook)" | ||
$ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh | ||
$ bash ./Miniconda3-latest-Linux-x86_64.sh -b | ||
$ eval "$($HOME/miniconda3/bin/conda shell.bash hook)" | ||
``` | ||
|
||
Create a new environment and install the dependencies: | ||
|
||
```bash | ||
conda create --name metro-pose3d python=3.6 Cython matplotlib pillow imageio ffmpeg scikit-image scikit-learn tqdm numba | ||
conda activate metro-pose3d | ||
conda install opencv3 -c menpo | ||
pip install tensorflow-gpu==1.13.1 attrdict jpeg4py transforms3d more_itertools spacepy | ||
$ conda create --yes --name metro-pose3d python=3.6 Cython matplotlib pillow imageio ffmpeg scikit-image scikit-learn tqdm numba | ||
$ conda activate metro-pose3d | ||
$ conda install --yes opencv3 -c menpo | ||
$ pip install tensorflow-gpu==1.13.1 attrdict jpeg4py transforms3d more_itertools spacepy | ||
``` | ||
### COCO tools | ||
#### COCO tools | ||
|
||
Install the [COCO tools](https://github.com/pdollar/coco) (used for managing runlength-encoded masks): | ||
Install the [COCO tools](https://github.com/cocodataset/cocoapi) (used for managing runlength-encoded masks): | ||
|
||
``` | ||
git clone https://github.com/cocodataset/cocoapi | ||
pushd coco/PythonAPI | ||
make | ||
python setup.py install | ||
popd | ||
rm -rf cocoapi | ||
$ git clone https://github.com/cocodataset/cocoapi | ||
$ cd cocoapi/PythonAPI | ||
$ make | ||
$ python setup.py install | ||
$ cd ../.. | ||
$ rm -rf cocoapi | ||
``` | ||
|
||
### CDF | ||
If you also want to train the model, you'll need to install the CDF library because | ||
Human3.6M supplies the annotations as cdf files. We read them using the [SpacePy](https://spacepy.github.io/) Python library, | ||
which in turn depends on the CDF library. | ||
#### CDF | ||
We need to install the [CDF library](https://cdf.gsfc.nasa.gov/) because Human3.6M supplies the annotations as cdf files. | ||
We read them using the [SpacePy](https://spacepy.github.io/) Python library, which in turn depends on the CDF library. | ||
|
||
```bash | ||
wget https://spdf.sci.gsfc.nasa.gov/pub/software/cdf/dist/cdf37_0/linux/cdf37_1-dist-cdf.tar.gz | ||
tar xf cdf37_1-dist-cdf.tar.gz | ||
rm cdf37_1-dist-cdf.tar.gz | ||
cd cdf37_1-dist | ||
make OS=linux ENV=gnu CURSES=yes FORTRAN=no UCOPTIONS=-O2 SHARED=yes -j4 all | ||
$ wget https://spdf.sci.gsfc.nasa.gov/pub/software/cdf/dist/cdf37_1/linux/cdf37_1-dist-cdf.tar.gz | ||
$ tar xf cdf37_1-dist-cdf.tar.gz | ||
$ rm cdf37_1-dist-cdf.tar.gz | ||
$ cd cdf37_1-dist | ||
$ make OS=linux ENV=gnu CURSES=yes FORTRAN=no UCOPTIONS=-O2 SHARED=yes -j4 all | ||
``` | ||
|
||
If you have sudo rights, simply run `sudo make install`. If you have no `sudo` rights, make sure to add the | ||
`cdf37_1-dist/src/lib` to the `LD_LIBRARY_PATH` environment variable (add to ~/.bashrc for permanent effect), or use GNU Stow. | ||
|
||
### libjpeg-turbo | ||
|
||
Install libjpeg-turbo to make JPEG loading faster. TODO | ||
#### libjpeg-turbo (optional) | ||
Install libjpeg-turbo to make JPEG loading faster. | ||
|
||
```bash | ||
$ git clone https://github.com/libjpeg-turbo/libjpeg-turbo.git | ||
$ cmake -G"Unix Makefiles" . | ||
$ make | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +0,0 @@ | ||
## Inference | ||
|
||
This guide is about how to run a pretrained model on new images. | ||
|
||
*--Coming soon--* | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
|
||
import numpy as np | ||
import skimage.data | ||
import skimage.transform | ||
import tensorflow as tf | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description='MeTRo-Pose3D', allow_abbrev=False) | ||
parser.add_argument('--model-path', type=str, required=True) | ||
opts = parser.parse_args() | ||
|
||
images_numpy = np.stack([skimage.transform.resize(skimage.data.astronaut(), (256, 256))]) | ||
images_tensor = tf.convert_to_tensor(images_numpy) | ||
poses_tensor = estimate_pose(images_tensor, opts.model_path) | ||
|
||
with tf.Session() as sess: | ||
poses_arr = sess.run(poses_tensor) | ||
edges = [(1, 0), (0, 18), (0, 2), (2, 3), (3, 4), (0, 8), (8, 9), (9, 10), (18, 5), (5, 6), | ||
(6, 7), (18, 11), (11, 12), (12, 13), (15, 14), (14, 1), (17, 16), (16, 1)] | ||
visualize_pose(image=images_numpy[0], coords=poses_arr[0], edges=edges) | ||
|
||
|
||
def estimate_pose(im, model_path): | ||
graph_def = tf.GraphDef() | ||
with tf.gfile.GFile(model_path, 'rb') as f: | ||
graph_def.ParseFromString(f.read()) | ||
|
||
im_t = tf.cast(im, tf.float32) # / 255 *2 -1 | ||
im_t = tf.transpose(im_t, [0, 3, 1, 2]) | ||
return tf.import_graph_def( | ||
graph_def, input_map={'input:0': im_t}, return_elements=['pred'])[0].outputs[0] | ||
|
||
|
||
def visualize_pose(image, coords, edges): | ||
import matplotlib.pyplot as plt | ||
plt.switch_backend('TkAgg') | ||
# noinspection PyUnresolvedReferences | ||
from mpl_toolkits.mplot3d import Axes3D | ||
|
||
# Matplotlib interprets the Z axis as vertical, but our pose | ||
# has Y as the vertical axis. | ||
# Therefore we do a 90 degree rotation around the horizontal (X) axis | ||
coords2 = coords.copy() | ||
coords[:, 1], coords[:, 2] = coords2[:, 2], -coords2[:, 1] | ||
|
||
fig = plt.figure(figsize=(10, 5)) | ||
image_ax = fig.add_subplot(1, 2, 1) | ||
image_ax.set_title('Input') | ||
image_ax.imshow(image) | ||
|
||
pose_ax = fig.add_subplot(1, 2, 2, projection='3d') | ||
pose_ax.set_title('Prediction') | ||
range_ = 800 | ||
pose_ax.set_xlim3d(-range_, range_) | ||
pose_ax.set_ylim3d(-range_, range_) | ||
pose_ax.set_zlim3d(-range_, range_) | ||
|
||
for i_start, i_end in edges: | ||
pose_ax.plot(*zip(coords[i_start], coords[i_end]), marker='o', markersize=2) | ||
|
||
pose_ax.scatter(coords[:, 0], coords[:, 1], coords[:, 2], s=2) | ||
|
||
fig.tight_layout() | ||
plt.show() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
sudo apt install build-essential --yes wget curl gfortran git ncurses-dev unzip tar | ||
|
||
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh | ||
bash ./Miniconda3-latest-Linux-x86_64.sh -b | ||
eval "$("$HOME/miniconda3/bin/conda" shell.bash hook)" | ||
|
||
conda create --yes --name metro-pose3d python=3.6 Cython matplotlib pillow imageio ffmpeg scikit-image scikit-learn tqdm numba | ||
conda activate metro-pose3d | ||
conda install --yes opencv3 -c menpo | ||
pip install tensorflow-gpu==1.13.1 attrdict jpeg4py transforms3d more_itertools spacepy | ||
|
||
git clone https://github.com/cocodataset/cocoapi | ||
cd cocoapi/PythonAPI | ||
make | ||
python setup.py install | ||
cd ../.. | ||
rm -rf cocoapi | ||
|
||
wget https://spdf.sci.gsfc.nasa.gov/pub/software/cdf/dist/cdf37_1/linux/cdf37_1-dist-cdf.tar.gz | ||
tar xf cdf37_1-dist-cdf.tar.gz | ||
rm cdf37_1-dist-cdf.tar.gz | ||
cd cdf37_1-dist | ||
make OS=linux ENV=gnu CURSES=yes FORTRAN=no UCOPTIONS=-O2 SHARED=yes -j4 all | ||
|
||
export LD_LIBRARY_PATH=$PWD/src/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} | ||
|
||
# Optional: | ||
# wget https://sourceforge.net/projects/libjpeg-turbo/files/2.0.4/libjpeg-turbo-2.0.4.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.