This library is a TensorFlowLiteSwift wrapping library for vision pre/post-processing. You can use TFLiteSwift-Vision, if you want to implemented preprocessing and postprocessing functions in the repository.
Here is more detail of this repo's background and goal, and what is diff.
TFLiteSwift-Vision is available through CocoaPods. To install it, simply add the following line to your Podfile:
target 'MyXcodeProject' do
use_frameworks!
# Pods for Your Project
pod 'TFLiteSwift-Vision', '~> 0.2.6'
end
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
And then, run following:
pod install
.tflite
file in the Xcode ProjectIf you have other label file or other meta data file, also import it.
Import TFLiteSwift_Vision framework.
import TFLiteSwift_Vision
Setup interpreter.
let options = TFLiteVisionInterpreter.Options(
modelName: "mobilenet_v2_1.0_224",
inputRankType: .bwhc, // if it is pytorch model, use `.bchw`
normalization: .scaled(from: 0.0, to: 1.0)
)
var visionInterpreter = try? TFLiteVisionInterpreter(options: options)
Inference with an image. The following is an image classification case.
// inference
guard let output: TFLiteFlatArray = try? self.visionInterpreter?.inference(with: uiImage)?.first
else { fatalError("Cannot inference") }
// postprocess
let predictedIndex: Int = Int(output.argmax())
print("predicted index: \(predictedLabel)")
print(output.dimensions)
git clone https://github.com/tucan9389/TFLiteSwift-Vision
cd TFLiteSwift-Vision/Example
pod install
open TFLiteSwift-Vision.xcworkspace
Download tflite model and label txt, and then import the files into Xcode project.
You can also download the following files on here
After build and run the project, you can test the model(mobilenet_v2_1.0_224.tflite
) with your own image data.
image classification |
---|
TFLiteSwift-Vision is supporting (or wants to support) follow functions:
vImageScale_ARGB8888
)TFLiteSwift-Vision is available under the Apache license. See the LICENSE file for more info.