• 【深度学习】python调用超分Real-ESRGAN


    Real-ESRGAN是超分自然场景图和动漫图,视频也可以,项目地址:https://github.com/xinntao/Real-ESRGAN/tree/master

    安装python包:

    basicsr>=1.4.2
    facexlib>=0.2.5
    gfpgan>=1.3.5
    numpy
    opencv-python
    Pillow
    torch>=1.7
    torchvision
    tqdm
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    然后安装:

    pip install realesrgan gfpgan
    
    • 1

    可以在CLI终端直接用:

    Usage: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile -o outfile [options]...
    
    A common command: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile --outscale 3.5 --face_enhance
    
      -h                   show this help
      -i --input           Input image or folder. Default: inputs
      -o --output          Output folder. Default: results
      -n --model_name      Model name. Default: RealESRGAN_x4plus
      -s, --outscale       The final upsampling scale of the image. Default: 4
      --suffix             Suffix of the restored image. Default: out
      -t, --tile           Tile size, 0 for no tile during testing. Default: 0
      --face_enhance       Whether to use GFPGAN to enhance face. Default: False
      --fp32               Use fp32 precision during inference. Default: fp16 (half precision).
      --ext                Image extension. Options: auto | jpg | png, auto means using the same extension as inputs. Default: auto
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    可以写python脚本调用:

    import time
    
    import cv2
    from basicsr.archs.rrdbnet_arch import RRDBNet
    from realesrgan import RealESRGANer
    
    if __name__ == '__main__':
        outscale = 1.5
        # RealESRGAN_x2plus
        model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
        netscale = 2
        # RealESRNet_x4plus
        # model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
        # netscale = 4
        model_path = 'weights/RealESRGAN_x2plus.pth'
    
        # restorer
        upsampler = RealESRGANer(
            scale=netscale,
            model_path=model_path,
            dni_weight=1,  # RealESRGAN_x2plus不需要这个参数
            model=model,
            tile=0,
            tile_pad=10,
            pre_pad=0,
            half=True,  # 半精度计算
            gpu_id=0)
    
        img = cv2.imread("./demo.jpg", cv2.IMREAD_COLOR)
        print(img.shape)
    
        start_time = time.time()
        try:
            output, _ = upsampler.enhance(img, outscale=outscale)
        except RuntimeError as error:
            print('Error', error)
            print('If you encounter CUDA out of memory, try to set --tile with a smaller number.')
        print("time:", time.time() - start_time)
        print(output.shape)
        cv2.imwrite("./demo2.jpg", output)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41

    脚本是参考这个文件写的:
    https://github.com/xinntao/Real-ESRGAN/blob/master/inference_realesrgan.py

    在这里插入图片描述

    其他介绍

    AnimeVideo-v3模型是一个专注于动漫视频处理的小型模型。该模型的目标是通过实际算法实现对图像和视频的高效恢复。具体来说,它是Real-ESRGAN项目的一部分,Real-ESRGAN致力于开发通用图像/视频修复的实用算法。

    Real-ESRGAN_x4plus_anime_6B是专门为动漫图像设计的插图模型。这个模型使用Real-ESRGAN框架,通过在纯合成数据上进行训练,实现对动漫图像的高倍超分辨率恢复。该模型的设计目的是提供对动漫插图的强大恢复能力。

    项目提供了在线演示和Colab演示,方便用户在不同平台上体验Real-ESRGAN的功能。同时,还提供了适用于Intel/AMD/Nvidia GPU的可移植的Windows/Linux/MacOS可执行文件,使用户能够在本地环境中运行该模型。

    Real-ESRGAN项目的核心理念是通过将ESRGAN(Enhanced Super-Resolution Generative Adversarial Network)技术扩展到实际的图像/视频修复应用中。ESRGAN是一种强大的图像超分辨率算法,Real-ESRGAN通过在纯合成数据上进行训练,使其更适用于实际应用场景。

    项目作者感谢用户提供的宝贵反馈和建议,并将所有反馈整理在feedback.md文件中,以不断改进模型的性能和功能。

    除了Real-ESRGAN,项目还推荐了其他相关项目,如GFPGAN(用于实际人脸修复的算法)、BasicSR(开源的图像和视频修复工具箱)、facexlib(提供有用的面部相关功能的集合)、HandyView(基于PyQt5的图像查看器)、HandyFigure(论文图形的开源项目)等,为用户提供了更多的选择和工具。

  • 相关阅读:
    浅学Go下的ssti漏洞问题
    .net餐厅管理系统数据层餐厅服务类修改、查询菜品信息
    数据库读写分离和分库分表
    js高级:函数
    聊一聊redis奇葩数据类型与集群知识
    COCO数据集中图像的caption读取到txt文件
    张高兴的 Entity Framework Core 即学即用:(一)创建第一个 EF Core 应用
    SAP MM 事务代码VL04为STO创建外向交货单
    什么是内存泄漏?JavaScript 垃圾回收机制原理及方式有哪些?哪些操作会造成内存泄漏?
    SpringBoot 场景开发多面手成长手册
  • 原文地址:https://blog.csdn.net/x1131230123/article/details/134527235