python使用NVlabs/stylegan3生成图片和视频

此项目只能随机生成图片,不能以图生图

先把源码克隆到本地,https://github.com/NVlabs/stylegan3

进入项目文件夹,激活虚拟环境

conda env create -f environment.yml
conda activate stylegan3

访问https://pytorch.org/get-started/locally/,根据自己的环境选择

在虚拟环境执行

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

生成图片,用官方的模型

# Generate an image using pre-trained AFHQv2 model ("Ours" in Figure 1, left).
python gen_images.py --outdir=out --trunc=1 --seeds=2 --network=https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-r-afhqv2-512x512.pkl

生成视频,用官方的模型,这个电脑不行的话,会有点慢,我的电脑跑了1h。。。

# Render a 4x2 grid of interpolations for seeds 0 through 31.
python gen_video.py --output=lerp.mp4 --trunc=1 --seeds=0-31 --grid=4x2 --network=https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-r-afhqv2-512x512.pkl

结果


若生成视频报错

OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause inco

去创建的虚拟环境下 anaconda/envs/env_name/Library/bin 的 libiomp5md.dll 文件删除,再跑代码就没问题了

posted @ 2024-04-15 10:26  朝阳1  阅读(146)  评论(0编辑  收藏  举报