【发布时间】:2023-04-04 20:18:01
【问题描述】:
在swiftdocumentation中,MLModel有两个预测函数
- func 预测(来自:MLFeatureProvider)-> MLFeatureProvider。根据给定的输入特征值预测输出特征值。
- func 预测(来自:MLFeatureProvider,选项:MLPredictionOptions)-> MLFeatureProvider。根据给定的输入特征值预测输出特征值。
但是,在我自动生成的 MLModel 类中,没有生成带有 options 参数的函数。以下代码是我自动生成的预测函数。
func prediction(input: coreML_1denses_80iters_k213_2Input) throws -> coreML_1denses_80iters_k213_2Output {
let outFeatures = try model.prediction(from: input)
let result = coreML_1denses_80iters_k213_2Output(output1: outFeatures.featureValue(for: "output1")!.multiArrayValue!, lstm_1_h_out: outFeatures.featureValue(for: "lstm_1_h_out")!.multiArrayValue!, lstm_1_c_out: outFeatures.featureValue(for: "lstm_1_c_out")!.multiArrayValue!)
return result
}
func prediction(input1: MLMultiArray, input2: MLMultiArray, lstm_1_h_in: MLMultiArray?, lstm_1_c_in: MLMultiArray?) throws -> coreML_1denses_80iters_k213_2Output {
let input_ = coreML_1denses_80iters_k213_2Input(input1: input1, input2: input2, lstm_1_h_in: lstm_1_h_in, lstm_1_c_in: lstm_1_c_in)
return try self.prediction(input: input_)
}
注意: 顺便说一句,我想找到带有“选项”参数的预测函数的原因是这个错误消息:
[coreml] Cannot evaluate a sequence of length 600, which is longer than maximum of 400.
我发现了一个solution,它在预测函数中添加了一个forceCPU标志。可以在名为“usesCPUOnly”的MLPredictionOptions 中找到该选项。但是,我找不到放置选项的地方。
【问题讨论】: