Git Product home page Git Product logo

srmaster's Introduction

SR大师

image_20230614182142

本项目的主要内容是把AI超分辨率模型转化成移动端模型,然后部署到Android端实现本地的图片超分辨率功能,在这个过程中探索出相对简单易用、高效可靠的部署方案,给不精通于Android开发的AI研究人员提供一些参考。

目前,超分辨率模型采用Real-ESRGAN,移动端模型后端已实现Pytorch Mobile、ONNX Runtime。

模型算法请移步 Real-ESRGAN ,由于我并非专业AI研究人员,因此只对其模型结构部分有所阅读了解。

模型转换请参考 Pytorch Mobile 文档和 ONNX Runtime 文档,在此不再赘述。

软件说明

主要功能

选取: 选择要增强的图片。建议100万(=长x宽)像素以下的图片,否则默认会先压缩到100万像素以下再增强,可在设置中修改。

运行: 开始增强图片。请等待一段时间,速度取决于手机性能和图片复杂度,效果取决于图片细节留存度。

保存: 保存增强后的图片。储存在“根目录/Pictures/SRMaster”文件夹。

菜单: 设置更改一些选项。左上角的按钮。

对比: 切换预览增强前后的图片。右上角第二颗按钮。

设备要求

Android 9.0,CPU arm64-v8a(64位)

之前是支持Android 5.0,CPU armeabi-v7a(32位)的,但是实际上过于老旧的设备运行计算量如此大的超分辨率模型非常吃力,且统计发现用户中Android 9.0以下的设备非常少,因此不再适配。

若你有适配需求,可以直接在你的项目中改动minSdk和abiFilters,然后在历史提交中找到FileUtil.kt中对Android 9.0以下图片bitmap读写的代码,使用到你的项目中。

功能计划

  • 模型管理功能
  • NCNN后端

技术说明

过程中一些容易出现问题的点在这里进行提醒。

1.Real-ESRGAN的模型结构

有RRDBNet和SRVGGNetCompact两种,请注意对应版本。

image-20230614172841375

2.Pytorch Mobile库的混淆规则

在正式打包APP设置minifyEnabled=true时,请添加 -keep class org.pytorch.** {*;} -keep class com.facebook.** {*;} 到proguard-rules.pro,否则R8将会压缩混淆掉库方法,APP运行会报错ClassNotFoundException。

image-20230614173126045

3.ONNX Runtime的OrtEnvironment

在使用ONNX Runtime的库方法时,请一定在之前调用 OrtEnvironment.getEnvironment() 初始化,否则调用不了库里的方法,报错UnsatisfiedLinkError。

YES ===>

image-20230614174155993

NO ===>

image-20230614174447321

image-20230614174858726

srmaster's People

Contributors

coo1m avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kksyw coolmalf

srmaster's Issues

pth 转换到pt

观察到pytorch mobile 使用的是.pt文件的模型格式。

请问,模型转换的地方是如何操作的呢?

我使用的代码如下:

import torch
import torch.utils.data.distributed

# pytorch环境中
model_pth = 'realesr-general-x4v3.pth'  # 模型的参数文件
mobile_pt = 'realesr-general-x4v3.pt'  # 将模型保存为Android可以调用的文件

model = torch.load(model_pth, map_location=torch.device('cpu'))
model.eval()  # 模型设为评估模式
device = torch.device('cpu')
model.to(device)
# 1张3通道224*224的图片
input_tensor = torch.rand(1, 3, 224, 224)  # 设定输入数据格式

mobile = torch.jit.trace(model, input_tensor)  # 模型转化
mobile.save(mobile_pt)  # 保存文件

但是始终报错:AttributeError: 'dict' object has no attribute 'eval'

Provide tensorflow lite version

Hello,

Thank you for your effort to create sample app to this super resolution model.
Could you provide a TFlite version for it model.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.