{"id":27013574,"url":"https://github.com/xlite-dev/ssrnet-toolkit","last_synced_at":"2025-06-12T03:16:52.109Z","repository":{"id":103962010,"uuid":"447654102","full_name":"xlite-dev/ssrnet-toolkit","owner":"xlite-dev","description":"🍅🍅 SSRNet: 190 Kb!! Super fast Age Estimation with MNN/TNN/ONNXRuntime C++. ","archived":false,"fork":false,"pushed_at":"2022-02-04T11:28:15.000Z","size":16903,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-04T12:51:15.623Z","etag":null,"topics":["ssrnet"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xlite-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-13T15:38:05.000Z","updated_at":"2025-03-29T10:24:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"1b289668-7965-491c-bac1-ecc25827bce5","html_url":"https://github.com/xlite-dev/ssrnet-toolkit","commit_stats":null,"previous_names":["xlite-dev/ssrnet-toolkit"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xlite-dev/ssrnet-toolkit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlite-dev%2Fssrnet-toolkit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlite-dev%2Fssrnet-toolkit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlite-dev%2Fssrnet-toolkit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlite-dev%2Fssrnet-toolkit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xlite-dev","download_url":"https://codeload.github.com/xlite-dev/ssrnet-toolkit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlite-dev%2Fssrnet-toolkit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259388340,"owners_count":22849770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ssrnet"],"created_at":"2025-04-04T12:40:47.127Z","updated_at":"2025-06-12T03:16:52.058Z","avatar_url":"https://github.com/xlite-dev.png","language":"C++","readme":"# ssrnet.lite.ai.toolkit\n使用 [🍅🍅 Lite.AI.ToolKit](https://github.com/DefTruth/lite.ai.toolkit) C++工具箱来跑SSRNet年龄估计的一些案例, 包含ONNXRuntime C++、MNN和TNN版本。SSRNet的权重文件大小只有 **190Kb** ，是一个非常轻量级的年龄估计模型。\n\n\u003cdiv align='center'\u003e\n  \u003cimg src='resources/2_onnx.jpg' height=\"224px\" width=\"224px\"\u003e\n  \u003cimg src='resources/3_mnn.jpg' height=\"224px\" width=\"224px\"\u003e\n  \u003cimg src='resources/4_tnn.jpg' height=\"224px\" width=\"224px\"\u003e\n\u003c/div\u003e  \n\n\n如果觉得有用，不妨给个Star⭐️🌟支持一下吧~ 🙃🤪🍀\n\n## 2. C++版本源码\n\nSSRNet C++ 版本的源码包含ONNXRuntime、MNN和TNN三个版本，源码可以在 [lite.ai.toolkit](https://github.com/DefTruth/lite.ai.toolkit) 工具箱中找到。本项目主要介绍如何基于 [lite.ai.toolkit](https://github.com/DefTruth/lite.ai.toolkit) 工具箱，直接使用SSRNet来跑人脸检测。需要说明的是，本项目是基于MacOS下编译的 [liblite.ai.toolkit.v0.1.0.dylib](https://github.com/DefTruth/yolox.lite.ai.toolkit/blob/main/lite.ai.toolkit/lib) 来实现的，对于使用MacOS的用户，可以直接下载本项目包含的*liblite.ai.toolkit.v0.1.0*动态库和其他依赖库进行使用。而非MacOS用户，则需要从[lite.ai.toolkit](https://github.com/DefTruth/lite.ai.toolkit) 中下载源码进行编译。[lite.ai.toolkit](https://github.com/DefTruth/lite.ai.toolkit) c++工具箱目前包含80+流行的开源模型，就不多介绍了，只是平时顺手捏的，整合了自己学习过程中接触到的一些模型，感兴趣的同学可以去看看。\n* [ssrnet.cpp](https://github.com/DefTruth/lite.ai.toolkit/blob/main/lite/ort/cv/ssrnet.cpp)\n* [ssrnet.h](https://github.com/DefTruth/lite.ai.toolkit/blob/main/lite/ort/cv/ssrnet.h)\n* [mnn_ssrnet.cpp](https://github.com/DefTruth/lite.ai.toolkit/blob/main/lite/mnn/cv/mnn_ssrnet.cpp)\n* [mnn_ssrnet.h](https://github.com/DefTruth/lite.ai.toolkit/blob/main/lite/mnn/cv/mnn_ssrnet.h)\n* [tnn_ssrnet.cpp](https://github.com/DefTruth/lite.ai.toolkit/blob/main/lite/tnn/cv/tnn_ssrnet.cpp)\n* [tnn_ssrnet.h](https://github.com/DefTruth/lite.ai.toolkit/blob/main/lite/tnn/cv/tnn_ssrnet.h)\n\nONNXRuntime C++、MNN和TNN版本的推理实现均已测试通过，欢迎白嫖~  \n\n## 3. 模型文件\n\n### 3.1 ONNX模型文件\n可以从我提供的链接下载 ([Baidu Drive](https://pan.baidu.com/s/1elUGcx7CZkkjEoYhTMwTRQ) code: 8gin) , 也可以从本直接仓库下载。\n\n\n|                 Class                 |      Pretrained ONNX Files      |              Rename or Converted From (Repo)              | Size  |\n| :-----------------------------------: | :-----------------------------: | :-------------------------------------------------------: | :---: |  \n|     *lite::cv::face::attr::SSRNet*      |               ssrnet.onnx                | [SSR_Net...](https://github.com/oukohou/SSR_Net_Pytorch) | 190Kb |\n\n\n### 3.2 MNN模型文件\nMNN模型文件下载地址，([Baidu Drive](https://pan.baidu.com/s/1KyO-bCYUv6qPq2M8BH_Okg) code: 9v63), 也可以从本直接仓库下载。\n\n|                 Class                 |      Pretrained MNN Files      |              Rename or Converted From (Repo)              | Size  |\n| :-----------------------------------: | :-----------------------------: | :-------------------------------------------------------: | :---: |\n|     *lite::mnn::cv::face::attr::SSRNet*      |               ssrnet.mnn                | [SSR_Net...](https://github.com/oukohou/SSR_Net_Pytorch) | 190Kb |\n\n### 3.3 TNN模型文件\nTNN模型文件下载地址，([Baidu Drive](https://pan.baidu.com/s/1lvM2YKyUbEc5HKVtqITpcw) code: 6o6k), 也可以从本直接仓库下载。\n\n|                 Class                 |      Pretrained TNN Files      |              Rename or Converted From (Repo)              | Size  |\n| :-----------------------------------: | :-----------------------------: | :-------------------------------------------------------: | :---: |\n|     *lite::tnn::cv::face::attr::SSRNet*      |               ssrnet.opt.tnnproto\u0026tnnmodel                | [SSR_Net...](https://github.com/oukohou/SSR_Net_Pytorch) | 190Kb |\n\n\n## 4. 接口文档\n\n在[lite.ai.toolkit](https://github.com/DefTruth/lite.ai.toolkit) 中，SSRNet的实现类为：\n\n```c++\nclass LITE_EXPORTS lite::cv::face::attr::SSRNet;\nclass LITE_EXPORTS lite::mnn::cv::face::attr::SSRNet;\nclass LITE_EXPORTS lite::tnn::cv::face::attr::SSRNet;\n```  \n\n该类型目前包含1公共接口`detect`用于进行年龄检测。\n```c++\npublic:\n  void detect(const cv::Mat \u0026mat, types::Age \u0026age);\n```\n`detect`接口的输入参数说明：\n* mat: cv::Mat类型，BGR格式，一张包含人脸头部的图片（不包含过多的背景）。\n* age: types::Age，包含被检测到的年龄; \n\n## 5. 使用案例\n\n### 5.1 ONNXRuntime版本\n```c++\n#include \"lite/lite.h\"\n\nstatic void test_default()\n{\n    std::string onnx_path = \"../hub/onnx/cv/ssrnet.onnx\";\n    std::string test_img_path = \"../resources/1.png\";\n    std::string save_img_path = \"../logs/1.jpg\";\n    \n    auto *ssrnet = new lite::cv::face::attr::SSRNet(onnx_path);\n    \n    lite::types::Age age;\n    cv::Mat img_bgr = cv::imread(test_img_path);\n    ssrnet-\u003edetect(img_bgr, age);\n    \n    lite::utils::draw_age_inplace(img_bgr, age);\n    \n    cv::imwrite(save_img_path, img_bgr);\n    \n    std::cout \u003c\u003c \"Default Version Done! Detected SSRNet Age: \" \u003c\u003c age.age \u003c\u003c std::endl;\n    \n    delete ssrnet;\n}\n```  \n\n### 5.2 MNN版本\n```c++\n#include \"lite/lite.h\"\n\nstatic void test_mnn()\n{\n#ifdef ENABLE_MNN\n    std::string mnn_path = \"../hub/mnn/cv/ssrnet.mnn\";\n    std::string test_img_path = \"../resources/3.png\";\n    std::string save_img_path = \"../logs/3_mnn.jpg\";\n    \n    auto *ssrnet = new lite::mnn::cv::face::attr::SSRNet(mnn_path);\n    \n    lite::types::Age age;\n    cv::Mat img_bgr = cv::imread(test_img_path);\n    ssrnet-\u003edetect(img_bgr, age);\n    \n    lite::utils::draw_age_inplace(img_bgr, age);\n    \n    cv::imwrite(save_img_path, img_bgr);\n    \n    std::cout \u003c\u003c \"MNN Version Done! Detected SSRNet Age: \" \u003c\u003c age.age \u003c\u003c std::endl;\n    \n    delete ssrnet;\n#endif\n}\n```  \n\n### 5.3 TNN版本\n```c++\n#include \"lite/lite.h\"\n\nstatic void test_tnn()\n{\n#ifdef ENABLE_TNN\n    std::string proto_path = \"../hub/tnn/cv/ssrnet.opt.tnnproto\";\n    std::string model_path = \"../hub/tnn/cv/ssrnet.opt.tnnmodel\";\n    std::string test_img_path = \"../resources/4.png\";\n    std::string save_img_path = \"../logs/4_tnn.jpg\";\n    \n    auto *ssrnet = new lite::tnn::cv::face::attr::SSRNet(proto_path, model_path);\n    \n    lite::types::Age age;\n    cv::Mat img_bgr = cv::imread(test_img_path);\n    ssrnet-\u003edetect(img_bgr, age);\n    \n    lite::utils::draw_age_inplace(img_bgr, age);\n    \n    cv::imwrite(save_img_path, img_bgr);\n    \n    std::cout \u003c\u003c \"TNN Version Done! Detected SSRNet Age: \" \u003c\u003c age.age \u003c\u003c std::endl;\n    \n    delete ssrnet;\n#endif\n}\n```  \n\n\n* 输出结果为:\n\n\u003cdiv align='center'\u003e\n  \u003cimg src='resources/2_onnx.jpg' height=\"224px\" width=\"224px\"\u003e\n  \u003cimg src='resources/3_mnn.jpg' height=\"224px\" width=\"224px\"\u003e\n  \u003cimg src='resources/4_tnn.jpg' height=\"224px\" width=\"224px\"\u003e\n\u003c/div\u003e  \n\n## 6. 编译运行\n在MacOS下可以直接编译运行本项目，无需下载其他依赖库。其他系统则需要从[lite.ai.toolkit](https://github.com/DefTruth/lite.ai.toolkit) 中下载源码先编译*lite.ai.toolkit.v0.1.0*动态库。\n```shell\ngit clone --depth=1 https://github.com/DefTruth/ssrnet.lite.ai.toolkit.git\ncd ssrnet.lite.ai.toolkit \nsh ./build.sh\n```  \n\n* CMakeLists.txt设置\n\n```cmake\ncmake_minimum_required(VERSION 3.17)\nproject(ssrnet.lite.ai.toolkit)\n\nset(CMAKE_CXX_STANDARD 11)\n\n# setting up lite.ai.toolkit\nset(LITE_AI_DIR ${CMAKE_SOURCE_DIR}/lite.ai.toolkit)\nset(LITE_AI_INCLUDE_DIR ${LITE_AI_DIR}/include)\nset(LITE_AI_LIBRARY_DIR ${LITE_AI_DIR}/lib)\ninclude_directories(${LITE_AI_INCLUDE_DIR})\nlink_directories(${LITE_AI_LIBRARY_DIR})\n\nset(OpenCV_LIBS\n        opencv_highgui\n        opencv_core\n        opencv_imgcodecs\n        opencv_imgproc\n        opencv_video\n        opencv_videoio\n        )\n# add your executable\nset(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/examples/build)\n\nadd_executable(lite_ssrnet examples/test_lite_ssrnet.cpp)\ntarget_link_libraries(lite_ssrnet\n        lite.ai.toolkit\n        onnxruntime\n        MNN  # need, if built lite.ai.toolkit with ENABLE_MNN=ON,  default OFF\n        ncnn # need, if built lite.ai.toolkit with ENABLE_NCNN=ON, default OFF\n        TNN  # need, if built lite.ai.toolkit with ENABLE_TNN=ON,  default OFF\n        ${OpenCV_LIBS})  # link lite.ai.toolkit \u0026 other libs.\n```\n\n* building \u0026\u0026 testing information:\n```shell\n[ 50%] Building CXX object CMakeFiles/lite_ssrnet.dir/examples/test_lite_ssrnet.cpp.o\n[100%] Linking CXX executable lite_ssrnet\n[100%] Built target lite_ssrnet\nTesting Start ...\nLITEORT_DEBUG LogId: ../hub/onnx/cv/ssrnet.onnx\n=============== Input-Dims ==============\ninput_node_dims: 1\ninput_node_dims: 3\ninput_node_dims: 64\ninput_node_dims: 64\n=============== Output-Dims ==============\nOutput: 0 Name: age Dim: 0 :1\n========================================\nDefault Version Done! Detected SSRNet Age: 35.567\nLITEORT_DEBUG LogId: ../hub/onnx/cv/ssrnet.onnx\n=============== Input-Dims ==============\ninput_node_dims: 1\ninput_node_dims: 3\ninput_node_dims: 64\ninput_node_dims: 64\n=============== Output-Dims ==============\nOutput: 0 Name: age Dim: 0 :1\n========================================\nONNXRuntime Version Done! Detected SSRNet Age: 27.4245\nLITEMNN_DEBUG LogId: ../hub/mnn/cv/ssrnet.mnn\n=============== Input-Dims ==============\n        **Tensor shape**: 1, 3, 64, 64, \nDimension Type: (CAFFE/PyTorch/ONNX)NCHW\n=============== Output-Dims ==============\ngetSessionOutputAll done!\nOutput: age:    **Tensor shape**: 1, \n========================================\nMNN Version Done! Detected SSRNet Age: 33.37\nLITETNN_DEBUG LogId: ../hub/tnn/cv/ssrnet.opt.tnnproto\n=============== Input-Dims ==============\ninput: [1 3 64 64 ]\nInput Data Format: NCHW\n=============== Output-Dims ==============\nage: [1 ]\n========================================\nTNN Version Done! Detected SSRNet Age: 23.7442\nTesting Successful !\n```  \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxlite-dev%2Fssrnet-toolkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxlite-dev%2Fssrnet-toolkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxlite-dev%2Fssrnet-toolkit/lists"}