pkhungurn / talking-head-anime-3-demo

Demo Programs for the "Talking Head(?) Anime from a Single Image 3: Now the Body Too" Project
http://pkhungurn.github.io/talking-head-anime-3/
MIT License
950 stars 101 forks source link

Needs a little modification to run on M1Mac. #8

Open autumnmotor opened 1 year ago

autumnmotor commented 1 year ago

hi. I've tried ifacialmocap_puppeteer.py and manual_poser.py and they are very interesting! It's cool to be able to move a single picture like this without the complicated setup of Live2D!

By the way, I tried running this script on my M1Mac, but it required some modifications to the source. First, since M1Mac does not support cuda,

if name == "main": ... device = torch.device('cuda')

to

device = torch.device('cpu')

I had to change it to M1Mac should support "torch.device('mps')", but in this case, in the update_images method

output_image = self.poser.pose(self.torch_source_image, pose, output_index)

I am getting an error at the above location.

Loading the eyebrow decomposer ... DONE!!! Loading the eyebrow morphing conbiner ... DONE!!! Loading the face morpher ... DONE!!! Loading the face-body rotator ... DONE!!! Loading the combiner ... DONE!!! loc("mps_scatter_along_axis"("(mpsFileLoc): /AppleInternal/Library/BuildRoots/2d9b4df9-4b93-11ed->b0fc-2e32217d8374/Library/Caches/com.apple.xbs/Sources/MetalPerformanceShadersGraph/mpsgraph/>MetalPerformanceShadersGraph/Core/Files/MPSGraphUtilities.mm":350:0)): error: invalid input tensor >shapes, indices shape and updates shape must be equal /AppleInternal/Library/BuildRoots/2d9b4df9-4b93-11ed-b0fc-2e32217d8374/Library/Caches/com.apple.xbs/>Sources/MetalPerformanceShadersGraph/mpsgraph/MetalPerformanceShadersGraph/Core/Files/>MPSGraphExecutable.mm:1584: failed assertion `Error: MLIR pass manager failed' /opt/homebrew/Caskroom/miniconda/base/envs/talking-head-anime-3-demo/bin/pythonw: line 3: 15381 >Abort trap: 6 /opt/homebrew/Caskroom/miniconda/base/envs/talking-head-anime-3-demo/>python.app/Contents/MacOS/python "$@"

So I had to choose torch.device('cpu'). Also, regarding the --model argument, standard_float, separable_float worked, but standard_half, separable_half did not work with the following error.

/python3.8/site-packages/torch/nn/modules/conv.py", line 459, in _conv_forward return F.conv2d(input, weight, bias, self.stride, RuntimeError: "slow_conv2d_cpu" not implemented for 'Half'

I've also encountered other programs using pytorch, but half (float16?) doesn't seem to work on M1Mac for now.

Anyway, the fix above worked. Of course, the speed is slow because the CPU is specified as the device, but I feel there is a lot of potential. Thank you for publishing such a wonderful project!

Translated from Japanese to English by Google. Thank you for reading my poor English!

dragonmeteor commented 1 year ago

Thank you for your comment. I'll leave the thread here for others who might want to run this on a Mac.

shisaq commented 1 year ago

I found the solution, you should install the preview(nightly) version of pyTorch:

$ conda install pytorch torchvision torchaudio -c pytorch-nightly

Then simply change cuda into mps here:

https://github.com/pkhungurn/talking-head-anime-3-demo/blob/8946939ec7b417f443d7b0e3fcd97384313fcdb8/tha3/app/ifacialmocap_puppeteer.py#L423

When using cpu version, the fps was only 1; after using mps version, it increases to about 10 fps, which is more like an animation.

wanaincode commented 1 year ago

Thanks for the thread. I installed it successfully on my M1 MAC. Just a friendly reminder that don't forget to change python into pythonw while executing > python tha3/app/manual_poser.py or other python command

Shaikhyunus7039 commented 1 year ago

Thanks for the thread. I installed it successfully on my M1 MAC. Just a friendly reminder that don't forget to change python into pythonw while executing > python tha3/app/manual_poser.py or other python command

is it possible to run it in windows using cpu ? pls reply