if let img = image?.cgImage, let fcrn = try? FCRN(contentsOf: FCRN.urlOfModelInThisBundle, configuration: config) {
if let input = try? FCRNInput(imageWith: img), let output = try? fcrn.prediction(input: input) {
print(output.depthmapShapedArray)
}
}
}
复制代码
MNISTClassifier:
/**
涂鸦分类
对单个手写数字进行分类 (支持数字 0-9)。
*/
func mnistClassifier(image: UIImage?) {
if let img = image?.cgImage, let mnist = try? MNISTClassifier(contentsOf: MNISTClassifier.urlOfModelInThisBundle, configuration: MLModelConfiguration()) {
if let input = try? MNISTClassifierInput(imageWith: img), let output = try? mnist.prediction(input: input) {
if let img = image?.cgImage, let updatable = try? UpdatableDrawingClassifier(contentsOf: UpdatableDrawingClassifier.urlOfModelInThisBundle, configuration: MLModelConfiguration()) {
if let input = try? UpdatableDrawingClassifierInput(drawingWith: img), let output = try? updatable.prediction(input: input) {
print(output.label)
print(output.labelProbs)
}
}
}
复制代码
MobileNetV2:
/**
图像分类
MobileNetv2 架构经过训练,可对相机取景框内或图像中的主要对象进行分类。
*/
func mobileNetV2(image: UIImage?) {
if let img = image?.cgImage, let netv2 = try? MobileNetV2(contentsOf: MobileNetV2.urlOfModelInThisBundle, configuration: MLModelConfiguration()) {
if let input = try? MobileNetV2Input(imageWith: img), let output = try? netv2.prediction(input: input) {
print(output.classLabel)
print(output.classLabelProbs)
}
}
}
复制代码
Resnet50:
/**
图像分类
一种残差神经网络,它能对相机取景框内或图像中的主要对象进行分类。
*/
func resnet50(image: UIImage?) {
if let img = image?.cgImage, let resnet = try? Resnet50(contentsOf: Resnet50.urlOfModelInThisBundle, configuration: MLModelConfiguration()) {
if let input = try? Resnet50Input(imageWith: img), let output = try? resnet.prediction(input: input) {
print(output.classLabel)
print(output.classLabelProbs)
}
}
}
复制代码
SqueezeNet:
/**
图像分类
一种小型深度神经网络架构,它能对相机取景框内或图像中的主要对象进行分类。
*/
func squeezeNet(image: UIImage?) {
if let img = image?.cgImage, let net = try? SqueezeNet(contentsOf: SqueezeNet.urlOfModelInThisBundle, configuration: MLModelConfiguration()) {
if let input = try? SqueezeNetInput(imageWith: img), let output = try? net.prediction(input: input) {