我的 xcode 项目中有多个 .mlModel,我希望用户选择模型并执行预测
let gestureClassifier = GestureClassifier() //mlModel
func predictGesture(window: Int) {
let previousOutput = modelOutputs[window]
let modelOutput = try? gestureClassifier.prediction(features: modelInput, hiddenIn: previousOutput?.hiddenOut, cellIn: previousOutput?.cellOut)
modelOutputs[window] = modelOutput
if let prediction = modelOutput?.activity,
let probability = modelOutput?.activityProbability[prediction] {
if prediction == Config.restItValue {
return
}
if probability > Config.predictionThreshold {
if prediction == Config.chopItValue || prediction == Config.driveItValue || prediction == Config.shakeItValue {
print("prediction: \(prediction)")
self.recordGestures(gesture: prediction)
}
}
else{
print("unrecognised gesture")
self.recordGestures(gesture: "unRecognised Gesture")
}
}
}
我有另一个模型gestureClassifier1 我想做这样的事情
func predictGesture(window: Int, **selectedModel**) {
let previousOutput = modelOutputs[window]
let modelOutput = try? **selectedModel**.prediction(features: modelInput, hiddenIn:
previousOutput?.hiddenOut, cellIn: previousOutput?.cellOut)
}
我怎样才能做到这一点,我尝试使用 Anyclass 作为数据类型,但无法访问诸如 .prediction(..) 之类的类函数。