首页 > 解决方案 > Watson VisualRecognition 无法对图像进行分类,给出错误 400(使用 swift)

问题描述

我正在学习使用 Watson 的 VisualRecognition 服务。应用程序将图像发送到 Watson,然后从 Watson 接收分类结果。它以前工作正常。但是它今天突然停止工作。

let apiKey = "my api key"
let version = "2019-01-01"


func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage{
        SVProgressHUD.show()
        self.cameraButton.isEnabled = false
        self.folderButton.isEnabled = false
        self.ShareButton.isHidden = true
        foodNameIndicatorText.isHidden = true
        foodDescriptionButtonA.isHidden = true
        foodDescriptionButtonB.isHidden = true
        foodDescriptionButtonC.isHidden = true
        //clear the results array everytime users pick an new image
        self.classificationResults = []
        self.foodItemResults = []
        imageView.image = image
        //dismiss the imgPickerController after presented
        imgPickerController.dismiss(animated: true, completion: nil)

        let visualRecognition = VisualRecognition(version: version, apiKey: apiKey)
        visualRecognition.classify(image: image, threshold: 0.0, owners: ["default"], classifierIDs: ["food"], acceptLanguage: "en") { response, error in
            if let error = error {
                print("============================here is error =========================================")
                print(error)
                print("============================end of error =========================================")
            }
            guard let classifiedImages = response?.result else {
                print("Failed to classify the image")
                return
            }
            print(classifiedImages) ......

错误:

http(statusCode: Optional(400), message: nil, metadata: nil)

============================错误结束=================== ================

我尝试创建一个新的 visualRecognition 实例,并根据 Watson 的 IOS 文档使用它的分类方法。我使用的图像参数来自 imagePickerController,我允许用户从库中选择图像。但是,我在响应处理程序中收到错误,并且代码无法对我的图像进行分类。究竟发生了什么?

标签: swiftibm-watsonvisual-recognition

解决方案


如果您使用的是 Lite(免费)计划并且它突然停止工作,我的第一个猜测是您每月使用了 1000 个免费事件,这些事件用于训练和/或分类。否则,您可能应该使用您的帐户实例的详细信息打开 IBM Cloud 客户支持票证。


推荐阅读