TensorFlow Lite (一) iOS快速入门

1. TensorFlow Lite sample applications

下载 tensorflow example代码:

git clone https://github.com/tensorflow/examples

examples/lite目录下是TensorFlow Lite sample applications。每个示例程序都用Android 和 iOS开发,介绍了Tesnsorflow Lite如何应用到移动开发应用程序上。
详细参考examples/lite/README.txt
例如:
lite/examples/image_classification/ios是一图片分类程序在iOS开发中的应用,Xcode打开既可以运行。
参考lite/examples/image_classification/ios/EXPLORE_THE_CODE.md,有详细介绍。

额外使用tensorflow-lite使用开发应用程序,参考官网https://tensorflow.google.cn/lite/examples?hl=zh_cn

2. 将TensorFlow Lite加入到Swift or Objective-C工程

TensorFlow Lite官方提供原生iOS库,用Swift和Objective-C开发。以图像分类实例程序为起点开发你的应用程序:https://github.com/tensorflow/examples/tree/master/lite/examples/image_classification/ios
下面介绍怎么把TensorFlow Lite加入到你的swift或者是objective-c工程中。

2-1. CocoaPods导入

在Podfile文件中加入TensorFlow Lite引用,运行pod install安装。
Swift:

use_frameworks!
pod 'TensorFlowLiteSwift'

Objective-C:

pod 'TensorFlowLiteObjC'

如果基于Objective-C开发,TensorFlow Lite引用, 在Podfile中必须包含use_frameworks。
上述默认引用最新的稳定发行版。如果进行引用指定版本,如下引用2.0.0版本。

pod 'TensorFlowLiteSwift', '~> 2.0.0'

如果引用每晚发型的版本:

pod 'TensorFlowLiteSwift', '0.0.1-nightly'

第一次运行pod install将会创建Podfile.lock文件,这将会锁定nightly library version 到今天版本。运行pod update 命令进行版本更新。
版本号如何填写,参考 Specifying pod versions

2-2. Bazel开发

在BUILD文件中, 加入TensorFlowLite依赖。
Swift:

swift_library(
  deps = [
      "//tensorflow/lite/experimental/swift:TensorFlowLite",
  ],
)

Objective-C:

objc_library(
  deps = [
      "//tensorflow/lite/experimental/objc:TensorFlowLite",
  ],
)
2-3. 导入TensorFlow Lite

Swift源代码中,导入TensorFlow Lite模块:

import TensorFlowLite

Objective-C源文件, 导入头文件:

#import "TFLTensorFlowLite.h"

在Xoce工程中, 设置模块CLANG_ENABLE_MODULES = YES:

@import TFLTensorFlowLite;

Note: For CocoaPods developers who want to import the Objective-C TensorFlow Lite module, you must also include use_frameworks! in your Podfile.

如何编译iOS TensorFlow Lite,请参考https://blog.csdn.net/mandagod/article/details/104354961

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值