Hello,
I am currently stuck on a problem involving the newly released feature of CreateML components.
I followed Get to know CreateML components, however, its not clear to me how this model can train with multiple iterations. I got a model to go through one iteration with the code shown in the video (it wasnt released as a project file), but there doesnt seem to be a way to increase the iterations. I also looked through the only associated project on CreateML components, but the code was different from what was described in that video and lacked the audio classifier example to see how it ticked.
It was also mentioned in the video that there might be issues saving the model in a CoreML file format due to it being custom, but that leaves the question of how ones supposed to save the trained model once done. It seems like saving a model would be really beneficial to machine learning tasks, right?
Here is the code I am using in swift playgrounds:
truct ImageRegressor{
static let trainingDataURL = URL(fileURLWithPath: "Project/regression_label")
static let parameterURL = URL(fileURLWithPath: "Project/parameters")
static func train() async throws -> some Transformer<CIImage, Float>{
let estimator = ImageFeaturePrint()
.appending(LinearRegressor())
let data = try AnnotatedFiles(labeledByNamesAt: trainingDataURL, separator: "-",type: .image)
.mapFeatures(ImageReader.read)
.mapAnnotations({_ in Float()})
let (training,validation) = data.randomSplit(by: 0.8)
let transformer = try await estimator.fitted(to:training,validateOn: validation){
event in guard let trainingMaxError = event.metrics[.trainingMaximumError] else{
return
}
guard let validationMaxError = event.metrics[.validationMaximumError] else{
return
}
print("Training max error: \(trainingMaxError), Validation max error: \(validationMaxError)")
}
let validationError = try await meanAbsoluteError(
transformer.applied(to: validation.map(\.feature)),
validation.map(\.annotation))
print("Mean absolute error: \(validationError)")
try estimator.write(transformer, to:parameterURL)
return transformer
}
}
func doSomething() {
Task{
let transformer = try await ImageRegressor.train()
}
}
doSomething()