Day 12: ML APIs | Google Cloud

Practice

Quest-Integrate with Machine Learning APIs

Lab-Extract, Analyze, and Translate Text from Images with the Cloud ML APIs
  • ID: GSP075
  • Cloud Vision API's text detection method
    • 使用 OCR 从图片提取文字
  • Translation API
    • 翻译文字
  • Natural Language API
    • 分析文字
Steps:
1. Create an API Key
  • Cloud Console中,依序点选
    Navigation Menu > APIs & services > Credentials

  • + Create Credentials > 下拉选单选 API key

  • Copy key 後按Close

  • 把Key加入环境变数

export API_KEY=<YOUR_API_KEY>


2. Upload an image to a cloud storage bucket

image: sign.jpg 为侦测目标

  • Search Storage
  • Create Bucket
  • Setting
  • Create
  • 上传档案到Cloud Stotage

  • 设定档案权限为公开


3. Create Vision API request

{
  "requests": [
      {
        "image": {
          "source": {
              "gcsImageUri": "gs://my-bucket-name/sign.jpeg"
          }
        },
        "features": [
          {
            "type": "TEXT_DETECTION",
            "maxResults": 10
          }
        ]
      }
  ]
}

4. Call the Vision API's text detection method

在Cloud shell中,使用curl call the Vision API

curl -s -X POST -H "Content-Type: application/json" --data-binary @ocr-request.json  https://vision.googleapis.com/v1/images:annotate?key=${API_KEY}

可以看到:
[更正-my bucket name为project id]


由於输出太长,可以输出到文字档内

5. Sending text from the image to the Translation API
  • 将图片撷取的文字交由Translation API进行翻译
  • 建立translation-request.json
  • 使用上一步骤输出的文字挡xxxresponse.json

  • Call the Translation API
6. Analyzing the image's text with the Natural Language API

Summary:

上传图片到Cloud Storage,
使用Vision API撷取文字,
将撷取出来的文字存到文字档(.json),
接着使用Translation API可以知道是哪国语言,
并翻译成target(范例为en:english),
同样地把翻译好的结果存在文字档,
建立Natural Language API 的request JSON档,
将翻译好的存档输入刚建的request,
再call api得每个word的分析(分类)。


<<:  Day 12 Docker的简单介绍

>>:  Day 14 | Flutter 基本介绍

【Day 11】For 回圈

前言 今天要来介绍一点 for 回圈,因为接下来的 list 会用到!会介绍一些基本的 for 的用...

损失函数的演进--3

接下来在2017年,为了要解决人脸辨识常见的资料不均衡的问题,使用weight和feature no...

[Day8] Git学习笔记 -RE篇(MacOS)

前面两天整理的笔记主要都在建立新的东西 今天就把修改用的指令做整理 1. revert - 重做上个...

安装开发环境-Visual Studio Code

开发环境可以使用的有很多,选择一个适合自己,能够让自己方便、习惯使用的就好。 由於去年开始写line...

Flutter基础介绍与实作-Day4 Dart语法介绍(1)

Dart是属於物件导向的语言,类似Java、JavaScript,如果大家之前有学过就不用太担心了。...