Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possbile to porting to Android phone? #6

Open
mychina75 opened this issue Jun 16, 2020 · 9 comments
Open

Is it possbile to porting to Android phone? #6

mychina75 opened this issue Jun 16, 2020 · 9 comments

Comments

@mychina75
Copy link

Thx.

@nihui
Copy link
Owner

nihui commented Jun 16, 2020

@mychina75
Copy link
Author

啥时间更新预编译的ncnn-android-vulkan-lib?
想在手机上跑跑超分的模型,APK里面。
不过好像需要下面的几个库...
ncnn-android-vulkan-lib/${ANDROID_ABI}/libglslang.a
ncnn-android-vulkan-lib/${ANDROID_ABI}/libOGLCompiler.a
ncnn-android-vulkan-lib/${ANDROID_ABI}/libOSDependent.a
ncnn-android-vulkan-lib/${ANDROID_ABI}/libSPIRV.a)

@nihui
Copy link
Owner

nihui commented Jun 16, 2020

@mychina75
Copy link
Author

多谢大神!

@mychina75
Copy link
Author

mychina75 commented Jun 17, 2020

@nihui 帮忙看看是啥问题吧。
在手机上跑了下,512x512的输入
模型load需要2s多,process时间6s多。输出的结果也不太对,保存的图是黑的...
如果用原图尺寸的话,3xxx X 2xxx跑一下时间更久,要几十秒

大概的调用是这样的:
// ncnn from bitmap
ncnn::Mat in = ncnn::Mat::from_android_bitmap_resize(env, bitmap, ncnn::Mat::PIXEL_BGR2RGB,512,512);
int c = 3;
ncnn::Mat out = ncnn::Mat(512 * scale, 512 * scale, (size_t)c, c);
BSTLOGE("before proc out width = %d, height = %d", out.w, out.h);

srmd.process(in, out);
BSTLOGE("out width = %d, height = %d", out.w, out.h);

// ncnn to bitmap
out.to_android_bitmap(env, outBitmap, ncnn::Mat::PIXEL_RGB);

我是在linux上面编译通了这套代码,生成好些*_int8s.spv.hex.h,*_fp16s.spv.hex.h的头文件,然后把这些头文件放在Android工程里面。会不会这些头文件与运行环境有关,在手机上需要专门生成一下?

@nihui
Copy link
Owner

nihui commented Jun 17, 2020

tilesize太大了?

@mychina75
Copy link
Author

这段代码获取的heap_budget是一千多, tilesize就设成了200;

if (tilesize == 0)
{
uint32_t heap_budget = ncnn::get_gpu_device(gpuid)->get_heap_budget();

    // more fine-grained tilesize policy here
    if (model.find(PATHSTR("models-srmd")) != path_t::npos)
    {
        if (heap_budget > 2600)
            tilesize = 400;
        else if (heap_budget > 740)
            tilesize = 200;
        else if (heap_budget > 250)
            tilesize = 100;
        else
            tilesize = 32;
    }
}

@bananaCaptain
Copy link

@mychina75 请问能移植到android不?

@mychina75
Copy link
Author

不太行...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants