
写真から360°の3Dが生成できる 『PanoHead』の使い方/Google Colab
1枚の写真から頭部の360°3Dモデルを構築できる『PanoHead』のテスト。Google Colabを使用。

リポジトリはこちら↓
①コード入力・実行
%cd /content
!git clone -b dev1 https://github.com/camenduru/PanoHead
!apt -y install -qq aria2
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/camenduru/PanoHead/resolve/main/ablation-trigridD-1-025000.pkl -d /content/PanoHead/models -o ablation-trigridD-1-025000.pkl
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/camenduru/PanoHead/resolve/main/baseline-easy-khair-025000.pkl -d /content/PanoHead/models -o baseline-easy-khair-025000.pkl
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/camenduru/PanoHead/resolve/main/easy-khair-180-gpc0.8-trans10-025000.pkl -d /content/PanoHead/models -o easy-khair-180-gpc0.8-trans10-025000.pkl
!pip install imgui glfw pyspng mrcfile ninja plyfile trimesh onnxruntime onnx
%cd /content
!git clone -b dev https://github.com/camenduru/3DDFA_V2
%cd /content/3DDFA_V2
!sh ./build.sh
!cp -rf /content/PanoHead/3DDFA_V2_cropping/test /content/3DDFA_V2
!cp /content/PanoHead/3DDFA_V2_cropping/dlib_kps.py /content/3DDFA_V2
!cp /content/PanoHead/3DDFA_V2_cropping/recrop_images.py /content/3DDFA_V2
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/camenduru/shape_predictor_68_face_landmarks/resolve/main/shape_predictor_68_face_landmarks.dat -d /content/3DDFA_V2 -o shape_predictor_68_face_landmarks.dat
!mkdir /content/in /content/stage /content/output
②inフォルダ内に画像を格納
以下のjpeg画像「test.jpg」をアップロードしてみた。

③コード入力・実行
%cd /content/3DDFA_V2
!rm -rf /content/stage/* /content/3DDFA_V2/crop_samples/img/* /content/3DDFA_V2/test/original/* /content/output/*
!cp /content/in/* /content/3DDFA_V2/test/original
!python dlib_kps.py
!python recrop_images.py -i data.pkl -j dataset.json
!cp -rf /content/3DDFA_V2/crop_samples/img/* /content/stage
# %cd /content/PanoHead
# !./gen_pti_script.sh
stageフォルダ内にtest.jpgが格納されていることを確認する。
④コード入力・実行
%cd /content/PanoHead
!python projector_withseg.py --num-steps=300 --num-steps-pti=300 --outdir=/content/output --target_img=/content/stage --network=/content/PanoHead/models/easy-khair-180-gpc0.8-trans10-025000.pkl --idx 0
output>content/output/easy-khair-180-gpc0.8-trans10-025000.pkl >0>proj.png、proj.mp4が格納されていることを確認する。
⑤コード入力・実行
%cd /content/PanoHead
!python gen_videos_proj_withseg.py --output=/content/output/easy-khair-180-gpc0.8-trans10-025000.pkl/0/PTI_render/pre.mp4 --latent=/content/output/easy-khair-180-gpc0.8-trans10-025000.pkl/0/projected_w.npz --trunc 0.7 --network /content/PanoHead/models/easy-khair-180-gpc0.8-trans10-025000.pkl --cfg Head
output>content/output/easy-khair-180-gpc0.8-trans10-025000.pkl>0>PTI_render>pre.mp4が格納されていることを確認する。
%cd /content/PanoHead
!python gen_videos_proj_withseg.py --output=/content/output/easy-khair-180-gpc0.8-trans10-025000.pkl/0/PTI_render/post.mp4 --latent=/content/output/easy-khair-180-gpc0.8-trans10-025000.pkl/0/projected_w.npz --trunc 0.7 --network /content/output/easy-khair-180-gpc0.8-trans10-025000.pkl/0/fintuned_generator.pkl --cfg Head
output>content/output/easy-khair-180-gpc0.8-trans10-025000.pkl>0>PTI_render>post.mp4が生成されたgif。
生成結果

360°違和感なく綺麗に生成できました。
最適化している過程のgif

画像によってはエラーになってしまうことが多々ある。
真正面を向いている画像、肩まで写り込む距離感の画像が生成しやすい。
西洋人の写真の方がエラーが出にくいような。
今後の活用可能性
革新的な技術ですが、現段階では用途はあまり思い浮かびません。
・3DモデルとしてFBXやBlender形式でエクスポートできる
・顔のパーツ分けがされた3Dモデルをエクスポートできる
・体も360°構築される
上記の技術までいけば、3DCGでの人物モデリングはAIにほとんどお任せできるようになって、クリエイティブがより捗って良さそう。
自分の見た目のキャラクターをゲーム内に誰でも簡単に持っていけるようになって、自分自身を主人公にして操作できる・喋らせられるとかできたら面白そう!