I want to use it in the code
Core ML
RSS for tagIntegrate machine learning models into your app using Core ML.
Post
Replies
Boosts
Views
Activity
I am sending CVPixelBuffers to the input of the DeepLabV3 MLModel. I am of the understanding that it requires pixel color format 32ARGB or 32RGBA. Correct?
Can 32BRGA be input? CVPixelBuffers support 32BRGA and OpenCV as well. Please note, I want to use the MLModel as trained.
Neither 32RGBA no 32ARGB are supported for type CVPixelBuffer.
32ARGB: An unsupported runtime error occurs with the configuration as follows...
func configureOutput() {
videoOutput.setSampleBufferDelegate(self, queue: bufferQueue)
videoOutput.alwaysDiscardsLateVideoFrames = true
videoOutput.videoSettings = [String(kCVPixelBufferPixelFormatTypeKey): kCMPixelFormat_32ARGB].
32RGBA: "Cannot find 'kCMPixelFormat_32rgba' in scope."
The app process: Video captured pixelBuffers are sent to c++ code where openCV operations are done, creating up to 3 smaller Mats which are then converted back into pixel buffers in the Objective-C. These converted PixedBuffer are used in three ways. All are sent to the MLModel for image segmentation to identify people; the files may be sent to the photo library; or may simply be viewed on the screen. I need a color format that can support all these down stream operations/pipelines.
I'm following Apple WWDC video (https://developer.apple.com/videos/play/wwdc2021/10037/) about how to create a recommendation model. But I'm getting this error when I run the project on that like of code from their tutorial.
"Column keywords has element of unsupported type Dictionary<String, Double>."
Here is the block of code took from the transcript of WWDC video that cause me issue:
func featuresFromMealAndKeywords(meal: String, keywords: [String]) -> [String: Double] {
// Capture interactions between content (the dish keywords) and context (meal) by
// adding a copy of each keyword modified to include the meal.
let featureNames = keywords + keywords.map { meal + ":" + $0 }
// For each keyword, create an entry in a dictionary of features with a value of 1.0.
return featureNames.reduce(into: [:]) { features, name in
features[name] = 1.0
}
}
var trainingKeywords: [[String: Double]] = []
var trainingTargets: [Double] = []
for item in userPurchasedItems {
// Add in the positive example.
trainingKeywords.append(
featuresFromMealAndKeywords(meal: item.meal, keywords: item.keywords))
trainingTargets.append(1.0)
// Add in the negative example.
let negativeKeywords = allKeywords.subtracting(item.keywords)
trainingKeywords.append(
featuresFromMealAndKeywords(meal: item.meal, keywords: Array(negativeKeywords)))
trainingTargets.append(-1.0)
}
// Create the training data.
var trainingData = DataFrame()
trainingData.append(column: Column(name: "keywords" contents: trainingKeywords))
trainingData.append(column: Column(name: "target", contents: trainingTargets))
// Create the model.
let model = try MLLinearRegressor(trainingData: trainingData, targetColumn: "target")
Did DataFrame implementation changed since then and doesn't support Dictionary anymore? I'm at lost right now on how to reproduce their example.
I created a word tagging model in CreateML and am trying to make predictions with it using the following code:
let text = "$30.00 7/1/2023"
let model = TaggingModel()
let input = TaggingModelInput(text: text)
guard let output = try? model.prediction(input: input) else {
fatalError("Unexpected runtime error.")
}
However, the output separates "$" and "30.00" as separate tokens as well as "7", "/", "1", "/", etc. Is there any way to make sure prices and dates get grouped together and to simply separate tokens based on whitespace? Any help is appreciated!
I have converted an UIImage to MLShapedArray and by default this is NCHW format. I need to permute it into NCWH to prepare it for an ML model. What is the recommended way to achieve this ?