This file contains hidden or 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
let pdfDocument = PDFDocument() | |
for i in 0 ..< scan.pageCount { | |
if let image = scan.imageOfPage(at: i).resize(toWidth: 250){ | |
let pdfPage = PDFPage(image: image) | |
pdfDocument.insert(pdfPage!, at: i) | |
} | |
} |
This file contains hidden or 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
let config = UIImage.SymbolConfiguration(textStyle: .largeTitle) | |
UIImage(systemName: "paperplane", withConfiguration : config) |
This file contains hidden or 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
let fileManager = FileManager.default | |
let documentDirectory = try fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor:nil, create:true) | |
let modelURL = documentDirectory.appendingPathComponent("CatDog.mlmodelc") |
This file contains hidden or 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) |
This file contains hidden or 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
func predict(image: UIImage) -> Animal? { | |
let imageConstraint = model.modelDescription.inputDescriptionsByName["image"]!.imageConstraint! | |
do{ | |
let imageOptions: [MLFeatureValue.ImageOption: Any] = [ | |
.cropAndScale: VNImageCropAndScaleOption.scaleFill.rawValue | |
] | |
let featureValue = try MLFeatureValue(cgImage: image.cgImage!, constraint: imageConstraint, options: imageOptions) |
This file contains hidden or 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 loadModel(url: URL) -> MLModel? { | |
do { | |
let config = MLModelConfiguration() | |
config.computeUnits = .all | |
return try MLModel(contentsOf: url, configuration: config) | |
} catch { | |
print("Error loading model: \(error)") | |
return nil | |
} | |
} |
This file contains hidden or 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
let updateTask = try MLUpdateTask(forModelAt: updatableModelURL, trainingData: trainingData, configuration: model.configuration, completionHandler: { context in | |
} | |
updateTask.resume() |