Created
May 26, 2021 05:51
-
-
Save iosdevie/a34d088fbbef03d0022e396825858c65 to your computer and use it in GitHub Desktop.
Create a batch provider CoreML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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