I have rewatched WWDC22 a few times , but still not getting full understanding how to get .mlmodel model file type from components .
Example with banana ripeness is cool , but what need to be added to actually have output of .mlmodel , is somewhere full sample code for this type of modular project ?
Code is from [https://developer.apple.com/videos/play/wwdc2022/10019)
import CoreImage
import CreateMLComponents
struct ImageRegressor {
static let trainingDataURL = URL(fileURLWithPath: "~/Desktop/bananas")
static let parametersURL = URL(fileURLWithPath: "~/Desktop/parameters")
static func train() async throws -> some Transformer<CIImage, Float> {
let estimator = ImageFeaturePrint()
.appending(LinearRegressor())
// File name example: banana-5.jpg
let data = try AnnotatedFiles(labeledByNamesAt: trainingDataURL, separator: "-", index: 1, type: .image)
.mapFeatures(ImageReader.read)
.mapAnnotations({ Float($0)! })
let (training, validation) = data.randomSplit(by: 0.8)
let transformer = try await estimator.fitted(to: training, validateOn: validation)
try estimator.write(transformer, to: parametersURL)
return transformer
}
}
I have tried to run it in Mac OS command line type app, Swift-UI but most what I had as output was .pkg with
"pipeline.json, parameters, optimizer.json, optimizer"