🍉 移动端TNN部署学习笔记,支持Android与iOS。

Overview

🚀 如果有帮助,点个star!

移动端TNN部署,摄像头实时捕获视频流进行检测。

iOS:

  • Xcode 11.5
  • macOS 10.15.4
  • iPhone 6sp 13.5.1

Android:

  • Android Studio 4.1.1
  • Win10 20H2
  • Meizu 16x 8.1.0 (CPU:Qualcomm 710 GPU:Adreno 616)

安卓已经增加权限申请,但如果还是闪退请手动确认下相关权限是否允许。

Android

从界面中选择需要测试的模型。

iOS

从界面中选择需要测试的模型。

模型

model android iOS from
YOLOv5s yes yes Github

iOS:

  • 如果缺少模型请从 "android_TNN_Demo\app\src\main\assets" 复制 .tnnproto 和 .tnnmodel 文件到 "iOS_TNN_Demo\TNNDemo\res" 下。
  • iOS如果opencv2.framework有用到也需要重新下载并替换到工程。
  • iOS默认使用的库为scripts/build_ios.sh编译生成。

Android:

  • 由于手机性能、图像尺寸等因素导致FPS在不同手机上相差比较大。该项目主要测试TNN框架的使用,具体模型的转换可以去TNN官方查看转换教程。
  • 由于opencv库太大只保留 arm64-v8a/armeabi-v7a 有需要其它版本的自己去官方下载。
  • AS版本不一样可能编译会有各种问题,如果编译错误无法解决、建议使用AS4.0以上版本尝试一下。

懒人本地转换(不会上传模型): [xxxx -> tnn] https://convertmodel.com/

🎨 截图

Android

YOLOv5s

iOS

YOLOv5s

感谢:

Comments
  • input_cvt_param.scale and bias

    input_cvt_param.scale and bias

    input_cvt_param.scale = {1.0 / 255, 1.0 / 255, 1.0 / 255, 0.0}; input_cvt_param.bias = {0.0, 0.0, 0.0, 0.0}; why scale is 1/255 ,and the last is 0.0? bias is ?

    opened by henbucuoshanghai 15
  • 关于检测类别问题

    关于检测类别问题

    @cmdbug

    大神,我的模型可以正常运行 ,但是检测的类别依然按照coco类别显示的,类别索引是对的,我把label数组改成自己的了,但是依然显示的是coco的label。

    # yolov5.h文件
        std::vector<std::string> labels{"prohibitory", "warning", "mandatory"};
    private:
        std::shared_ptr<tnn::TNN> net;
        std::shared_ptr<TNN_NS::Instance> instance;
        TNN_NS::DeviceType device_type;
    
        int net_width = 640;
        int net_height = 640;
        int num_class = 3;
    

    比如,索引号检测是0,应该显示prohibitory,结果显示的是coco中的person,求大神解答一下

    opened by Zengyf-CVer 3
  • Details about Yolov5

    Details about Yolov5

    Hi. I am running your demo and feel confused about your YOLOv5 demo.

    There is a "layers" parameter in the Yolov5.h: https://github.com/cmdbug/TNN_Demo/blob/f361ba092924902854f336784f7b8fb9bfd21347/iOS_TNN_Demo/TNNDemo/Yolov5.h#L87 std::vector layers{ {"output", 32, {{116, 90}, {156, 198}, {373, 326}}}, {"413", 16, {{30, 61}, {62, 45}, {59, 119}}}, {"431", 8, {{10, 13}, {16, 30}, {33, 23}}}, };

    I wonder what's the meanings of these values?

    opened by NoLookDefense 4
  • Error when deploying nanodet

    Error when deploying nanodet

    Hello. I trained a nanodet model from https://github.com/RangiLyu/nanodet, and an error occurred to me when processing auto status = NanoDet::instance->GetCommandQueue(&command_queue); :

    2021-10-03 22:27:42.800142+0800 TNNDemo[7059:1059735] new NanoDet E/tnn: virtual tnn::Status tnn::DefaultNetwork::InitLayers(tnn::NetStructure *, tnn::NetResource *) [File /Users/TURUI/Desktop/TNN/source/tnn/core/default_network.cc][Line 236] Error Init layer Conv_0 (err: 4096 or 0x1000) 2021-10-03 22:27:42.839470+0800 TNNDemo[7059:1059735] GPU initialization failed, switch to CPU E/tnn: virtual tnn::Status tnn::DefaultNetwork::InitLayers(tnn::NetStructure *, tnn::NetResource *) [File /Users/TURUI/Desktop/TNN/source/tnn/core/default_network.cc][Line 236] Error Init layer Conv_0 (err: 4096 or 0x1000) 2021-10-03 22:27:42.845144+0800 TNNDemo[7059:1059735] TNN init failed 4096 (lldb)

    It seems that the error is caused by initialization. Do you have any ideas to fix it?

    opened by CheungBH 5
  • yolov5s v5.0模型转换TNN后运行出错

    yolov5s v5.0模型转换TNN后运行出错

    使用的模型:https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt 转换onnx命令:python models/export.py --weights yolov5s.pt --img 640 --batch 1 转换TNN命令:python converter.py onnx2tnn yolov5s.onnx -o . -in 1,3,448,640 转换后的模型:https://www.lanzoui.com/iSktTqkfote 运行demo时报错: image

    opened by winterfell2021 1
Owner
teng
Good Good Study,Day Day Up。
teng
🥭 移动端MNN部署学习笔记。支持Android与iOS。

?? 移动端MNN部署学习笔记。支持Android与iOS。

teng 62 Oct 8, 2022