Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“警告”';init()';已弃用;。[Swift、Ios应用程序、学习模式]_Swift_Ios App Extension - Fatal编程技术网

“警告”';init()';已弃用;。[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()并跳转到它的定义。它

我正在用Swift制作一个图像分类iOS应用程序

当我写作时

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(配置:)并适当处理错误。”)
这不适合你。这可能意味着以下任何情况:

  • 您的ML设置不正确
  • 你的iOS不是最新的

  • 轻松修复: 您只需将其粘贴到项目中:

    扩展挤压网{
    便利初始化(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(配置:)并适当处理错误。”)
    这不适合你。这可能意味着以下任何情况:

  • 您的ML设置不正确
  • 你的iOS不是最新的

  • 轻松修复: 您只需将其粘贴到项目中:

    扩展挤压网{
    便利初始化(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()