新聞中心
概述

創(chuàng)新互聯(lián)公司長期為上千家客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為額敏企業(yè)提供專業(yè)的成都做網(wǎng)站、成都網(wǎng)站建設(shè),額敏網(wǎng)站改版等技術(shù)服務(wù)。擁有十年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
在移動設(shè)備上使用 TensorFlow Lite 模型運行推理不僅僅是與模型交互,還需要額外的代碼來處理復(fù)雜的邏輯,如數(shù)據(jù)轉(zhuǎn)換、預(yù)處理/后處理、加載關(guān)聯(lián)文件等。
- 額外的代碼
- https://tensorflow.google.cn/lite/guide/lite_support
今天,我們將為大家介紹 TensorFlow Lite Task Library,這是一組功能強大且易于使用的模型接口,可代您處理大多數(shù)預(yù)處理和后處理以及其他復(fù)雜邏輯。Task Library 支持主流的機器學(xué)習(xí)任務(wù),包括圖像分類與分割、目標檢測和自然語言處理。模型接口針對每個任務(wù)進行過專門設(shè)計,可實現(xiàn)最佳性能和易用性——現(xiàn)在,只需 5 行代碼就可以在受支持任務(wù)的預(yù)訓(xùn)練和自定義模型上執(zhí)行推理!目前,Task Library 已廣泛用于許多 Google 產(chǎn)品的生產(chǎn)環(huán)境中。
- TensorFlow Lite Task Library
- https://tensorflow.google.cn/lite/inference_with_metadata/task_library/overview
支持的 ML 任務(wù)
TensorFlow Lite Task Library 目前支持六個 ML 任務(wù),包括視覺和自然語言處理用例。下面將逐一進行簡要介紹。
- ImageClassifier
圖像分類器是機器學(xué)習(xí)的一種常見用例,用于識別圖像所代表的內(nèi)容。例如,我們可能想知道給定圖片中出現(xiàn)了哪種動物。ImageClassifier API 支持常見的圖像處理和配置,還允許在特定的受支持區(qū)域設(shè)置中顯示標簽,并根據(jù)標簽許可名單和禁止名單篩選結(jié)果。 - ObjectDetector
物體檢測器可以識別一組中可能存在哪些已知物體,并提供這些物體在給定圖像或視頻串流中的位置信息。ObjectDetector API 支持類似于 ImageClassifer 的圖像處理選項。輸出結(jié)果將列出檢測到的前 k 個物體并帶有標簽、邊界框和概率。 - ImageSegmenter
圖像分割器預(yù)測圖像的每個像素是否與某個類相關(guān)聯(lián)。這與物體檢測(檢測矩形區(qū)域中的物體)和圖像分類(對整個圖像進行分類)相反。除圖像處理外,ImageSegmenter 還支持兩種類型的輸出蒙版:類別蒙版和置信度蒙版。 - NLClassifier 和 BertNLClassifier
- NLClassifier將輸入文本分為不同的類別。可對該通用 API 進行配置,使其可以加載任何支持文本輸入和分數(shù)輸出的 TFLite 模型。
- BertNLClassifier 與 NLClassifier 類似,不同之處在于,此 API 專門為 BERT 相關(guān)模型量身定制,需要在 TFLite 模型之外進行 Wordpiece 和 Sentencepiece 分詞。
- BertQuestionAnswerer
BertQuestionAnswerer 加載 BERT 模型并根據(jù)給定段落的內(nèi)容回答問題。目前支持MobileBERT 和 ALBERT。與 BertonCollector 類似,BertQuestionAnswerer 封裝了對輸入文本的復(fù)雜分詞處理。您可以將上下文和問題以字符串形式傳遞給 BertQuestionAnswerer 模型。
支持的模型
Task Library 與下列已知的模型源兼容:
- TensorFlow Hub Task Library 模型集合(圖像分類/物體檢測/圖像分割/問答)。
- TensorFlow Lite Model Maker 創(chuàng)建的模型。
- AutoML Vision Edge 創(chuàng)建的模型。
Task Library 還支持符合每個 Task API 的模型兼容性要求的自定義模型。關(guān)聯(lián)的文件(即標簽圖和 vocab 文件)和處理參數(shù)(如果適用)應(yīng)正確填充到模型元數(shù)據(jù)中。有關(guān)更多詳細信息,請參見 TensorFlow 網(wǎng)站上針對每個 API 的文檔。
- 模型元數(shù)據(jù)
- https://tensorflow.google.cn/lite/convert/metadata
- TensorFlow 網(wǎng)站上針對每個 API 的文檔https://tensorflow.google.cn/lite/inference_with_metadata/task_library/overview
使用 Task Library 運行推理
Task Library 可跨平臺工作,并且在 Java、C++(實驗性)和 Swift(實驗性)上均受支持。使用 Task Library 運行推理十分簡單,只需編寫幾行代碼。例如,您可以使用 DeepLab v3 TFLite 模型在 Android 中分割飛機圖像(圖 1),如下所示:
- // Create the API from a model file and options
- String modelPath = "path/to/model.tflite"
- ImageSegmenterOptions options = ImageSegmenterOptions.builder().setOutputType(OutputType.CONFIDENCE_MASK).build();ImageSegmenter imageSegmenter = ImageSegmenter.createFromFileAndOptions(context, modelPath, options);// Segment an imageTensorImage image = TensorImage.fromBitmap(bitmap);List results = imageSegmenter.segment(image);
ImageSegmenter 輸入圖像
分割蒙版
然后,您可以在結(jié)果中使用彩色標簽和類別蒙版來構(gòu)造分割蒙版圖像,如圖 2 所示。
三個文本 API 均支持 Swift。要在 iOS 中使用 SQuAD v1 TFLite 模型對給定的上下文和問題執(zhí)行問答,您可以運行:
- let modelPath = "path/to/model.tflite"
- // Create the API from a model file
- let mobileBertAnswerer = TFLBertQuestionAnswerer.mobilebertQuestionAnswerer(modelPath: modelPath)let context = """
- The Amazon rainforest, alternatively, the Amazon Jungle, also known in \
- English as Amazonia, is a moist broadleaf tropical rainforest in the \
- Amazon biome that covers most of the Amazon basin of South America. This \
- basin encompasses 7,000,000 square kilometers(2,700,000 square miles), of \
- which 5,500,000 square kilometers(2,100,000 square miles) are covered by \
- the rainforest. This region includes territory belonging to nine nations.
- """
- let question = "Where is Amazon rainforest?"
- // Answer a questionlet answers = mobileBertAnswerer.answer(context: context, question: question)// answers.[0].text could be “South America.”
- DeepLab v3 TFLite 模型
- https://tfhub.dev/tensorflow/lite-model/deeplabv3/1/metadata/1
- SQuAD v1 TFLite 模型https://tfhub.dev/tensorflow/lite-model/albert_lite_base/squadv1/1
為您的用例構(gòu)建一個 Task API
如果現(xiàn)有 Task 庫不支持您的用例,則您可以利用 Task API 基礎(chǔ)架構(gòu)并構(gòu)建自定義 C++/Android/iOS 推理 API。有關(guān)更多詳細信息,請參閱本指南。
- 指南
- https://tensorflow.google.cn/lite/inference_with_metadata/task_library/customized_task_api
未來工作
我們將繼續(xù)改善 Task Library 的用戶體驗。近期的路線圖如下:
- 改善 C++ Task Library 的易用性,例如為希望從源代碼構(gòu)建的用戶提供預(yù)構(gòu)建的二進制文件并創(chuàng)建人性化工作流。
- 使用 Task Library 發(fā)布參考示例。
- 通過新的任務(wù)類型支持更多的機器學(xué)習(xí)用例。
- 改善跨平臺支持,針對 iOS 支持更多任務(wù)。
反饋
歡迎大家提供反饋,并就 Task Library 中支持的新用例給出建議。請向 tflite@tensorflow.org發(fā)送電子郵件或在 GitHub 中提 issue。
- issue
- https://github.com/tensorflow/tflite-support/issues/new
致謝
這項成果離不開以下人員的共同努力:
- Task Library Vision API 的主要貢獻者 Cédric Deltheil 和 Maxime Brénon。
- Task Library 原生/Android/iOS 基礎(chǔ)架構(gòu)和 Text API 的主要貢獻者 Chen Cen。
- 開發(fā)基礎(chǔ)結(jié)構(gòu)和發(fā)布流程的主要貢獻者 Xunkai 和 YoungSeok Yoon。
以及 Tian Lin、Sijia Ma、YoungSeok Yoon、Yuqi Li、Hsiu Wang、Qifei Wang、Alec Go、Christine Kaeser-Chen、Yicheng Fan、Elizabeth Kemp、Willi Gierke、Arun Venkatesan、Amy Jang、Mike Liang、Denis Brulé、Gaurav Nemade、Khanh LeViet、Luiz GUStavo Martins、Shuangfeng Li、Jared Duke、Erik Vee、Sarah Sirajuddin 以及 Tim Davis 都對本項目給予了大力支持,在此一并表示感謝。
網(wǎng)站標題:TensorFlow推出新接口,簡化ML移動端開發(fā)流程
文章網(wǎng)址:http://www.5511xx.com/article/cdipspg.html


咨詢
建站咨詢
