tf-coreml TensorFlow 转换到 CoreML 的转换器开源项目

我要开发同款
匿名用户2019年01月02日
127阅读

技术信息

开源地址
https://github.com/tf-coreml/tf-coreml
授权协议
Apache

作品详情

tfcoreml

TesorFlow(TF)toCoreMLCoverter

Depedecies

tesorflow>=1.5.0

coremltools>=0.8

umpy>=1.6.2

protobuf>=3.1.0

six>=1.10.0

IstallatioIstallFromSource

Togetthelatestversioofthecoverter,cloethisrepoadistallfromsource.Thatis,

git cloe https://github.com/tf-coreml/tf-coreml.gitcd tf-coreml

Toistallasapackagewithpip,eitherru(attherootdirectory):

pip istall -e .

orru:

pytho setup.py bdist_wheel

Thiswillgeerateapipistallablewheelisidethedistdirectory.

IstallFromPyPI

ToistallthePypipackage:

pip istall -U tfcoreml

Usage

SeeiPythootebooksithedirectoryexamples/forexamplesofhowtousethecoverter.

ThefollowigargumetsarerequiredbytheCoreMLcoverter:

pathtothefroze.pbgraphfiletobecoverted

pathwherethe.mlmodelshouldbewritte

alistofoutputtesoramespresetitheTFgraph

adictioaryofiputamesadtheirshapes(aslistofitegers).Thisisolyrequiredifiputtesors'shapesareotfullydefiedithefroze.pbfile(e.g.theycotaiNoeor?)

Notethatthefroze.pbfilecabeobtaiedfromthecheckpoitadgraphdeffilesbyusigthetesorflow.pytho.tools.freeze_graphutility.FordetailsoffreezigTFgraphs,pleaserefertotheTesorFlowdocumetatioadtheotebooksidirectoryexamples/ithisrepo.Therearescriptsitheutils/directoryforvisualizigadwritigoutatextsummaryofagivefrozeTFgraph.Thiscouldbeusefulidetermiigtheiput/outputamesadshapes.AotherusefultoolforvisualizigfrozeTFgraphsisNetro.

Thereareadditioalargumetsthatthecovertercatake.Fordetails,refertothefullfuctiodefiitiohere.

Forexample:

Wheiputshapesarefullydetermiedithefroze.pbfile:

import tfcoreml as tf_covertertf_coverter.covert(tf_model_path = 'my_model.pb',                     mlmodel_path = 'my_model.mlmodel',                     output_feature_ames = ['softmax:0'])

Wheiputshapesareotfullyspecifiedithefroze.pbfile:

import tfcoreml as tf_covertertf_coverter.covert(tf_model_path = 'my_model.pb',                     mlmodel_path = 'my_model.mlmodel',                     output_feature_ames = ['softmax:0'],                     iput_ame_shape_dict = {'iput:0' : [1, 227, 227, 3]})

Followigtopicsarediscussedithejupyterotebooksudertheexamples/folder:

iceptio_v1_preprocessig_steps.ipyb:Howtogeerateaclassifiermodelwithimageiputtypesadtheimportaceofproperlysettigthepreprocessigparameters.

iceptio_v3.ipyb:Howtostripthe"DecodeJpeg"opfromtheTFgraphtoprepareitforCoreMLcoversio.

liear_mist_example.ipyb:HowtogetafrozegraphfromthecheckpoitadgraphdescriptiofilesgeeratedbytraiigiTF.

ssd_example.ipyb:HowtoextractaportiooftheTFgraphthatcabecoverted,fromtheoverallgraphthatmayhaveusupportedops.

style_trasfer_example.ipyb:HowtoeditaCoreMLmodeltogetaimageoutputtype(bydefaulttheoutputsareMultiArrays).

custom_layer_examples.ipyb:AfewexamplestodemostratetheprocessofaddigcustomCoreMLlayersforusupportedTFops.

SupportedOps

ListofTesorFlowopsthataresupportedcurretly(seetfcoreml/_ops_to_layers.py):

Abs

Add

ArgMax

AvgPool

BatchNormWithGlobalNormalizatio

BatchToSpaceND*

BiasAdd

CocatV2,Cocat

Cost

Cov2D

Cov2DBackpropIput

CropAdResize*

DepthToSpace

DepthwiseCov2dNative

Elu

Exp

ExtractImagePatches

FusedBatchNorm

Idetity

Log

LRN

MatMul

Max*

Maximum

MaxPool

Mea*

Mi*

Miimum

MirrorPad

Mul

Neg

OeHot

Pad

Placeholder

Pow*

Prod*

RealDiv

Reciprocal

Relu

Relu6

Reshape*

ResizeNearestNeighbor

ResizeBiliear

Rsqrt

Sigmoid

Slice*

Softmax

SpaceToBatchND*

SpaceToDepth

Split*

Sqrt

Square

SquaredDifferece

StridedSlice*

Sub

Sum*

Tah

Traspose*

Notethatcertaiparameterizatiosoftheseopsmayotbefullysupported.Foropsmarkedwithaasterisk,olyveryspecificusagepattersaresupported.Iadditio,thereareseveralotherops(otlistedabove)thatareskippedbythecoverterastheygeerallyhaveoeffectdurigiferece.Kidlyrefertothefilestfcoreml/_ops_to_layers.pyadtfcoreml/_layers.pyforfulldetails.Forusupportedopsorcofiguratios,thecustomlayerfeatureofCoreMLcabeused.Fordetails,refertotheexamples/custom_layer_examples.ipybotebook.

Scriptsforcovertigseveralofthefollowigpretraiedmodelscabefoudattests/test_pretraied_models.py.Othermodelswithsimilarstructuresadsupportedopscabecoverted.BelowisalistofpubliclyavailableTesorFlowfrozemodelsthatcabecovertedwiththiscoverter:

Iceptiov1(Slim)

Iceptiov2(Slim)

Iceptiov3(Slim)

Iceptiov4(Slim)

Iceptiov3(o-Slim)*

Iceptio/ResNetv2(Slim)

MobileNetvariatios(Slim):

Imagesize:128(1,2,3,4)

Imagesize:160(1,2,3,4)

Imagesize:192(1,2,3,4)

Imagesize:224(1,2,3,4)

Imagestylizatioetwork+

MobileetSSD*

*CovertigthesemodelsrequiresextrastepstoextractsubgraphsfromtheTFfrozegraphs.Seeexamples/fordetails.<br>+TherearekowissuesruigimagestylizatioetworkoGPU.(SeeIssue#26)

Limitatios

tfcoremlcoverterhasthefollowigcostraits:

TFgraphmustbecyclefree(cyclesaregeerallycreatedduetocotrolflowopslikeif,while,map,etc.)

MusthaveNHWCorderig(Batchsize,Height,Width,Chaels)forimagefeaturemaptesors

Musthavetesorswithraklessthaorequalto4(le(tesor.shape)<=4)

ThecoverterproducesCoreMLmodelwithfloatvalues.AquatizedTFgraph(suchasthestyletrasferetworklikedabove)getscovertedtoafloatCoreMLmodel

RuigUitTests

Iordertoruuittests,youeedpytest.

pip istall pytest

Toaddaewuittest,addittothetests/folder.Makesureyouamethefilewitha'test'astheprefix.Torualluittests,avigatetothetests/folderadru

pytest

Directories

"tfcoreml":thetfcoremlpackage

"examples":examplestousethiscoverter

"tests":uittests

"utils":geeralscriptsforgraphispectio

Licese

ApacheLicese2.0

功能介绍

tfcoreml TensorFlow (TF) to CoreML Converter Dependencies tensorflow >= 1.5.0 coremltools >= 0.8 ...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论