当前位置:网站首页>HMS Core 机器学习服务
HMS Core 机器学习服务
2022-07-04 19:44:00 【Just_Paranoid】
机器学习服务(ML Kit)提供机器学习套件,为开发者使用机器学习能力开发各类应用,提供优质体验。得益于华为长期技术积累,ML Kit为开发者提供简单易用、服务多样、技术领先的机器学习能力,助力开发者更快更好地开发各类AI应用。
- 文本模块:文本识别、文档识别、身份证识别、银行卡识别、通用卡证识别、文本翻译、语种检测、实时语音识别、语音合成、离线语音合成、音频文件转写、声音识别、文本嵌入、实时语音转写
- 视觉模块:图像分割、对象检测与跟踪、图片分类、地标识别、图像超分辨率、文字图像超分辨率、场景识别、表格识别、文档校正
- 人体模块:人脸检测、3D人脸检测、人体骨骼检测、活体检测、手部关键点识别、手势识别、人脸比对
- 自定义模型的演示Demo
指南:
https://developer.huawei.com/consumer/cn/doc/development/hiai-Guides/service-introduction-0000001050040017
服务依赖列表
https://developer.huawei.com/consumer/cn/doc/development/hiai-Guides/overview-sdk-0000001051070278
文本识别
//1.创建文本分析器MLTextAnalyzer用于识别图片中的文字,您可以通过MLLocalTextSetting设置识别的语种,不设置语言默认只能识别拉丁字符。
//方式一:使用默认参数配置端侧文本分析器,只能识别拉丁语系文字。
MLTextAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer();
//方式二:使用自定义参数MLLocalTextSetting配置端侧文本分析器。
MLLocalTextSetting setting = new MLLocalTextSetting.Factory()
.setOCRMode(MLLocalTextSetting.OCR_DETECT_MODE)
// 设置识别语种。
.setLanguage("zh")
.create();
MLTextAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer(setting);
//2.通过android.graphics.Bitmap创建MLFrame,支持的图片格式包括:jpg/jpeg/png/bmp,建议输入图片长宽比范围:1:2到2:1。
// 通过bitmap创建MLFrame,bitmap为输入的Bitmap格式图片数据。
MLFrame frame = MLFrame.fromBitmap(bitmap);
//3.将生成的MLFrame对象传递给asyncAnalyseFrame方法进行文字识别。
Task<MLText> task = analyzer.asyncAnalyseFrame(frame);
task.addOnSuccessListener(new OnSuccessListener<MLText>() {
@Override
public void onSuccess(MLText text) {
// 识别成功处理。
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
// 识别失败处理。
}
});
//示例代码中使用了异步调用方式,本地文本识别还支持analyseFrame同步调用方式,识别结果以“MLText.Block”数组进行提供
Context context = getApplicationContext();
MLTextAnalyzer analyzer = new MLTextAnalyzer.Factory(context).setLocalOCRMode(MLLocalTextSetting.OCR_DETECT_MODE).setLanguage("zh").create();
SparseArray<MLText.Block> blocks = analyzer.analyseFrame(frame);
//4.识别完成,停止分析器,释放识别资源。
try {
if (analyzer != null) {
analyzer.stop();
}
} catch (IOException e) {
// 异常处理。
}
静态图片检测
//1.创建图片分类分析器。可以通过图像分类自定义类MLLocalClassificationAnalyzerSetting创建分析器。
// 方式一:端侧识别使用自定义参数配置。
MLLocalClassificationAnalyzerSetting setting =
new MLLocalClassificationAnalyzerSetting.Factory()
.setMinAcceptablePossibility(0.8f)
.create();
MLImageClassificationAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalImageClassificationAnalyzer(setting);
// 方式二:端侧识别使用默认参数配置。
MLImageClassificationAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalImageClassificationAnalyzer();
//2.通过android.graphics.Bitmap创建MLFrame,支持的图片格式包括:jpg/jpeg/png/bmp,建议图片尺寸不小于112*112像素。
// 通过bitmap创建MLFrame,bitmap为输入的Bitmap格式图片数据。
MLFrame frame = MLFrame.fromBitmap(bitmap);
//3.调用asyncAnalyseFrame方法进行图像分类(错误码信息可参见:机器学习服务错误码)。
Task<List<MLImageClassification>> task = analyzer.asyncAnalyseFrame(frame);
task.addOnSuccessListener(new OnSuccessListener<List<MLImageClassification>>() {
@Override
public void onSuccess(List<MLImageClassification> classifications) {
// 识别成功。
// 遍历返回的列表MLImageClassification,获取分类名称等信息。
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
// 识别失败。
// Recognition failure.
try {
MLException mlException = (MLException)e;
// 获取错误码,开发者可以对错误码进行处理,根据错误码进行差异化的页面提示。
int errorCode = mlException.getErrCode();
// 获取报错信息,开发者可以结合错误码,快速定位问题。
String errorMessage = mlException.getMessage();
} catch (Exception error) {
// 转换错误处理。
}
}
});
//4.识别完成,停止分析器,释放检测资源。
try {
if (analyzer != null) {
analyzer.stop();
}
} catch (IOException e) {
// 异常处理。
}
//以上示例代码中使用了异步调用方式,图片分类还支持同步调用使用analyseFrame函数获取检测结果:
SparseArray<MLImageClassification> classifications = analyzer.analyseFrame(frame);
边栏推荐
- FS4061A升压8.4V充电IC芯片和FS4061B升压12.6V充电IC芯片规格书datasheet
- What if the win11 shared file cannot be opened? The solution of win11 shared file cannot be opened
- Flet tutorial 06 basic introduction to textbutton (tutorial includes source code)
- idea配置标准注释
- 测试员的算法面试题-找众数
- 哈希(Hash)竞猜游戏系统开发功能分析及源码
- Win11U盘拒绝访问怎么办?Win11U盘拒绝访问的有效解决方法
- Flet tutorial 05 outlinedbutton basic introduction (tutorial includes source code)
- Selected review | machine learning technology for Cataract Classification / classification
- NLP、视觉、芯片...AI重点方向发展几何?青源会展望报告发布[附下载]
猜你喜欢
面对同样复杂的测试任务为什么大老很快能梳理解决方案,阿里十年测试工程师道出其中的技巧
Related concepts of federal learning and motivation (1)
电脑共享打印机拒绝访问要怎么办
What is involution?
How to solve the problem that win11 cannot write the value to the registry key?
测试员的算法面试题-找众数
Qt五子棋人机对战画棋子之QPainter的使用误区总结
FS8B711S14电动红酒开瓶器单片机IC方案开发专用集成IC
Flet教程之 04 FilledTonalButton基础入门(教程含源码)
二叉树的四种遍历方式以及中序后序、前序中序、前序后序、层序创建二叉树【专为力扣刷题而打造】
随机推荐
【ISMB2022教程】图表示学习的精准医疗,哈佛大学Marinka Zitnik主讲,附87页ppt
Automatic generation of interface automatic test cases by actual operation
RFID仓储管理系统解决方案的优点
Understand the reading, writing and creation of files in go language
go语言笔记(2)go一些简单运用
Advantages of semantic tags and block level inline elements
针对深度学习的“失忆症”,科学家提出基于相似性加权交错学习,登上PNAS
word中使用自动插入题注功能
什么是区块哈希竞猜游戏系统开发?哈希竞猜游戏系统开发(案例成熟)
Flet教程之 04 FilledTonalButton基础入门(教程含源码)
工厂从自动化到数字孪生,图扑能干什么?
ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声
What if win11u disk refuses access? An effective solution to win11u disk access denial
Why is TCP three handshakes and four waves
The concept and application of hash table
What ppt writing skills does the classic "pyramid principle" teach us?
哈希表、哈希函数、布隆过滤器、一致性哈希
CDGA|数据治理不得不坚持的六个原则
LeetCode 871. 最低加油次数
Quelques suggestions pour la conception de l'interface