前提
poetryを使用してgithubに上がっていたコードを実行しようとしています。
コードの実行前にpoetry add pytorch3dでインストールしたのですが、
poetry run python animate_face.py --helpというコードに対して、
ModuleNotFoundError: No module named 'pytorch3d'のエラーが出てしまっています。
実現したいこと
- poetry run python animate_face.py --helpを正常に実行できるようにしたい。
発生している問題・エラーメッセージ
$ poetry run python animate_face.py --help Traceback (most recent call last): File "animate_face.py", line 12, in <module> from utils.renderer import Renderer File "/home/challenger/ascender/notebooks/utils/renderer.py", line 11, in <module> from pytorch3d.io import load_obj ModuleNotFoundError: No module named 'pytorch3d'
該当のソースコード
import argparse import numpy as np import torch as th from utils.renderer import Renderer from utils.helpers import smooth_geom, load_mask, get_template_verts, load_audio, audio_chunking from models.vertex_unet import VertexUnet from models.context_model import ContextModel from models.encoders import MultimodalEncoder parser = argparse.ArgumentParser() parser.add_argument("--model_dir", type=str, default="pretrained_models", help="directory containing the models to load") parser.add_argument("--audio_file", type=str, default="assets/example_sentence.wav", help="wave file to use for face animation" ) parser.add_argument("--face_template", type=str, default="assets/face_template.obj", help=".obj file containing neutral template mesh" ) parser.add_argument("--output", type=str, default="video.mp4", help="video output file" ) args = parser.parse_args() """ load assets """ print("load assets...") template_verts = get_template_verts(args.face_template) audio = load_audio(args.audio_file) mean = th.from_numpy(np.load("assets/face_mean.npy")) stddev = th.from_numpy(np.load("assets/face_std.npy")) forehead_mask = th.from_numpy(load_mask("assets/forehead_mask.txt", dtype=np.float32)).cuda() neck_mask = th.from_numpy(load_mask("assets/neck_mask.txt", dtype=np.float32)).cuda() renderer = Renderer("assets/face_template.obj") """ load models """ print("load models...") geom_unet = VertexUnet(classes=128, heads=16, n_vertices=6172, mean=mean, stddev=stddev, ) geom_unet.load(args.model_dir) geom_unet.cuda().eval() context_model = ContextModel(classes=128, heads=16, audio_dim=128 ) context_model.load(args.model_dir) context_model.cuda().eval() encoder = MultimodalEncoder(classes=128, heads=16, expression_dim=128, audio_dim=128, n_vertices=6172, mean=mean, stddev=stddev, ) encoder.load(args.model_dir) encoder.cuda().eval() """ generate and render sequence """ print("animate face mesh...") # run template mesh and audio through networks audio = audio_chunking(audio, frame_rate=30, chunk_size=16000) with th.no_grad(): audio_enc = encoder.audio_encoder(audio.cuda().unsqueeze(0))["code"] one_hot = context_model.sample(audio_enc, argmax=False)["one_hot"] T = one_hot.shape[1] geom = template_verts.cuda().view(1, 1, 6172, 3).expand(-1, T, -1, -1).contiguous() result = geom_unet(geom, one_hot)["geom"].squeeze(0) # smooth results result = smooth_geom(result, forehead_mask) result = smooth_geom(result, neck_mask) # render sequence print("render...") renderer.to_video(result, args.audio_file, args.output) print("done")
補足情報(FW/ツールのバージョンなど)
poetry showを見る限り、確実にpytorch3dはインストールされています。(version=0.0.1なので、もしかしたら古すぎるのが問題なのかも知れません)
$ poetry show attrs black certifi cffi charset-normalizer click cmake coverage cryptography cycler ffmpeg flake8 fonttools idna imageio iniconfig isort javascript kiwisolver matplotlib mccabe mypy mypy-extensions networkx numpy opencv-python packaging pathspec pickle-secure pillow platformdirs pluggy py pycodestyle pycparser pyflakes pyparsing pytest pytest-cov python-dateutil python-speech-features pytorch3d pywavelets requests scikit-image scipy setuptools-scm six tifffile tomli torch torchaudio torchvision tqdm typing-extensions urllib3
追記
githubからpytorch3dをインストールしようとしたところ、
$ poetry add 'git+https://github.com/facebookresearch/pytorch3d.git@stable' PackageInfoError Unable to determine package info for path: /tmp/pypoetry-git-pytorch3dpc5yil8r Fallback egg_info generation failed. Command ['/tmp/tmpymg8pb33/.venv/bin/python', 'setup.py', 'egg_info'] errored with the following return code 1, and output: Traceback (most recent call last): File "setup.py", line 14, in <module> import torch ModuleNotFoundError: No module named 'torch' at /usr/local/lib/python3.8/dist-packages/poetry/inspection/info.py:500 in _pep517_metadata 496│ try: 497│ venv.run_python("setup.py", "egg_info") 498│ return cls.from_metadata(path) 499│ except EnvCommandError as fbe: → 500│ raise PackageInfoError( 501│ path, "Fallback egg_info generation failed.", fbe 502│ ) 503│ finally: 504│ os.chdir(cwd.as_posix())
と、今度はtorchがModuleNotFoundErrorになってしまっています。
あなたの回答
tips
プレビュー