Skip to content

Instantly share code, notes, and snippets.

@iosdevie
Created May 26, 2021 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iosdevie/a34d088fbbef03d0022e396825858c65 to your computer and use it in GitHub Desktop.
Save iosdevie/a34d088fbbef03d0022e396825858c65 to your computer and use it in GitHub Desktop.
Create a batch provider CoreML
private func batchProvider() -> MLArrayBatchProvider
{
var batchInputs: [MLFeatureProvider] = []
let imageOptions: [MLFeatureValue.ImageOption: Any] = [
.cropAndScale: VNImageCropAndScaleOption.scaleFill.rawValue
]
for (image,label) in imageLabelDictionary {
do{
let featureValue = try MLFeatureValue(cgImage: image.cgImage!, constraint: imageConstraint, options: imageOptions)
if let pixelBuffer = featureValue.imageBufferValue{
let x = CatDogUpdatableTrainingInput(image: pixelBuffer, classLabel: label)
batchInputs.append(x)
}
}
catch(let error){
print("error description is \(error.localizedDescription)")
}
}
return MLArrayBatchProvider(array: batchInputs)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment