Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OCI Vision でらくらく画像解析 / Image Analysis with OCI Vision

OCI Vision でらくらく画像解析 / Image Analysis with OCI Vision

2024/01/12 に行われた Oracle AI Brown Bag Seminar - OCI Vision でらくらく画像解析で用いた資料です

oracle4engineer

January 12, 2024
Tweet

More Decks by oracle4engineer

Other Decks in Technology

Transcript

  1. OCI Visionでらくらく画像解析 Oracle AI Brown Bag Seminar #4 Shuhei Kawamura

    Cloud Architect Oracle Digital, Oracle Corporation Japan January 12, 2024
  2. Copyright © 2024, Oracle and/or its affiliates 2 • 所属

    • ⽇本オラクル株式会社 • Oracle Digital • 普段の業務 • Digital Nativeなお客様を技術⾯でご⽀援 • コミュニティ • OCHaCafe • CloudNative Days – Observability team 川村 修平 (Shuhei Kawamura) @shukawam X/GitHub/Qiita
  3. Copyright © 2024, Oracle and/or its affiliates 3 Agenda 1.

    Vision + Data Labelingの概要 2. Vision + Data Labelingを使いこなす 3. Demo
  4. Copyright © 2024, Oracle and/or its affiliates 4 Oracle AI

    Stack … Machine learning services Data AI services AI infrastructure OCI Data Science ML in Oracle Database MySQL Heatwave AutoML Compute bare metal instances and VMs Cluster networking Block, object, file storage, HPC filesystems Digital Assistant Speech Language Document Understanding Anomaly Detection OCI Generative AI + Business applications, Oracle SaaS portfolio Vision Data Labeling
  5. Copyright © 2024, Oracle and/or its affiliates 5 Oracle AI

    Stack … Machine learning services Data AI services AI infrastructure OCI Data Science ML in Oracle Database MySQL Heatwave AutoML Compute bare metal instances and VMs Cluster networking Block, object, file storage, HPC filesystems Digital Assistant Speech Language Document Understanding Anomaly Detection OCI Generative AI + Business applications, Oracle SaaS portfolio Vision Data Labeling 画像解析 (分類/検出) 学習データセットの作成、管理
  6. Copyright © 2024, Oracle and/or its affiliates 6 デジタルアセットの管理 •

    画像にタグ付けし、インデックス(索引)化することで検索の向上 カタログタギング • シーン内の画像を⼩売カタログの特定の商品と照合 視覚的な異常検出 • 製品や機器の標準品/不良品分類 場⾯の監視 • ⼩売店の棚に商品が存在するか︖ • 送電線の監視画像内に植物が⽣えているか︖ • 配送/出荷のためにトラックが駐⾞可能か︖ • etc. 画像解析のユースケース
  7. Copyright © 2024, Oracle and/or its affiliates 8 • 画像内のシーンベースの特徴やオブジェクトを識別するために使⽤

    • サポートされている機能 • ラベル • 信頼度スコア: ラベルに対する信頼度(0~1)を提供 • オントロジークラス: 意味的な階層構造を提供(e.g. ⽝、猫の上位概念として動物が存在) • Single/Batch リクエスト イメージ分類 AI - Vision Image { "labels": [ { "confidence": 0.9930608, "name": "Vegetation" }, ... ], ... "ontology_classes": [ { "name": "Vegetation", "parent_names": [ "Plant" ], "synonym_names": [] }, ], ... } INLINE (ペイロード内に含める) Buckets OBJECT_STORAGE から参照させる ラベルと信頼度 オントロジークラス
  8. Copyright © 2024, Oracle and/or its affiliates 9 • 画像内の物体の位置を特定し、識別するために使⽤

    • サポートされている機能 • ラベル • 信頼度スコア: ラベルに対する信頼度(0~1)を提供 • オブジェクトのバウンディングボックス(境界線) • Single/Batch リクエスト オブジェクト検出 { "image_objects": [ { "bounding_polygon": { "normalized_vertices": [ {"x": 0.46893491124260356, "y": 0.49473684210526314}, ...] }, "confidence": 0.95109206, "name": "Car" } ], "ontology_classes": [ { "name": "Car", "parent_names": [ "Land vehicle" ], "synonym_names": [] } ], } ラベルと信頼度 オントロジークラス 境界線情報 AI - Vision Image INLINE (ペイロード内に含める) Buckets OBJECT_STORAGE から参照させる
  9. Copyright © 2024, Oracle and/or its affiliates 10 参考: レスポンス・ボディーに含まれるbounding_polygonについて

    "image_objects": [ { "bounding_polygon": { "normalized_vertices": [ { "x": 0.26666666666666666, "y": 0.23115577889447236 }, { "x": 0.7577777777777778, "y": 0.23115577889447236 }, { "x": 0.7577777777777778, "y": 0.8492462311557789 }, { "x": 0.26666666666666666, "y": 0.8492462311557789 } ] }, "confidence": 0.9639679, "name": "Car" }, ... ]
  10. Copyright © 2024, Oracle and/or its affiliates 11 • 画像内から顔を検出するために使⽤

    • サポートされている機能 • 画像内に顔が存在するかどうか • 画像内の顔の位置検出 • 顔のランドマーク(⽬、⿐、⼝)検出 • 顔の視覚的品質(=⽣体認証に適切かどうか) 顔検出 AI - Vision Image { "detected_faces": [ { "bounding_polygon": { "normalized_vertices": [ { "x": 0.4865..., "y": 0.2895... }, ... ] }, "confidence": 0.98381543, "landmarks": [ { "type": "LEFT_EYE", "x": 0.52, "y": 0.40991735 }, ... ], "quality_score": 0.90399426 }, ], } INLINE (ペイロード内に含める) Buckets OBJECT_STORAGE から参照させる 画像内の顔の位置検出 顔の視覚的品質 ランドマーク検出 信頼度
  11. Copyright © 2024, Oracle and/or its affiliates 12 事前トレーニング済モデル •

    Oracleによって、事前に学習された画像解析モデル • 提供モデル︓イメージ分類/オブジェクト検出/顔検出 カスタム・モデル • Data Labelingでラベル付けされたデータセットを⽤いて学習されたモデル • イメージ分類とオブジェクト検出に対応 • ユーザー固有のアイテムの分類や検出を⾏いたい場合に使⽤ • e.g. ブランドロゴの検出、製品のSKU(Stock Keeping Unit)分類、etc. 事前トレーニング済モデルとカスタム・モデル
  12. Copyright © 2024, Oracle and/or its affiliates 13 n ユースケース

    • 機械学習のデータセット構築・管理に n 特⻑ • Web UIベースのシンプルなワークフローで、正解ラベル付け、 データセットの構築・管理が可能 • 画像分類、物体検出、テキスト分類、固有表現抽出、ド キュメント分類のためのラベル付け • 機械学習サービス(Data Science Service、AI Vision Service)からの容易なデータセット読み込み n 価格 (2024年01⽉現在) • 1,000注釈付きのデータレコード/⽉まで無償 • 以降、1,000注釈付きのデータレコード/⽉毎に ¥0.024 参考: Data Labeling 機械学習データのラベル付けとデータセットの管理 物体検出のラベル付け データセットの管理
  13. Copyright © 2024, Oracle and/or its affiliates 14 1. Data

    Labelingを⽤いてDataset^1 を作成する • 検出するラベルごとに最低でも10枚、理想的には50枚以上の画像を⽤意することが望ましい • 良いデータセットを作成するためのプラクティスが掲載されています • https://docs.oracle.com/en-us/iaas/Content/vision/using/dataset_create.htm 2. Visionで作成済みのDatasetを指定し、学習を⾏う • トレーニング期間 • 推奨トレーニング: 最適なトレーニング期間(最⼤で24時間)を⾃動的に選択し、モデルを作成 • クイックトレーニング: 約1時間で利⽤可能なモデルを作成 • カスタムトレーニング: 最⼤のトレーニング時間を設定し、モデルを作成 [^1]: モデルの学習に⽤いるラベル付きの画像データの集合 カスタム・モデルの作成 AI – Vision (Custom Model) AI – Vision Data Labeling . |- image01.png |- image02.png |- image03.png |- … 学習 Object Storage
  14. Copyright © 2024, Oracle and/or its affiliates 15 制限 制限値

    受け⼊れ可能なファイル形式 JPEG or PNG 最⼤ファイル・サイズ Single/Batchリクエストともに5MB/image 最⼤イメージ数 Singleリクエスト … 1枚 Batchリクエスト … 2,000枚 (各リクエスト・ボディーは500KB以内) 最⼩/最⼤解像度 32 * 32px / 10,000 * 10,000px 保留中状態の⾮同期ジョブの最⼤数 200/tenancy 事前トレーニング済モデルの同期トランザクションの最⼤数 Ashburn, Phoenix, London … 10 TPS Other … 5 TPS 主な制限事項 その他の制限事項: https://docs.oracle.com/en-us/iaas/Content/vision/using/limits.htm
  15. Copyright © 2024, Oracle and/or its affiliates 16 画像解析アプリケーションのアーキテクチャ例 OCI

    Region Load Balancer MySQL Database System Application Application Application Object Storage Events AI – Vision (Custom Model) User Oracle Analytics Cloud Functions 1 1 2 3 4 5 6 7 7 1. 画像を含めてリクエスト 2. Object Storageに画像を格納 3. Objectの作成を検知 4. Functionsを起動 5. VisionのAPIを実⾏ 6. 実⾏結果を永続化 7. 永続化したデータをアプリケー ションから参照 or 分析ワーク ロードに活⽤
  16. Copyright © 2024, Oracle and/or its affiliates 17 Vision +

    Data Labelingを使いこなす w/ OCI SDK for Python
  17. Copyright © 2024, Oracle and/or its affiliates 18 • OCI

    Console • REST API • https://docs.oracle.com/en-us/iaas/api/ - /en/vision/20220125/ • CLI • https://docs.oracle.com/en-us/iaas/tools/oci-cli/3.37.1/oci_cli_docs/cmdref/ai-vision.html • SDK(Software Development Kits) • Java - https://github.com/oracle/oci-java-sdk • Python - https://github.com/oracle/oci-python-sdk // 今⽇はコレ • TypeScript and JavaScript - https://github.com/oracle/oci-typescript-sdk • .NET - https://github.com/oracle/oci-dotnet-sdk • Go - https://github.com/oracle/oci-go-sdk • Ruby - https://github.com/oracle/oci-ruby-sdk • PL/SQL - https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/plsqlsdk.htm OCI Visionを扱う⽅法
  18. Copyright © 2024, Oracle and/or its affiliates 19 環境 •

    Python: 3.11 • SDK for Python: 2.118.0 今⽇の前提 from oci.config import from_file from oci.ai_vision import AIServiceVisionClient from oci.ai_vision.models import ( AnalyzeImageDetails, ImageClassificationFeature, InlineImageDetails, ObjectStorageImageDetails, ObjectLocation, CreateImageJobDetails, ObjectListInlineInputLocation, OutputLocation, ImageObjectDetectionFeature, FaceDetectionFeature ) config = from_file() vision_client = AIServiceVisionClient(config = config) ↑ 今⽇使うコードはこちら
  19. Copyright © 2024, Oracle and/or its affiliates 20 リクエスト・ペイロード中に画像ファイルを含め、同期処理で分類を⾏う イメージ分類(事前トレーニング済モデル)

    image_classification_analyze_details = AnalyzeImageDetails( features = [ ImageClassificationFeature( feature_type = "IMAGE_CLASSIFICATION” ) ], image = InlineImageDetails( source = "INLINE", data = base64.b64encode(image_file).decode('utf-8’) ), compartment_id = COMPARTMENT_ID, ) image_classification_response = vision_client.analyze_image( analyze_image_details = image_classification_analyze_details ) { "labels": [ { "confidence": 0.9930608, "name": "Vegetation" }, ... ], ... "object_detection_model_version": null, "ontology_classes": [ { "name": "Vegetation", "parent_names": [ "Plant" ], "synonym_names": [] }, ], ... }
  20. Copyright © 2024, Oracle and/or its affiliates 21 オブジェクト・ストレージから画像を参照させ、同期処理で分類を⾏う イメージ分類(事前トレーニング済モデル)

    image_classification_analyze_details = AnalyzeImageDetails( features = [ ImageClassificationFeature( feature_type = "IMAGE_CLASSIFICATION", ) ], image = ObjectStorageImageDetails( source = "OBJECT_STORAGE", namespace_name = NAMESPACE, bucket_name = BUCKET_NAME, object_name = OBJECT_NAME ), compartment_id = COMPARTMENT_ID, ) image_classification_response = vision_client.analyze_image( analyze_image_details = image_classification_analyze_details ) { "labels": [ { "confidence": 0.9930608, "name": "Vegetation" }, ... ], ... "object_detection_model_version": null, "ontology_classes": [ { "name": "Vegetation", "parent_names": [ "Plant" ], "synonym_names": [] }, ], ... }
  21. Copyright © 2024, Oracle and/or its affiliates 22 オブジェクト・ストレージから画像を参照させ、⾮同期処理で分類を⾏う イメージ分類(事前トレーニング済モデル)

    create_image_job_details = CreateImageJobDetails( features = [ ImageClassificationFeature( feature_type = "IMAGE_CLASSIFICATION", ) ], input_location = ObjectListInlineInputLocation( source_type = "OBJECT_LIST_INLINE_INPUT_LOCATION", object_locations = object_locations ), output_location = OutputLocation( namespace_name = NAMESPACE, bucket_name = BUCKET_NAME, prefix = f"batch_job_result_{now}" ), compartment_id = COMPARTMENT_ID, display_name = f"ImageClassificationBatchJob-{now}" ) batch_job_response = vision_client.create_image_job( create_image_job_details = create_image_job_details ) { "labels": [ { "confidence": 0.9930608, "name": "Vegetation" }, ... ], ... "object_detection_model_version": null, "ontology_classes": [ { "name": "Vegetation", "parent_names": [ "Plant" ], "synonym_names": [] }, ], ... } ※実際には、結果はバケットに出⼒されます
  22. Copyright © 2024, Oracle and/or its affiliates 23 リクエスト・ペイロード中に画像ファイルを含め、同期処理で検出を⾏う オブジェクト検出(事前学習済みモデル)

    object_detection_analyze_details = AnalyzeImageDetails( features = [ ImageObjectDetectionFeature( feature_type = "OBJECT_DETECTION", ) ], image = InlineImageDetails( source = "INLINE", data = base64.b64encode(image_file).decode('utf-8’) ), compartment_id = COMPARTMENT_ID, ) object_detection_analyze_details = vision_client.analyze_image( analyze_image_details = object_detection_analyze_details ) { "image_objects": [ { "bounding_polygon": { "normalized_vertices": [ {"x": 0.46893491124260356, "y": 0.49473684210526314}, ... ] }, "confidence": 0.95109206, "name": "Car" } ], "ontology_classes": [ { "name": "Car", "parent_names": [ "Land vehicle" ], "synonym_names": [] } ], }
  23. Copyright © 2024, Oracle and/or its affiliates 24 オブジェクト・ストレージから画像を参照させ、同期処理で分類を⾏う オブジェクト検出(事前学習済みモデル)

    object_detection_analyze_details = AnalyzeImageDetails( features = [ ImageObjectDetectionFeature( feature_type = "OBJECT_DETECTION", ) ], image = ObjectStorageImageDetails( source = "OBJECT_STORAGE", namespace_name = NAMESPACE, bucket_name = BUCKET_NAME, object_name = OBJECT_NAME ), compartment_id = COMPARTMENT_ID, ) object_detection_analyze_response = vision_client.analyze_image( analyze_image_details = object_detection_analyze_details ) { "image_objects": [ { "bounding_polygon": { "normalized_vertices": [ {"x": 0.46893491124260356, "y": 0.49473684210526314}, ... ] }, "confidence": 0.95109206, "name": "Car" } ], "ontology_classes": [ { "name": "Car", "parent_names": [ "Land vehicle" ], "synonym_names": [] } ], }
  24. Copyright © 2024, Oracle and/or its affiliates 25 オブジェクト・ストレージから画像を参照させ、⾮同期処理で分類を⾏う オブジェクト検出(事前学習済みモデル)

    create_image_job_details = CreateImageJobDetails( features = [ ImageObjectDetectionFeature( feature_type = "OBJECT_DETECTION", ) ], input_location = ObjectListInlineInputLocation( source_type = "OBJECT_LIST_INLINE_INPUT_LOCATION", object_locations = object_locations ), output_location = OutputLocation( namespace_name = NAMESPACE, bucket_name = BUCKET_NAME, prefix = f"batch_job_result_{now}" ), compartment_id = COMPARTMENT_ID, display_name = f"ObjectDetectionBatchJob-{now}" ) batch_job_response = vision_client.create_image_job( create_image_job_details = create_image_job_details ) ※実際には、結果はバケットに出⼒されます { "image_objects": [ { "bounding_polygon": { "normalized_vertices": [ {"x": 0.46893491124260356, "y": 0.49473684210526314}, ... ] }, "confidence": 0.95109206, "name": "Car" } ], "ontology_classes": [ { "name": "Car", "parent_names": [ "Land vehicle" ], "synonym_names": [] } ], }
  25. Copyright © 2024, Oracle and/or its affiliates 26 リクエスト・ペイロード中に画像ファイルを含め、同期処理で検出を⾏う 顔検出(事前学習済みモデル)

    face_detection_analyze_details = AnalyzeImageDetails( features = [ FaceDetectionFeature( feature_type = "FACE_DETECTION", should_return_landmarks = True ) ], image = InlineImageDetails( source = "INLINE", data = base64.b64encode(image_file).decode('utf-8’) ), compartment_id = COMPARTMENT_ID, ) face_detection_analyze_details = vision_client.analyze_image( analyze_image_details = face_detection_analyze_details ) { "detected_faces": [ { "bounding_polygon": { "normalized_vertices": [ { "x": 0.4865..., "y": 0.2895... }, ... ] }, "confidence": 0.98381543, "landmarks": [ { "type": "LEFT_EYE", "x": 0.52, "y": 0.40991735 }, ... ], "quality_score": 0.90399426 }, ], }
  26. Copyright © 2024, Oracle and/or its affiliates 27 オブジェクト・ストレージから画像を参照させ、同期処理で分類を⾏う 顔検出(事前学習済みモデル)

    face_detection_analyze_details = AnalyzeImageDetails( features = [ FaceDetectionFeature( feature_type = "FACE_DETECTION", ) ], image = ObjectStorageImageDetails( source = "OBJECT_STORAGE", namespace_name = NAMESPACE, bucket_name = BUCKET_NAME, object_name = OBJECT_NAME ), compartment_id = COMPARTMENT_ID, ) face_detection_analyze_response = vision_client.analyze_image( analyze_image_details = face_detection_analyze_details ) { "detected_faces": [ { "bounding_polygon": { "normalized_vertices": [ { "x": 0.4865..., "y": 0.2895... }, ... ] }, "confidence": 0.98381543, "landmarks": [ { "type": "LEFT_EYE", "x": 0.52, "y": 0.40991735 }, ... ], "quality_score": 0.90399426 }, ], }
  27. Copyright © 2024, Oracle and/or its affiliates 28 オブジェクト・ストレージから画像を参照させ、⾮同期処理で分類を⾏う 顔検出(事前学習済みモデル)

    create_image_job_details = CreateImageJobDetails( features = [ FaceDetectionFeature( feature_type = "FACE_DETECTION", ) ], input_location = ObjectListInlineInputLocation( source_type = "OBJECT_LIST_INLINE_INPUT_LOCATION", object_locations = object_locations ), output_location = OutputLocation( namespace_name = NAMESPACE, bucket_name = BUCKET_NAME, prefix = f"batch_job_result_{now}" ), compartment_id = COMPARTMENT_ID, display_name = f"ObjectDetectionBatchJob-{now}" ) batch_job_response = vision_client.create_image_job( create_image_job_details = create_image_job_details ) ※実際には、結果はバケットに出⼒されます { "detected_faces": [ { "bounding_polygon": { "normalized_vertices": [ { "x": 0.4865..., "y": 0.2895... }, ... ] }, "confidence": 0.98381543, "landmarks": [ { "type": "LEFT_EYE", "x": 0.52, "y": 0.40991735 }, ... ], "quality_score": 0.90399426 }, ], }
  28. Copyright © 2024, Oracle and/or its affiliates 29 *Featuresに作成済みのmodel_idを含めればOK カスタム・モデルを使う場合

    image_classification_analyze_details = AnalyzeImageDetails( features = [ ImageClassificationFeature( feature_type = "IMAGE_CLASSIFICATION”, model_id = custom_model_id ) ], image = InlineImageDetails( source = "INLINE", data = base64.b64encode(image_file).decode('utf-8’) ), compartment_id = COMPARTMENT_ID, ) image_classification_response = vision_client.analyze_image( analyze_image_details = image_classification_analyze_details ) { "labels": [ { "confidence": 0.9930608, "name": "Vegetation" }, ... ], ... "object_detection_model_version": null, "ontology_classes": [ { "name": "Vegetation", "parent_names": [ "Plant" ], "synonym_names": [] }, ], ... }
  29. Copyright © 2024, Oracle and/or its affiliates 31 Demo: カスタム・モデルを⽤いたレモンの出荷判定

    OCI Region … API Gateway OCI Functions (Python) AI – Vision (Custom Model) Oracle Autonomous Database { ”result”: “good_quality”, “confidence”: 0.98 } Oracle Analytics Cloud