You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let inputTensor = Tensor<Float>(&imageBuffer, shape: [1, 3, 224, 224])
244
244
245
245
// Execute the 'forward' method with the given input tensor and get an output tensor back.
246
-
let outputTensor: Tensor<Float> = try module.forward(inputTensor)!
246
+
let outputTensor= try Tensor<Float>(module.forward(inputTensor))
247
247
248
248
// Copy the tensor data into logits array for easier access.
249
249
let logits = outputTensor.scalars()
@@ -711,7 +711,10 @@ Inputs can be any type conforming to `ValueConvertible` (like `Tensor`, `Int`, `
711
711
-`forward(_:)`: A convenient shortcut for executing the common "forward" method.
712
712
713
713
The API provides overloads for single inputs, multiple inputs, or no inputs.
714
-
Outputs are always returned as an array of `Value`.
714
+
715
+
Outputs are returned in two ways:
716
+
- As an array of `Value`s, letting you inspect and cast results yourself.
717
+
- As your expected type. The generic overloads decode the result directly into your desired Swift type (such as a single `Tensor<Float>`, an array, or any custom type conforming to the `ValueSequenceConstructible` protocol). If the output doesn’t match the expected type (e.g. multiple Values returned when a single object is expected, or a tensor data type mismatch), an invalid type error is thrown.
715
718
716
719
Objective-C:
717
720
@@ -777,6 +780,10 @@ do {
777
780
let logits = try outputTensor.scalars()
778
781
print("First 5 logits: \(logits.prefix(5))")
779
782
}
783
+
784
+
// Try casting the outputs to a single typed object.
785
+
let tensorOutput = try Tensor<Float>(module.forward(inputTensor1, inputTensor2))
0 commit comments