github链接:https://github.com/zhanghang1989/PyTorch-Multi-Style-Transfer

1、配置环境

复制代码
conda create -n PyTorch-Style-Transfer python=3.8 conda acivate PyTorch-Style-Transfer pip instll torch-1.11.0+cu113-cp38-cp38-win_amd64.whl pip install opencv-python pip install pillow

出现的问题

复制代码
ModuleNotFoundError: No module named ‘torch.utils.serialization’ 的解决方案 产生原因:pycharm版本比较新 解决方案:1.换一个版本旧的pycharm 2.1安装torchfile 我们使用清华的镜像 pip install torchfile -i https://pypi.tuna.tsinghua.edu.cn/simple 2.2将from torch.utils.serialization import load_lua改为import torchfile 2.3将load_lua改为torchfile.load 3.如果code中没有load_lua,我们就把from torch.utils.serialization import load_lua改为import torchfile即可,无需操作第三步

2、运行

启动摄像头

复制代码
python camera_demo.py demo --model models/21styles.model

测试图片效果

复制代码
python main.py eval --content-image images/content/venice-boat.jpg --style-image images/21styles/candy.jpg --model models/21styles.model --content-size 1024
  • If you don’t have a GPU, simply set --cuda=0. For a different style, set --style-image path/to/style. If you would to stylize your own photo, change the --content-image path/to/your/photo. More options:
    • --content-image: path to content image you want to stylize.
    • --style-image: path to style image (typically covered during the training).
    • --model: path to the pre-trained model to be used for stylizing the image.
    • --output-image: path for saving the output image.
    • --content-size: the content image size to test on.
    • --cuda: set it to 1 for running on GPU, 0 for CPU.