iOS使用CoreML运用小型深度神经网络架构对图像进行解析

编程入门 行业动态 更新时间:2024-10-11 17:22:27

iOS使用CoreML运用小型深度<a href=https://www.elefans.com/category/jswz/34/1769690.html style=神经网络架构对图像进行解析"/>

iOS使用CoreML运用小型深度神经网络架构对图像进行解析

查找一个图片选择器

我用的是ImagePicker
项目有点老了,需要做一些改造,下面是新的仓库

platform :ios, '16.0'use_frameworks!target 'learnings' dosource '.git'pod 'ImagePicker', :git => '.git'end

接下来就是使用图片选择器输出图片了

    func wrapperDidPress(_ imagePicker: ImagePicker.ImagePickerController, images: [UIImage]) {}func doneButtonDidPress(_ imagePicker: ImagePicker.ImagePickerController, images: [UIImage]) {if !images.isEmpty, let _ = images.first {/**在这里输出图片,可以调用模型进行解析*/}}func cancelButtonDidPress(_ imagePicker: ImagePicker.ImagePickerController) {imagePicker.dismiss(animated: true)}

当前我使用了几个公开的模型

FCRN:

/**深度估计根据一幅图像来预测深度。*/func fcrnDepthPrediction(image: UIImage?) {let config = MLModelConfiguration()configputeUnits = .allif 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) {print(output.classLabel)print(output.labelProbabilities)}}}

UpdatableDrawingClassifier:

/**涂鸦分类基于 K-最近邻算法(KNN)模型来学习识别新涂鸦的涂鸦分类器。*/func updatableDrawingClassifier(image: UIImage?) {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) {print(output.classLabel)print(output.classLabelProbs)}}}

更多推荐

iOS使用CoreML运用小型深度神经网络架构对图像进行解析

本文发布于:2023-12-05 17:29:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1664845.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:神经网络   架构   深度   图像   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!