{"id":15935192,"url":"https://github.com/asakusarinne/megengine_cpp_training_example","last_synced_at":"2025-04-03T15:18:30.336Z","repository":{"id":44099119,"uuid":"440063408","full_name":"AsakusaRinne/megengine_cpp_training_example","owner":"AsakusaRinne","description":"Examples for using MegEngine cpp API for model training, which support Linux, Windows, Android, Linux_arm and IOS.","archived":false,"fork":false,"pushed_at":"2021-12-27T04:12:38.000Z","size":48,"stargazers_count":2,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-29T08:23:47.342Z","etag":null,"topics":["cpp","deep-learning","megengine","mobile"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AsakusaRinne.png","metadata":{"files":{"readme":"README-CN.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}},"created_at":"2021-12-20T06:20:05.000Z","updated_at":"2022-05-20T06:59:12.000Z","dependencies_parsed_at":"2022-09-16T01:02:46.538Z","dependency_job_id":null,"html_url":"https://github.com/AsakusaRinne/megengine_cpp_training_example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsakusaRinne%2Fmegengine_cpp_training_example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsakusaRinne%2Fmegengine_cpp_training_example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsakusaRinne%2Fmegengine_cpp_training_example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsakusaRinne%2Fmegengine_cpp_training_example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AsakusaRinne","download_url":"https://codeload.github.com/AsakusaRinne/megengine_cpp_training_example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247024155,"owners_count":20870940,"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":["cpp","deep-learning","megengine","mobile"],"created_at":"2024-10-07T03:40:32.202Z","updated_at":"2025-04-03T15:18:30.314Z","avatar_url":"https://github.com/AsakusaRinne.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"[English](README.md) | 中文\n\n# 介绍\n本项目用于展示MegEngine的端上训练功能，目前仅给出了基于Mnist数据集使用LeNet进行端上训练的demo。\n\n[MegEngine](https://github.com/MegEngine/MegEngine)是一个快速、可拓展、易于使用且支持自动求导的深度学习框，不仅如此，现在MegEngine还对端上训练提供了支持，端上训练主要适用于移动端和IOT等场景，在一些情况下不方便将采集到的数据通过网络传回服务端进行训练，比如对人脸数据、指纹等的采集涉及到隐私和法律问题，这时候就需要在移动端或IOT设备上对模型进行训练。\n\n目前MegEngine端上训练还处于初期的探索阶段，可能还不太成熟，期待MegEngine之后会推出更强大而友好的端上训练API！\n\n# 使用\n\n### 首先，克隆本项目并运行脚本准备依赖项\n\n提示：国内可能会克隆一些子项目比较慢，甚至失败，请多尝试几次或者使用代理。\n\n```\ngit clone https://github.com/AsakusaRinne/megengine_cpp_training_example.git\ncd megengine_cpp_training_example\n./third_party/prepare.sh\n./third_party/MegEngine/third_party/prepare.sh\n./third_party/MegEngine/third_party/install-mkl.sh\n```\n\n### 然后，根据设备以及目标平台进行环境的配置，请根据下面的MegEngine文档进行\n\n[MegEngine cmake-build配置文档](https://github.com/MegEngine/MegEngine/blob/master/scripts/cmake-build/BUILD_README.md)\n\n### 编译并运行 \n\n这里有四种脚本可以进行自动编译与生成，分别是host, android_arm, linux_arm和IOS，请根据自己需要的目标平台选取脚本并运行。如果是其它的平台，也可以自己手动进行配置并编译与生成。\n\n脚本分别为 ```scripts/host_build.sh```, ```scripts/cross_build_android_arm_train.sh```, ```scripts/cross_build_linux_arm_train.sh```和```scripts/cross_build_ios_arm_train.sh```。\n\n比如如果我们要在Arm架构的Android平台上运行demo，我们可以运行以下命令，其中```-h```用来查询脚本的可选命令。\n\n```\n./scripts/cross_build_android_arm_train.sh -h # show the usages of the script.\n./scripts/cross_build_android_arm_train.sh -d -r # build with debug mode and remove the old directory before building\n```\n\n### 最后，将生成好的可执行文件拷贝到目标设备并执行\n\n其中，可执行文件默认存在于```build_dir```中与目标平台对应的目录中的```install/bin```文件夹下，也可以自行修改```CMakeLists.txt```中的```install```命令内容来指定安装目录。\n\n比如目标平台是```android_arm```且使用release模式时，处于```build_dir/android/arm-xx/Release/install/bin```路径下。\n\n```\n./CppTrainingExamples mnist\n```\n\n程序会要求输入一些和训练有关的信息，包括数据类型、训练轮数、数据集路径等。\n\n以下参数作为参考：\n\n```\nbatchsize: 16\ndtype: int8\nepochs: 1\n```\n\n\n可以通过以下命令下载mnist数据集：\n\n```\npython3 ./mnist/dataset/download.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasakusarinne%2Fmegengine_cpp_training_example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasakusarinne%2Fmegengine_cpp_training_example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasakusarinne%2Fmegengine_cpp_training_example/lists"}