Created
August 6, 2022 16:20
-
-
Save armindocachada/af1b21ef57d8f07516f36c76b20950c7 to your computer and use it in GitHub Desktop.
PIFu Demo with pytorch downgraded
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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "PIFu Demo with pytorch downgraded", | |
"provenance": [], | |
"collapsed_sections": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"accelerator": "GPU" | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/armindocachada/af1b21ef57d8f07516f36c76b20950c7/pifu-demo-with-pytorch-downgraded.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "LWTVk_PITxiE" | |
}, | |
"source": [ | |
"# PIFu: Pixel-Aligned Implicit Function for High-Resolution Clothed Human Digitization" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "wmFdsTvLKtBO" | |
}, | |
"source": [ | |
"Demo of the original PyTorch based implementation provided here: https://github.com/shunsukesaito/PIFu\n", | |
"\n", | |
"## Note\n", | |
"Before running this notebook make sure that your runtime type is 'Python 3 with GPU acceleration'. Go to Edit > Notebook settings > Hardware Accelerator > Select \"GPU\".\n", | |
"\n", | |
"## More Info\n", | |
"- Paper: https://arxiv.org/pdf/1905.05172.pdf\n", | |
"- Repo: https://github.com/shunsukesaito/PIFu\n", | |
"- Project Page: https://shunsukesaito.github.io/PIFu/" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "8vZaAyhUJ9QC" | |
}, | |
"source": [ | |
"## Requirements\n", | |
"- Python 3\n", | |
"- PyTorch tested on 1.4.0\n", | |
"- json\n", | |
"- PIL\n", | |
"- skimage\n", | |
"- tqdm\n", | |
"- numpy\n", | |
"- cv2" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "M9Az9CQpTT8_", | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"outputId": "86cd915d-ecdf-42ac-af8a-aefc6ad4ac03" | |
}, | |
"source": [ | |
"!git clone https://github.com/shunsukesaito/PIFu.git" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Cloning into 'PIFu'...\n", | |
"remote: Enumerating objects: 218, done.\u001b[K\n", | |
"remote: Counting objects: 100% (11/11), done.\u001b[K\n", | |
"remote: Compressing objects: 100% (10/10), done.\u001b[K\n", | |
"remote: Total 218 (delta 4), reused 6 (delta 1), pack-reused 207\u001b[K\n", | |
"Receiving objects: 100% (218/218), 2.43 MiB | 22.62 MiB/s, done.\n", | |
"Resolving deltas: 100% (90/90), done.\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Y0rgMInwTt0s" | |
}, | |
"source": [ | |
"## Demo" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "UrIcZweSNRFI", | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"outputId": "45b4b517-925d-4773-dfa4-89bd4ec5cf84" | |
}, | |
"source": [ | |
"cd /content/PIFu" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"/content/PIFu\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "k3jjm6HuQRk8", | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"outputId": "062c251e-61e0-49e9-d1b3-3ad4f051f665" | |
}, | |
"source": [ | |
"!sh ./scripts/download_trained_model.sh" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"+ mkdir -p checkpoints\n", | |
"+ cd checkpoints\n", | |
"+ wget https://drive.google.com/uc?export=download&id=1zEmVXG2VHy0MMzngcRshB4D8Sr_oLHsm -O net_G\n", | |
"--2022-08-06 15:35:02-- https://drive.google.com/uc?export=download&id=1zEmVXG2VHy0MMzngcRshB4D8Sr_oLHsm\n", | |
"Resolving drive.google.com (drive.google.com)... 74.125.196.113, 74.125.196.102, 74.125.196.101, ...\n", | |
"Connecting to drive.google.com (drive.google.com)|74.125.196.113|:443... connected.\n", | |
"HTTP request sent, awaiting response... 303 See Other\n", | |
"Location: https://doc-14-0o-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/u66c4r86q1p8auq46lfk2dipmatj3jgb/1659800100000/14428417455748421393/*/1zEmVXG2VHy0MMzngcRshB4D8Sr_oLHsm?e=download&uuid=10de986b-43fb-45a1-b26f-088ac7cc7891 [following]\n", | |
"Warning: wildcards not supported in HTTP.\n", | |
"--2022-08-06 15:35:07-- https://doc-14-0o-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/u66c4r86q1p8auq46lfk2dipmatj3jgb/1659800100000/14428417455748421393/*/1zEmVXG2VHy0MMzngcRshB4D8Sr_oLHsm?e=download&uuid=10de986b-43fb-45a1-b26f-088ac7cc7891\n", | |
"Resolving doc-14-0o-docs.googleusercontent.com (doc-14-0o-docs.googleusercontent.com)... 172.217.193.132, 2607:f8b0:400c:c03::84\n", | |
"Connecting to doc-14-0o-docs.googleusercontent.com (doc-14-0o-docs.googleusercontent.com)|172.217.193.132|:443... connected.\n", | |
"HTTP request sent, awaiting response... 200 OK\n", | |
"Length: 62510909 (60M) [application/octet-stream]\n", | |
"Saving to: ‘net_G’\n", | |
"\n", | |
"net_G 100%[===================>] 59.61M 336MB/s in 0.2s \n", | |
"\n", | |
"2022-08-06 15:35:07 (336 MB/s) - ‘net_G’ saved [62510909/62510909]\n", | |
"\n", | |
"+ wget https://drive.google.com/uc?export=download&id=1V83B6GDIjYMfHdpg-KcCSAPgHxpafHgd -O net_C\n", | |
"--2022-08-06 15:35:07-- https://drive.google.com/uc?export=download&id=1V83B6GDIjYMfHdpg-KcCSAPgHxpafHgd\n", | |
"Resolving drive.google.com (drive.google.com)... 74.125.196.113, 74.125.196.102, 74.125.196.101, ...\n", | |
"Connecting to drive.google.com (drive.google.com)|74.125.196.113|:443... connected.\n", | |
"HTTP request sent, awaiting response... 303 See Other\n", | |
"Location: https://doc-00-0o-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/ee4fa845p3arp1ct878if9hu9qoppn43/1659800100000/14428417455748421393/*/1V83B6GDIjYMfHdpg-KcCSAPgHxpafHgd?e=download&uuid=994d6160-ac54-490f-bdf0-c45900bb3d77 [following]\n", | |
"Warning: wildcards not supported in HTTP.\n", | |
"--2022-08-06 15:35:08-- https://doc-00-0o-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/ee4fa845p3arp1ct878if9hu9qoppn43/1659800100000/14428417455748421393/*/1V83B6GDIjYMfHdpg-KcCSAPgHxpafHgd?e=download&uuid=994d6160-ac54-490f-bdf0-c45900bb3d77\n", | |
"Resolving doc-00-0o-docs.googleusercontent.com (doc-00-0o-docs.googleusercontent.com)... 172.217.193.132, 2607:f8b0:400c:c03::84\n", | |
"Connecting to doc-00-0o-docs.googleusercontent.com (doc-00-0o-docs.googleusercontent.com)|172.217.193.132|:443... connected.\n", | |
"HTTP request sent, awaiting response... 200 OK\n", | |
"Length: 36570643 (35M) [application/octet-stream]\n", | |
"Saving to: ‘net_C’\n", | |
"\n", | |
"net_C 100%[===================>] 34.88M 169MB/s in 0.2s \n", | |
"\n", | |
"2022-08-06 15:35:09 (169 MB/s) - ‘net_C’ saved [36570643/36570643]\n", | |
"\n", | |
"+ cd ..\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!pip install torch==1.4.0" | |
], | |
"metadata": { | |
"id": "fr2fAD4h4ktw", | |
"outputId": "c89d37ff-cc00-4eb8-a40e-01c1a42d3320", | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
} | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", | |
"Collecting torch==1.4.0\n", | |
" Downloading torch-1.4.0-cp37-cp37m-manylinux1_x86_64.whl (753.4 MB)\n", | |
"\u001b[K |████████████████████████████████| 753.4 MB 7.1 kB/s \n", | |
"\u001b[?25hInstalling collected packages: torch\n", | |
" Attempting uninstall: torch\n", | |
" Found existing installation: torch 1.12.0+cu113\n", | |
" Uninstalling torch-1.12.0+cu113:\n", | |
" Successfully uninstalled torch-1.12.0+cu113\n", | |
"\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", | |
"torchvision 0.13.0+cu113 requires torch==1.12.0, but you have torch 1.4.0 which is incompatible.\n", | |
"torchtext 0.13.0 requires torch==1.12.0, but you have torch 1.4.0 which is incompatible.\n", | |
"torchaudio 0.12.0+cu113 requires torch==1.12.0, but you have torch 1.4.0 which is incompatible.\n", | |
"fastai 2.7.7 requires torch<1.13,>=1.7, but you have torch 1.4.0 which is incompatible.\u001b[0m\n", | |
"Successfully installed torch-1.4.0\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!pip install torchvision==0.5.0" | |
], | |
"metadata": { | |
"id": "YchK6vyd6Bls", | |
"outputId": "f8f5ac54-da37-44d1-9aa8-1cf61a4a17c0", | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
} | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", | |
"Collecting torchvision==0.5.0\n", | |
" Downloading torchvision-0.5.0-cp37-cp37m-manylinux1_x86_64.whl (4.0 MB)\n", | |
"\u001b[K |████████████████████████████████| 4.0 MB 3.2 MB/s \n", | |
"\u001b[?25hRequirement already satisfied: pillow>=4.1.1 in /usr/local/lib/python3.7/dist-packages (from torchvision==0.5.0) (7.1.2)\n", | |
"Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from torchvision==0.5.0) (1.21.6)\n", | |
"Requirement already satisfied: torch==1.4.0 in /usr/local/lib/python3.7/dist-packages (from torchvision==0.5.0) (1.4.0)\n", | |
"Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from torchvision==0.5.0) (1.15.0)\n", | |
"Installing collected packages: torchvision\n", | |
" Attempting uninstall: torchvision\n", | |
" Found existing installation: torchvision 0.13.0+cu113\n", | |
" Uninstalling torchvision-0.13.0+cu113:\n", | |
" Successfully uninstalled torchvision-0.13.0+cu113\n", | |
"\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", | |
"fastai 2.7.7 requires torch<1.13,>=1.7, but you have torch 1.4.0 which is incompatible.\n", | |
"fastai 2.7.7 requires torchvision>=0.8.2, but you have torchvision 0.5.0 which is incompatible.\u001b[0m\n", | |
"Successfully installed torchvision-0.5.0\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "6heKcA-0QEBw" | |
}, | |
"source": [ | |
"# RUN PIFu\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"import torch;\n", | |
"torch.__version__" | |
], | |
"metadata": { | |
"id": "fgwl0z-p23rn", | |
"outputId": "548d69b8-7be4-43b5-9849-8045a8b4ede7", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 35 | |
} | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"'1.4.0'" | |
], | |
"application/vnd.google.colaboratory.intrinsic+json": { | |
"type": "string" | |
} | |
}, | |
"metadata": {}, | |
"execution_count": 6 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "5995t2PnQTmG", | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"outputId": "24ffefca-b4f2-4d37-84c2-076d090ee482" | |
}, | |
"source": [ | |
"!sh ./scripts/test.sh" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"+ GPU_ID=0\n", | |
"+ DISPLAY_ID=10\n", | |
"+ NAME=pifu_demo\n", | |
"+ BATCH_SIZE=1\n", | |
"+ MLP_DIM=257 1024 512 256 128 1\n", | |
"+ MLP_DIM_COLOR=513 1024 512 256 128 3\n", | |
"+ VOL_RES=256\n", | |
"+ CHECKPOINTS_NETG_PATH=./checkpoints/net_G\n", | |
"+ CHECKPOINTS_NETC_PATH=./checkpoints/net_C\n", | |
"+ TEST_FOLDER_PATH=./sample_images\n", | |
"+ CUDA_VISIBLE_DEVICES=0 python ./apps/eval.py --name pifu_demo --batch_size 1 --mlp_dim 257 1024 512 256 128 1 --mlp_dim_color 513 1024 512 256 128 3 --num_stack 4 --num_hourglass 2 --resolution 256 --hg_down ave_pool --norm group --norm_color group --test_folder_path ./sample_images --load_netG_checkpoint_path ./checkpoints/net_G --load_netC_checkpoint_path ./checkpoints/net_C\n", | |
"initialize network with normal\n", | |
"Using Network: hgpifu\n", | |
"loading for net C ... ./checkpoints/net_C\n", | |
"initialize network with normal\n", | |
"num; 1\n", | |
"0it [00:00, ?it/s]./sample_images/codemental_2.png ./sample_images/codemental_2_mask.png\n", | |
"/content/PIFu/lib/mesh_util.py:45: FutureWarning: marching_cubes_lewiner is deprecated in favor of marching_cubes. marching_cubes_lewiner will be removed in version 0.19\n", | |
" verts, faces, normals, values = measure.marching_cubes_lewiner(sdf, 0.5)\n", | |
"1it [00:06, 6.57s/it]\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"# Training Demo\n", | |
"\n", | |
"Currently it is not possible to run the training in Google Colab. Best option is to run it in Linux or using a Dockerfile (see my blog article at spltech.co.uk/blog)" | |
], | |
"metadata": { | |
"id": "LyJzIKhQMOQb" | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment