Posts

Post not yet marked as solved
2 Replies
1.1k Views
I am attempting to load a set of images into Create ML so that I can train an image classifier model. However, when I select the folder that my training data is in, I get the error "No training data found. 0 invalid files found." My data is laid out as such. Parent folder -Training data (Selected in Create ML) -Individuals for each class -Image files -Test data -Individuals for each class -Image files My dataset can be viewed here - https://github.com/ivyjsgit/HOMUS-Bitmap/tree/master/Splitted
Posted
by AprilZion.
Last updated
.
Post not yet marked as solved
1 Replies
453 Views
I am working on an app that classifies drawings made by user. Currently, the user made drawings are represented as a set of SwiftUI Paths, and I have a trained Core ML model that takes images and outputs class names. I have written some code that is able to take in images in the form of UIImages and feed it into my classifier, but I am unsure of how I should adapt my code to take Paths. Here is my current code: import UIKit import CoreML import Vision import ImageIO import SwiftUI struct ImageClassifier{ 		var classifier = SymbolClassifier() 		func classify(image: CGImage) -> String?{ 				let pixelBuffer = image.pixelBuffer(width: 300, height: 300, orientation: CGImagePropertyOrientation.up)! 				let output = try? self.classifier.prediction(image: pixelBuffer) 				return output?.classLabel 		} 		func classifyUIImage(image: UIImage)-> String?{ 				guard let imageAsUIImage:CGImage = convertUIImageToCGImage(image: image) else{ 						return nil 				} 				return classify(image: imageAsUIImage) 		} 		func classifyPath(path:Path) -> String?{ 				//??? 				return nil 		} 		func convertUIImageToCGImage(image: UIImage) -> CGImage? { 				let inputImage = CIImage(image: image)! 				let context = CIContext(options: nil) 				return context.createCGImage(inputImage, from: inputImage.extent) 		} } Here - https://github.com/ivyjsgit/Manuscript-iOS/blob/main/Manuscript/Libraries/CGImage%2BCVPixelBuffer.swift is the image.pixelBuffer library and here - https://github.com/ivyjsgit/Manuscript-iOS/blob/main/Manuscript/Manuscript/SymbolClassifier.mlmodel is the model
Posted
by AprilZion.
Last updated
.
Post not yet marked as solved
10 Replies
1.4k Views
I am currently trying to refactor some of my variables that I am using within a View into a struct for clarity. However, when I try to do this, I get a bunch of errors such as Value of type 'Binding<DrawableStaff>' has no dynamic member 'drawings' using key path from root type 'DrawableStaff'. How do I fix these issues? I have looked into the documentation, and I have looked around online, and I haven't found a solution to this issue. Here is what the refactored struct looks like struct DrawableStaff{ &#9;&#9;var drawing: Drawing = Drawing() &#9;&#9;var drawingList: [Drawing] = [Drawing]() &#9;&#9;var paths: [Path] = [Path]() &#9;&#9;var PathHolder = Path() &#9;&#9;var color = Color.primary &#9;&#9;var lineWidth: CGFloat = 3.0 } Here is where DrawableStaff appears in my main ContentView struct ContentView: View { &#9;&#9;@State private var staff1DrawableStaff = DrawableStaff()&#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;VStack {&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;let staff1 = ZStack{ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;DrawingPad(drawableStaff: $staff1DrawableStaff) &#9;&#9;&#9;&#9;} &#9;&#9;} } Here is where DrawingPad is defined: struct DrawingPad: View { &#9;&#9; &#9;&#9;@Binding var drawableStaff: DrawableStaff &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;GeometryReader { geometry in &#9;&#9;&#9;&#9;&#9;&#9;Path { path in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;for drawing in self.drawableStaff.drawings { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.add(drawing: drawableStaff.drawing, toPath: &path) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.add(drawing: self.drawableStaff.currentDrawing, toPath: &path) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.drawableStaff.pathHolder = path &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;.stroke(self.drawableStaff.color, lineWidth: self.drawableStaff.lineWidth) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(Color(UIColor.systemBackground)) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.gesture( &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;DragGesture(minimumDistance: 0.1) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.onChanged({ (value) in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;let currentPoint = value.location &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;if currentPoint.y >= 0 &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&& currentPoint.y < geometry.size.height { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.drawableStaff.currentDrawing.points.append(currentPoint) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.onEnded({ (value) in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.drawableStaff.drawings.append(self.currentDrawing) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.drawableStaff.currentDrawing = Drawing() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) &#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;.frame(maxHeight: .infinity) &#9;&#9;}     private func add(drawing: Drawing, toPath path: inout Path) {         let points = drawing.points         if points.count > 1 {             for i in 0..<points.count-1 {                 let current = points[i]                 let next = points[i+1]                 path.move(to: current)                 path.addLine(to: next)             }         }     } } Here is my Drawing definition: struct Drawing {     var points: [CGPoint] = [CGPoint]() }
Posted
by AprilZion.
Last updated
.