Skip to content

Commit

Permalink
Helper function to predict from image URL
Browse files Browse the repository at this point in the history
Handy for CLI tests
  • Loading branch information
pcuenca committed Sep 10, 2024
1 parent 5ef523b commit f30136e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion SAM2-Demo/Common/SAM2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,17 @@ class SAM2: ObservableObject {
let encoding = try model.prediction(image: pixelBuffer)
self.imageEncodings = encoding
}


func getImageEncoding(from url: URL) async throws {
guard let model = imageEncoderModel else {
throw SAM2Error.modelNotLoaded
}

let inputs = try sam2_small_image_encoderInput(imageAt: url)
let encoding = try await model.prediction(input: inputs)
self.imageEncodings = encoding
}

func getPromptEncoding(from allPoints: [SAMPoint], with size: CGSize) async throws {
guard let model = promptEncoderModel else {
throw SAM2Error.modelNotLoaded
Expand Down

0 comments on commit f30136e

Please sign in to comment.