Skip to content

Commit 0ddd2ba

Browse files
authored
Use native Swift APIs (#25)
1 parent 96c602d commit 0ddd2ba

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

mv3/apple/ExecuTorchDemo/ExecuTorchDemo.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@
796796
isa = XCRemoteSwiftPackageReference;
797797
repositoryURL = "https://github.com/pytorch/executorch";
798798
requirement = {
799-
branch = "swiftpm-0.7.0.20250523";
799+
branch = "swiftpm-0.6.0";
800800
kind = branch;
801801
};
802802
};

mv3/apple/ExecuTorchDemo/ExecuTorchDemo/Sources/MobileNet/MobileNetClassifier.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ import UIKit
1313
import os.log
1414

1515
public enum MobileNetClassifierError: Error {
16-
case inference
1716
case rawData
1817
case transform
1918

2019
var localizedDescription: String {
2120
switch self {
22-
case .inference:
23-
return "Cannot recognize the image"
2421
case .rawData:
2522
return "Cannot get the pixel data from the image"
2623
case .transform:
@@ -62,9 +59,9 @@ public class MobileNetClassifier: ImageClassification {
6259
let input = try normalize(rawData(from: transformed(image))).withUnsafeBytes {
6360
Tensor(bytes: $0.baseAddress!, shape: [1, 3, 224, 224], dataType: .float)
6461
}
65-
guard let output = try module.forward(input).first?.tensor?.withUnsafeBytes([Float].init)
66-
else {
67-
throw MobileNetClassifierError.inference
62+
var output: [Float] = []
63+
try module.forward(input).first?.tensor?.bytes { pointer, count, _ in
64+
output = Array(UnsafeBufferPointer(start: pointer.assumingMemoryBound(to: Float.self), count: count))
6865
}
6966
return softmax(output)
7067
.enumerated()

0 commit comments

Comments
 (0)