styleGAN环境搭建 、 动漫模型效果测试


📙 声明:

本博文的主体内容借鉴该博文:

  • https://blog.csdn.net/weixin_41943311/article/details/100539707

我主要做的工作是精简流程和测试记录,想了解更多内容可以关注 https://blog.csdn.net/weixin_41943311 博客主页下的一系列 styleGAN 相关操作;

  • 感谢 闪闪·Style 博主所做工作;

📙 styleGAN环境搭建 | 动漫模型效果测试流程简记如下:


环境搭建:


服务器:ubuntu1~18.04 Quadro RTX 5000 16G (做测试11G的卡可以胜任)
CUDA版本 V10.0.130

conda create -n tf15 python=3.6.6

conda activate tf15

pip install tensorflow-gpu==1.15 (1.15 测试时会有一些 WARNING,不影响测试)
或者 
pip install tensorflow-gpu==1.13

pip install pillow

pip install requests



📙 动漫模型效果测试开启:


所使用代码: GitHub styleGAN 官方实现

styleGAN论文: A Style-Based Generator Architecture for Generative Adversarial Networks

项目目录结构如下:

0

模型下载(百度网盘):

已训练好的动漫头像模型(动漫头像为主,512x512)

# 该模型来自 https://blog.csdn.net/weixin_41943311/article/details/100539707 这位博主的发布


链接:https://pan.baidu.com/s/1_N2y1F4BpwsufNK6xOqaig 
提取码:2022

新建 pretrained_example-dongman.py 内容如下:

# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
#
# This work is licensed under the Creative Commons Attribution-NonCommercial
# 4.0 International License. To view a copy of this license, visit
# http://creativecommons.org/licenses/by-nc/4.0/ or send a letter to
# Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
 
"""Minimal script for generating an image using pre-trained StyleGAN generator."""
 
import os
import pickle
import numpy as np
import PIL.Image
import dnnlib
import dnnlib.tflib as tflib
import config
import glob
import random

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "3"

PREFIX = 'Anime'
#PREFIX = 'Animation'
 
TIMES_LOOP = 100
 
def main():
    # Initialize TensorFlow.
    tflib.init_tf()
 
    # Load pre-trained network.

    Model = 'cache/2019-03-08-stylegan-animefaces-network-02051-021980.pkl'
    
    model_file = glob.glob(Model)
    if len(model_file) == 1:
        model_file = open(model_file[0], "rb")
    else:
        raise Exception('Failed to find the model')
 
    _G, _D, Gs = pickle.load(model_file)
    # _G = Instantaneous snapshot of the generator. Mainly useful for resuming a previous training run.
    # _D = Instantaneous snapshot of the discriminator. Mainly useful for resuming a previous training run.
    # Gs = Long-term average of the generator. Yields higher-quality results than the instantaneous snapshot.
 
    # Print network details.
    Gs.print_layers()
 
    for i in range(TIMES_LOOP):
        # Pick latent vector.
        SEED = random.randint(0, 18000)
        rnd = np.random.RandomState(SEED)
        latents = rnd.randn(1, Gs.input_shape[1])
 
         # Generate image.
        fmt = dict(func=tflib.convert_images_to_uint8, nchw_to_nhwc=True)
        images = Gs.run(latents, None, truncation_psi=0.7, randomize_noise=True, output_transform=fmt)
 
         # Generate and Save image.
        os.makedirs(config.result_dir, exist_ok=True)
        save_name = PREFIX + '_' + str(random.getrandbits(64)) + '.png'
        save_path = os.path.join(config.result_dir, save_name)
        PIL.Image.fromarray(images[0], 'RGB').save(save_path)
 
if __name__ == "__main__":
    main()

测试运行命令如下:

python pretrained_example-dongman.py 

注意事项:

一定要设置使用的卡,不然它默认会使用所有卡,把其他卡的程序干掉了(难受):
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "1"

单卡 GPU占用
8271MiB

生成的动漫女生头像如下:
1


📙 备注:


再次感谢各位大佬闪闪·Style 博主所做工作;


📙 博主 AI 领域八大干货专栏、诚不我欺



📙 预祝各位 2022 前途似锦、可摘星辰


  • 🎉 作为全网 AI 领域 干货最多的博主之一,❤️ 不负光阴不负卿 ❤️
  • ❤️ 如果文章对你有帮助、点赞、评论鼓励博主的每一分认真创作

❤️ 比寻找温暖更重要的是,让自己成为一盏灯火 ❤️

0-9

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

墨理学AI

不必打赏,关注博主公众号即可

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值