“警告”';init()';已弃用;。[Swift、Ios应用程序、学习模式]
我正在用Swift制作一个图像分类iOS应用程序 当我写作时“警告”';init()';已弃用;。[Swift、Ios应用程序、学习模式],swift,ios-app-extension,Swift,Ios App Extension,我正在用Swift制作一个图像分类iOS应用程序 当我写作时 guard let model = try? VNCoreMLModel(for: SqueezeNet().model) else { return } 我收到了这个警告 'init()' is deprecated: Use init(configuration:) instead and handle errors appropriately. 你知道怎么摆脱它吗?真奇怪。右键单击SqueezeNet()并跳转到它的定义。它
guard let model = try? VNCoreMLModel(for: SqueezeNet().model) else { return }
我收到了这个警告
'init()' is deprecated: Use init(configuration:) instead and handle errors appropriately.
你知道怎么摆脱它吗?真奇怪。右键单击
SqueezeNet()
并跳转到它的定义。它会带你去上课
查找类的init()
方法。在您的SqueezeNet
类中应该是这样的:
/**
通过从应用程序包中自动加载模型来构建SqueezeNet实例。
*/
@可用(*,已弃用,消息:“改用init(配置:)并适当处理错误。”)
便利初始化(){
try!self.init(contentsOf:type(of:self).urlOfModelInThisBundle)
}
我不确定您是如何设置ML的,但它似乎是:
@available(*,已弃用,消息:“改用init(配置:)并适当处理错误。”)
轻松修复: 您只需将其粘贴到项目中:
扩展挤压网{
便利初始化(foo:Void){
try!self.init(contentsOf:type(of:self).urlOfModelInThisBundle)
}
}
然后,按如下方式编辑代码:
guard let model=try?VNCoreMLModel(for:squezenet(()).model)else{return}
它不应该工作得很好。如果没有,请告诉我。真奇怪。右键单击
SqueezeNet()
并跳转到它的定义。它会带你去上课
查找类的init()
方法。在您的SqueezeNet
类中应该是这样的:
/**
通过从应用程序包中自动加载模型来构建SqueezeNet实例。
*/
@可用(*,已弃用,消息:“改用init(配置:)并适当处理错误。”)
便利初始化(){
try!self.init(contentsOf:type(of:self).urlOfModelInThisBundle)
}
我不确定您是如何设置ML的,但它似乎是:
@available(*,已弃用,消息:“改用init(配置:)并适当处理错误。”)
轻松修复: 您只需将其粘贴到项目中:
扩展挤压网{
便利初始化(foo:Void){
try!self.init(contentsOf:type(of:self).urlOfModelInThisBundle)
}
}
然后,按如下方式编辑代码:
guard let model=try?VNCoreMLModel(for:squezenet(()).model)else{return}
它不应该工作得很好。如果没有,请告诉我。如消息所述,
init()
已被弃用。新的初始值设定项接受一个配置参数。默认配置可能适合您,在这种情况下,您可以将SqueezeNet()
替换为:
SqueezeNet(configuration: MLModelConfiguration())
如消息所述,
init()
已被弃用。新的初始值设定项接受一个配置参数。默认配置可能适合您,在这种情况下,您可以将SqueezeNet()
替换为:
SqueezeNet(configuration: MLModelConfiguration())
对我来说,一个苹果示例项目的代码是:
guard let mlModel = try? YOLOv3(configuration: .init()).model,
let model = try? VNCoreMLModel(for: mlModel) else {
print("Failed to load detector!")
return
这是给我警告的代码:
guard let model = try? VNCoreMLModel(for: YOLOv3().model) else {
print("Could not load model")
return
对我来说,一个苹果示例项目的代码是:
guard let mlModel = try? YOLOv3(configuration: .init()).model,
let model = try? VNCoreMLModel(for: mlModel) else {
print("Failed to load detector!")
return
这是给我警告的代码:
guard let model = try? VNCoreMLModel(for: YOLOv3().model) else {
print("Could not load model")
return
错误信息非常清楚。您应该使用
SqueezeNet(配置:)
而不是SqueezeNet()
。错误信息非常清楚。您应该使用SqueezeNet(配置:)
而不是SqueezeNet()
。