{"id":13801078,"url":"https://github.com/watson-developer-cloud/visual-recognition-coreml","last_synced_at":"2025-05-13T11:30:58.097Z","repository":{"id":66139971,"uuid":"124135124","full_name":"watson-developer-cloud/visual-recognition-coreml","owner":"watson-developer-cloud","description":"Classify images offline using Watson Visual Recognition and Core ML","archived":true,"fork":false,"pushed_at":"2019-09-10T16:42:49.000Z","size":185763,"stargazers_count":490,"open_issues_count":5,"forks_count":77,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-02-26T03:35:30.567Z","etag":null,"topics":["core-ml","visual-recognition","watson"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/watson-developer-cloud.png","metadata":{"files":{"readme":"README-cn.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-03-06T20:34:45.000Z","updated_at":"2025-02-22T05:47:36.000Z","dependencies_parsed_at":"2023-03-01T15:45:12.821Z","dependency_job_id":null,"html_url":"https://github.com/watson-developer-cloud/visual-recognition-coreml","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson-developer-cloud%2Fvisual-recognition-coreml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson-developer-cloud%2Fvisual-recognition-coreml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson-developer-cloud%2Fvisual-recognition-coreml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson-developer-cloud%2Fvisual-recognition-coreml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/watson-developer-cloud","download_url":"https://codeload.github.com/watson-developer-cloud/visual-recognition-coreml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253932774,"owners_count":21986446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["core-ml","visual-recognition","watson"],"created_at":"2024-08-04T00:01:19.279Z","updated_at":"2025-05-13T11:30:53.088Z","avatar_url":"https://github.com/watson-developer-cloud.png","language":"Swift","funding_links":[],"categories":["Swift","Data \u0026 AI","Core ML"],"sub_categories":["Repos"],"readme":"*阅读本文的其他语言版本：[English](README.md)。*\r\n\r\n# 支持 Core ML 的 Visual Recognition\r\n\r\n利用 [Watson Visual Recognition](https://www.ibm.com/watson/services/visual-recognition/) 和 [Core ML](https://developer.apple.com/machine-learning/) 对图像进行分类。使用经由 Visual Recognition 训练的深度神经网络脱机对图像进行分类。\r\n\r\n此项目包含 `QuickstartWorkspace.xcworkspace` 工作空间，其中含有以下两个项目：\r\n\r\n- **Core ML Vision Simple**：利用 Visual Recognition 在本地对图像进行分类。\r\n- **Core ML Vision Custom**：训练自定义 Visual Recognition 模型，实现更专业化的分类。\r\n\r\n## 准备工作\r\n\r\n确保已安装 [Xcode 9][xcode_download] 或更高版本以及 iOS 11.0 或更高版本。这些是支持 Core ML 所必需的版本。\r\n\r\n## 获取文件\r\n使用 GitHub 在本地克隆存储库，或者下载存储库的 .zip 文件并解压缩这些文件。\r\n\r\n## 运行 Core ML Vision Simple\r\n通过内置的 Visual Recognition 模型识别常见物体。使用 [Core ML](https://developer.apple.com/documentation/coreml) 框架对图像进行分类。\r\n\r\n1.  在 Xcode 中打开 `QuickstartWorkspace.xcworkspace`。\r\n1.  选择 `Core ML Vision Simple` 模式。\r\n1.  在模拟器或者您的设备上运行应用。\r\n1.  通过点击照相机图标并从照片库中选择照片，对图像进行分类。要将自定义图像添加到模拟器中，请将图像从 Finder 拖到模拟器窗口中。\r\n\r\n**提示**：此项目还包含一个 Core ML 模型，用于对树和真菌进行分类。通过对要在 [ImageClassificationViewController](../master/Core%20ML%20Vision%20Simple/Core%20ML%20Vision%20Simple/ImageClassificationViewController.swift#L35-L39)中使用的模型取消注释，即可在所包含的两个 Core ML 模型之间进行切换。\r\n\r\n`ImageClassificationViewController` 的[源代码](../master/Core%20ML%20Vision%20Simple/Core%20ML%20Vision%20Simple/ImageClassificationViewController.swift)。\r\n\r\n## 运行 Core ML Vision Custom\r\n此项目的第二部分是在第一部分的基础上构建的，可对 Visual Recognition 模型（也称为分类器）进行训练，以识别常见电缆类型（HDMI、USB 等）。使用 [Watson Swift SDK](https://github.com/watson-developer-cloud/swift-sdk) 来下载、管理和执行经过训练的模型。通过使用 Watson Swift SDK，您完全不必了解底层 Core ML 框架。\r\n\r\n### 在 Watson Studio 中设置 Visual Recognition\r\n1.  登录 [Watson Studio][watson_studio_visrec_tooling]。通过此链接，您可以创建一个 IBM Cloud 帐户、注册 Watson Studio 或进行登录。\r\n1.  注册或登录后，将进入 Watson Studio 中的 Visual Recognition 实例概述页面。\r\n\r\n    **提示**：如果在以下任一步骤中迷失方向，请单击页面左上角的 `IBM Watson` 徽标，以转至 Watson Studio 主页。在该主页上，可通过单击“Watson services”下相应服务旁的 **Launch tool** 按钮，访问自己的 Visual Recognition 实例。\r\n\r\n### 训练模型\r\n1.  在 Watson Studio 中的 Visual Recognition 实例概述页面上，单击 Custom 框中的 **Create Model**。\r\n1.  如果尚未将任何项目与您创建的 Visual Recognition 实例关联，将会创建一个项目。请将项目命名为 `Custom Core ML`，然后单击 **Create**。\r\n\r\n    **提示**：如果未定义存储，请单击 **refresh**。\r\n1.  将每个样本图像 .zip 文件从 `Training Images` 目录上传至页面右侧的数据窗格中。单击数据窗格中的 **Browse** 按钮，将 `hdmi_male.zip` 文件添加到模型中。同时将 `usb_male.zip`、`thunderbolt_male.zip` 和 `vga_male.zip` 文件添加到模型中。\r\n1.  上传这些文件后，从每个文件旁的菜单中选择 **Add to model**，然后单击 **Train Model**。\r\n\r\n### 复制模型 ID 和 API 密钥\r\n1.  在 Watson Studio 中的自定义模型概述页面上，单击 Visual Recognition 实例名称（位于 Associated Service 旁）。\r\n1.  向下滚动以查找刚才创建的 **Custom Core ML** 分类器。\r\n1.  复制分类器的 **Model ID**。\r\n1.  在 Watson Studio 中的 Visual Recognition 实例概述页面上，单击 **Credentials** 选项卡，然后单击 **View credentials**。复制服务的 `api_key`。\r\n\r\n### 将 classifierId 和 apiKey 添加到项目中\r\n1.  在 Xcode 中打开项目。\r\n1.  复制 **Model ID**，并将其粘贴到 [ImageClassificationViewController](../master/Core%20ML%20Vision%20Custom/Core%20ML%20Vision%20Custom/ImageClassificationViewController.swift)文件的 **classifierID** 属性中。\r\n1.  复制 **api_key**，并将其粘贴到 [ImageClassificationViewController](../master/Core%20ML%20Vision%20Custom/Core%20ML%20Vision%20Custom/ImageClassificationViewController.swift)文件的 **apiKey** 属性中。\r\n\r\n### 下载 Watson Swift SDK\r\n使用 Cocoapods 依赖关系管理器来下载和构建 Watson Swift SDK。\r\n\r\n1.  安装 [Cocoapods](https://cocoapods.org/)。\r\n1.  打开终端窗口，浏览至 `Core ML Vision Custom` 目录。\r\n1.  运行以下命令以下载和构建 Watson Swift SDK：\r\n\r\n    ```bash\r\n    pod install\r\n    ```\r\n\r\n**提示：** 定期下载 SDK 更新，以便与此项目的任何更新保持同步\r\n\r\n### 测试自定义模型\r\n\r\n1. 在 Xcode 中打开 `QuickstartWorkspace.xcworkspace`。\r\n1. 选择 `Core ML Vision Custom` 模式。\r\n1. 在模拟器或者设备上运行应用。\r\n1. 通过点击照相机图标并从照片库中选择照片，对图像进行分类。要将自定义图像添加到模拟器中，请将图像从 Finder 拖到模拟器窗口中。\r\n1. 通过右下角的 Refresh 按钮，拉取新版本的 Visual Recognition 模型。\r\n\r\n    **提示：** 分类器状态必须为 `Ready` 才能使用。请在 Watson Studio 中的 Visual Recognition 实例概述页面上检查分类器状态。\r\n\r\n`ImageClassificationViewController` 的[源代码](../master/Core%20ML%20Vision%20Custom/Core%20ML%20Vision%20Custom/ImageClassificationViewController.swift)。\r\n\r\n## 后续步骤\r\n\r\n通过 [Core ML Visual Recognition with Discovery][vizreq_with_discovery] 项目，向自定义项目添加另一个 Watson 服务。\r\n\r\n## 资源\r\n\r\n- [Watson Visual Recognition](https://www.ibm.com/watson/services/visual-recognition/)\r\n- [Watson Visual Recognition 工具][vizreq_tooling]\r\n- [Apple 机器学习](https://developer.apple.com/machine-learning/)\r\n- [Core ML 文档](https://developer.apple.com/documentation/coreml)\r\n- [Watson Swift SDK](https://github.com/watson-developer-cloud/swift-sdk)\r\n- [IBM Cloud](https://cloud.ibm.com)\r\n\r\n[vizreq_with_discovery]: https://github.com/watson-developer-cloud/visual-recognition-with-discovery-coreml/\r\n[xcode_download]: https://developer.apple.com/xcode/downloads/\r\n[vizreq_tooling]: https://dataplatform.ibm.com/registration/stepone?context=wdp\u0026apps=watson_studio\u0026target=watson_vision_combined\r\n[watson_studio_visrec_tooling]: https://dataplatform.ibm.com/registration/stepone?target=watson_vision_combined\u0026context=wdp\u0026apps=watson_studio\u0026cm_sp=WatsonPlatform-WatsonPlatform-_-OnPageNavCTA-IBMWatson_VisualRecognition-_-CoreMLGithub\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatson-developer-cloud%2Fvisual-recognition-coreml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwatson-developer-cloud%2Fvisual-recognition-coreml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatson-developer-cloud%2Fvisual-recognition-coreml/lists"}