coreml

how can I pass unsafemutablerawpointer as a C's pointer to objective c++?

北战南征 提交于 2019-12-14 04:04:16
问题 I'm trying to integrate CoreML model into my app. The output is given by a MLMultiArray , but I want the data in it in order to generate an OpenCV matrix. There is a dataPointer property in MLMultiArray , which is a UnsafeMutableRawPointer . How can I pass it as a C's pointer so that I can directly use it to generate an OpenCV matrix? Thanks in advance! 回答1: I found a solution. I don't need to pass the dataPointer as C's pointer from Swift to Objective-C++. I can just pass the whole

Unable to load CoreML model using MLModel.compileModel(at:)

走远了吗. 提交于 2019-12-13 05:08:00
问题 I am trying to load a .mlmodel file using the following code: let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) var documentsUrl = paths[0] documentsUrl.appendPathComponent("parallel.mlmodel") do { let compiledModelUrl = try MLModel.compileModel(at: documentsUrl) let model = try? MLModel(contentsOf: compiledModelUrl) } catch { print(error.localizedDescription) } But I get the error The file couldn’t be saved. , the model does exist at that location. 回答1: I

Convert MobileNet from Keras to CoreML

给你一囗甜甜゛ 提交于 2019-12-13 03:54:29
问题 I'm using Keras 2.1.3 and I want to convert MobileNet to CoreML: from keras.applications import MobileNet from keras.applications.mobilenet import relu6 from keras.applications.mobilenet import DepthwiseConv2D import coremltools.converters.keras as k def save_model(): model = MobileNet(input_shape=(128,128,3), include_top=False) model.save('temp.h5') def convert(): model = k.convert('temp.h5', input_names=['input'], output_names=['output'], model_precision='float16', custom_conversion

How do I get the .mlmodel to be used in Swift Playground?

风格不统一 提交于 2019-12-13 00:38:20
问题 I have already converted the .mlmodel to .mlmodelc , and I have put it in the resources folder. Im using Vision framework and MNIST model, following this tutorial (https://www.youtube.com/watch?v=bOg8AZSFvOc), but using swift playground. What am i missing? (im using .playground files, not .playgroundbook files) line of code: guard let visionModel = try? VNCoreMLModel(for: MNIST().modelc) else {fatalError("can not load Vision ML model")} Error message: use of undefined identifier 'MNIST'

How to initialize a MLMultiArray in CoreML

淺唱寂寞╮ 提交于 2019-12-12 16:25:08
问题 I've got an array of 40 arrays with 12 double features, so the type is [[double]]. Currently I'm sending this data to Google Cloud ML API to get a related prediction. Since Apple recently introduced CoreML and coremltools, I converted my model from keras to .mlmodel to avoid thousand of google cloud api calls and do inference directly on my iPhone: coreml_model = coremltools.converters.keras.convert(new_Model, input_names=['accelerations'], output_names=['scores']) coreml_model.save(

CoreML2 keeps telling me everything is the same thing

坚强是说给别人听的谎言 提交于 2019-12-12 06:52:39
问题 I am trying to start small and have trained my model with 2 items. It recognises both just fine but when I show it something other than the 2 items it knows, it keeps telling me that is is always the same item. For example, I have an apple and banana. If I show it the apple, it correctly gives me apple, if I show it a banana it correctly returns banana. But if I show it a dog, it tells me it is an apple. If I show it a helicopter it tells me it is an apple. I even tried an if statement to say

Error when running coreml in the background: Error computing NN outputs error

独自空忆成欢 提交于 2019-12-11 16:56:58
问题 I'm running an mlmodel that is coming from keras on an iPhone 6. The predictions often fails with the error Error computing NN outputs . Does anyone know what could be the cause and if there is anything I can do about it? do { return try model.prediction(input1: input) } catch let err { fatalError(err.localizedDescription) // Error computing NN outputs error } EDIT: I tried apple's sample project and that one works in the background so it seems it's specific to either our project or model

Turi Create - Please use dropna() to drop rows

走远了吗. 提交于 2019-12-11 16:32:55
问题 I am having issues with Apple Turi Create and image classifier. I have successfully created a model with 22 categories. I have recently added 5 more categories and console is giving me error warning Please use dropna() to drop rows with missing target values. The full console log looks like this: [16:30:30] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.8.0. Attempting to upgrade... [16:30:30] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!

AVCaptureVideo not showing label

空扰寡人 提交于 2019-12-11 16:00:10
问题 I am trying to retain the objects from the console to be shown in as a label(classifierText). The warning of "UILabel.text must be used from main thread only" appears. What seems to the problem as to why the items are being shown as the label? var previewLayer: AVCaptureVideoPreviewLayer! let classifierText: UILabel = { let classifier = UILabel() classifier.translatesAutoresizingMaskIntoConstraints = false classifier.textColor = .black classifier.font = UIFont(name: "Times-New-Roman", size:

How to L2 normalize an array with Swift

妖精的绣舞 提交于 2019-12-11 15:37:40
问题 I am trying normalize the input of my CoreML model like below, it kind of does something to the array but its quite different then what SKLearn does(I give same input and watch output in these environments). So appereantly I do something wrong. My Model is trained with Keras and SKlearn and it must do the same normalization as I did using SKLearn Normalizer, which is the default L2 normalizer . What I am doing below apperantly is not equalivant of sklearn, any ideas? vDSP_normalizeD(vec, 1,