效果展示

本周已解锁无限场景风格与固定人物的融合,先看效果:

 

以上风格LoRA分别为:户外花园婚纱、冬季雪景汉服、火焰女神、仙侠风

 

 

环境准备

在魔搭平台https://modelscope.cn/my/mynotebook/preset中选择PAI-DSW-GPU环境

 

进入后打开terminal环境,先检查显存需要20G左右(nvidia-smi),然后下载核心文件。

GIT_LFS_SKIP_SMUDGE=1 git clone https://github.com/modelscope/facechain.git

以下进入正题

 

固定人物LoRA训练

 

1、在facechain文件夹下新建文件夹 imgs,将需要训练的人脸照片放入该文件夹

2、人物LoRA训练

然后在terminal中运行以下代码启动训练

PYTHONPATH=. CUDA_VISIBLE_DEVICES="0" sh train_lora.sh "ly261666/cv_portrait_model" "v2.0" "film/film" "./imgs" "./processed" "./output"

 

风格LoRA替换

 

1、上传风格LoRA文件并修改参数

 

风格来源:https://www.liblibai.com/modelinfo/dcf7498c994b4ffc8f1c61aec06dcc62,主要迁移其户外花团锦簇风格,重新取名wedding

 

2、修改constants.py文件

主要修改文件名为新上传的风格文件,并在prompt增加wedding dress相关内容。

 

    
    styles = [
        {'name': '默认风格(default style)'},
        {'name': '凤冠霞帔(Chinese traditional gorgeous suit)',
         'model_id': 'ly261666/civitai_xiapei_lora',
         'revision': 'v1.0.0',
         'bin_file': 'xiapei.safetensors',
         'multiplier_style': 0.35,
         'cloth_name': '汉服风(hanfu)',
         'add_prompt_style': 'red, hanfu, tiara, crown, '},
        {'name': '婚纱(wedding)',
         'model_id': 'ly261666/civitai_xiapei_lora',
         'revision': 'v1.0.0',
         'bin_file': 'wedding.safetensors',
         'multiplier_style': 0.35,
         'cloth_name': '婚纱(wedding)',
         'add_prompt_style': 'bride wearing a white wedding dress,simple and elegant style, <lora:outdoor photo_20230819231754:0.6> --ar 3:4'},
    ]

     

    3、修改run_inference.py关键参数

    修改风格文件夹路径,use_style改为true,顺序编号顺延为2

    
    use_main_model = True
    use_face_swap = True
    use_post_process = True # 可改为False则不控制数量
    use_stylization = False
    processed_dir = './processed'
    num_generate = 5
    base_model = 'ly261666/cv_portrait_model'
    revision = 'v2.0'
    multiplier_style = 0.25
    base_model_sub_dir = 'film/film'
    train_output_dir = './output'
    output_dir = './generated'
    use_style = True
    
    if not use_style:
        style_model_path = None
        pos_prompt = generate_pos_prompt(styles[0]['name'], cloth_prompt[0]['prompt'])
    else:
        model_dir =  '/mnt/workspace/wedding'
        style_model_path = os.path.join(model_dir, styles[2]['bin_file'])
        pos_prompt = generate_pos_prompt(styles[2]['name'], styles[2]['add_prompt_style'])  # style has its own prompt
    
    gen_portrait = GenPortrait(pos_prompt, neg_prompt, style_model_path, multiplier_style, use_main_model,
                               use_face_swap, use_post_process,
                               use_stylization)
    
    outputs = gen_portrait(processed_dir, num_generate, base_model,
                           train_output_dir, base_model_sub_dir, revision)
    
    os.makedirs(output_dir, exist_ok=True)
    
    for i, out_tmp in enumerate(outputs):
        cv2.imwrite(os.path.join(output_dir, f'{i}.png'), out_tmp)
     

    LoRA融合后推理出图

    直接在terminal中运行:

    export CUDA_VISIBLE_DEVICES=0
    python run_inference.py

     

    固定人脸+迁移的户外花团锦簇风格+prompt控制的婚纱=婚纱户外写真

     

    附录

    1、项目地址:

    GitHub:https://github.com/modelscope/facechain(觉得有用的话记得点Star~)

     

    魔搭平台创空间体验:https://modelscope.cn/studios/CVstudio/cv_human_portrait/summary

     

    HuggingFace Space:https://huggingface.co/spaces/modelscope/FaceChain

     

    2、原理讲解图文及视频讲解

    图文版:3张照片打造专属形象!酷蛙FaceChain解密个人写真开源项目,人人AIGC!

     

    4分钟视频讲解版:

    https://developer.aliyun.com/live/252611?spm=a2c6h.13262185.profile.156.5186349clYRXxx

     

    3、上期周报

    酷蛙FaceChain开源项目迭代周记2023-08-19

     

    4、全球开发者招募

    酷蛙FaceChain项目计划后续联合社区的力量不断打磨该开源项目,解锁更多高阶玩法(比如人物表情包、人物连环画故事、虚拟试衣间……),并进行更深层次的算法创新,发表相应顶会论文。如果你对该开源项目感兴趣,对该开源项目的未来有憧憬与信仰,欢迎加入~

    报名链接

    https://www.yuque.com/forms/share/5892d145-99c3-406c-8785-13dcb50353b8

    Logo

    ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单!

    更多推荐