Amazon Lookout for Vision モデルの開始 - Amazon Lookout for Vision

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

Amazon Lookout for Vision モデルの開始

Amazon Lookout for Vision モデルを使用して異常を検出するには、まずモデルを開始する必要があります。StartModel API を呼び出してモデルを開始し、以下を渡します:

  • ProjectName — 開始するモデルを含むプロジェクトの名前。

  • ModelVersion — 開始するモデルのバージョン。

  • MinInferenceUnits — 推論単位の最小数。詳細については、「推論単位」を参照してください。

  • (オプション) MaxInferenceUnits — Amazon Lookout for Vision がモデルを自動的にスケーリングするために使用できる推論単位の最大数。詳細については、「推論単位数を自動スケーリングする」を参照してください。

Amazon Lookout for Vision コンソールには、モデルの開始と停止に使用できるサンプルコードが用意されています。

注記

モデルの稼働時間に応じて課金されます。実行中のモデルを停止するには、「Amazon Lookout for Vision モデルの停止 」を参照してください。

AWS SDKを使うと、Lookout for Vision を利用可能なすべての AWS リージョンにおける実行モデルを見ることができます。コード例については、find_running_models.py を参照してください。

モデルの開始 (コンソール)

Amazon Lookout for Vision コンソールは、モデルの開始と停止に使用できる AWS CLI コマンドを提供しています。モデルの開始後、画像内の異常の検出を開始できます。詳細については、「画像内の異常を検出する」を参照してください。

モデル(コンソール)を開始するには
  1. まだ行っていない場合は、AWS CLI とAWS SDK をインストールして構成します。詳細については、「ステップ 4: をセットアップする AWS CLI また、 AWS SDKs」を参照してください。

  2. https://console.aws.amazon.com/lookoutvision/ で Amazon Lookout for Vision コンソールを開きます。

  3. [開始する] を選択します。

  4. 左側のナビゲーションペインで、[プロジェクト] を選択します。

  5. [プロジェクト] リソースページで、開始するモデルを含むプロジェクトを選択します。

  6. [モデル] セクションで、開始するモデルを選択します。

  7. モデルの詳細ページで [モデルを使用] を選択し、[API をクラウドに統合] を選択します。

    ヒント

    モデルをエッジデバイスにデプロイする場合は、[モデルパッケージングジョブを作成] を選択します。詳細については、「Amazon Lookout for Vision モデルのパッケージング」を参照してください。

  8. [AWS CLI コマンド] で、AWS呼び出す CLI コマンドstart-modelをコピーします。

  9. コマンドプロンプトで、前のステップでコピーした start-model コマンドを入力します。lookoutvision プロファイルを使用して認証情報を取得する場合は、--profile lookoutvision-access パラメータを追加します。

  10. コンソールで、左のナビゲーションページから[モデル] を選択します。

  11. モデルの現在のステータスは、[ステータス] 欄をチェックします。ステータスが[ホスト済み] の場合、このモデルを使用して画像内の異常を検出できます。詳細については、「画像内の異常を検出する」を参照してください。

Amazon Lookout for Vision モデル (SDK) を開始する

StartModel オペレーションを呼び出してモデルを開始します。

モデルの開始までに時間がかかる場合があります。DescribeModel を呼び出して現在のステータスを確認できます 詳細については、「モデルの表示」を参照してください。

モデル (SDK) を起動するには
  1. まだ行っていない場合は、AWS CLI とAWS SDK をインストールして構成します。詳細については、「ステップ 4: をセットアップする AWS CLI また、 AWS SDKs」を参照してください。

  2. 次のサンプルコードを使用して、モデルを開始します。

    CLI

    以下の値を変更します。

    • project-name に開始したいモデルを含むプロジェクト名を入力します。

    • model-version に開始したいモデルのバージョンを入力します。

    • --min-inference-units で使用する推論単位の数を指定します。

    • (オプション) --max-inference-units を、自動的にモデルをスケーリングするために Amazon Lookout for Vision が使用できる推論単位の最大数に。

    aws lookoutvision start-model --project-name "project name"\ --model-version model version\ --min-inference-units minimum number of units\ --max-inference-units max number of units \ --profile lookoutvision-access
    Python

    このコードは、AWS ドキュメンテーション SDK サンプル GitHub リポジトリから引用されたものです。詳しい事例はこちらです。

    @staticmethod def start_model( lookoutvision_client, project_name, model_version, min_inference_units, max_inference_units = None): """ Starts the hosting of a Lookout for Vision model. :param lookoutvision_client: A Boto3 Lookout for Vision client. :param project_name: The name of the project that contains the version of the model that you want to start hosting. :param model_version: The version of the model that you want to start hosting. :param min_inference_units: The number of inference units to use for hosting. :param max_inference_units: (Optional) The maximum number of inference units that Lookout for Vision can use to automatically scale the model. """ try: logger.info( "Starting model version %s for project %s", model_version, project_name) if max_inference_units is None: lookoutvision_client.start_model( ProjectName = project_name, ModelVersion = model_version, MinInferenceUnits = min_inference_units) else: lookoutvision_client.start_model( ProjectName = project_name, ModelVersion = model_version, MinInferenceUnits = min_inference_units, MaxInferenceUnits = max_inference_units) print("Starting hosting...") status = "" finished = False # Wait until hosted or failed. while finished is False: model_description = lookoutvision_client.describe_model( ProjectName=project_name, ModelVersion=model_version) status = model_description["ModelDescription"]["Status"] if status == "STARTING_HOSTING": logger.info("Host starting in progress...") time.sleep(10) continue if status == "HOSTED": logger.info("Model is hosted and ready for use.") finished = True continue logger.info("Model hosting failed and the model can't be used.") finished = True if status != "HOSTED": logger.error("Error hosting model: %s", status) raise Exception(f"Error hosting model: {status}") except ClientError: logger.exception("Couldn't host model.") raise
    Java V2

    このコードは、AWS ドキュメンテーション SDK サンプル GitHub リポジトリから引用されたものです。詳しい事例はこちらです。

    /** * Starts hosting an Amazon Lookout for Vision model. Returns when the model has * started or if hosting fails. You are charged for the amount of time that a * model is hosted. To stop hosting a model, use the StopModel operation. * * @param lfvClient An Amazon Lookout for Vision client. * @param projectName The name of the project that contains the model that you * want to host. * @modelVersion The version of the model that you want to host. * @minInferenceUnits The number of inference units to use for hosting. * @maxInferenceUnits The maximum number of inference units that Lookout for * Vision can use for automatically scaling the model. If the * value is null, automatic scaling doesn't happen. * @return ModelDescription The description of the model, which includes the * model hosting status. */ public static ModelDescription startModel(LookoutVisionClient lfvClient, String projectName, String modelVersion, Integer minInferenceUnits, Integer maxInferenceUnits) throws LookoutVisionException, InterruptedException { logger.log(Level.INFO, "Starting Model version {0} for project {1}.", new Object[] { modelVersion, projectName }); StartModelRequest startModelRequest = null; if (maxInferenceUnits == null) { startModelRequest = StartModelRequest.builder().projectName(projectName).modelVersion(modelVersion) .minInferenceUnits(minInferenceUnits).build(); } else { startModelRequest = StartModelRequest.builder().projectName(projectName).modelVersion(modelVersion) .minInferenceUnits(minInferenceUnits).maxInferenceUnits(maxInferenceUnits).build(); } // Start hosting the model. lfvClient.startModel(startModelRequest); DescribeModelRequest describeModelRequest = DescribeModelRequest.builder().projectName(projectName) .modelVersion(modelVersion).build(); ModelDescription modelDescription = null; boolean finished = false; // Wait until model is hosted or failure occurs. do { modelDescription = lfvClient.describeModel(describeModelRequest).modelDescription(); switch (modelDescription.status()) { case HOSTED: logger.log(Level.INFO, "Model version {0} for project {1} is running.", new Object[] { modelVersion, projectName }); finished = true; break; case STARTING_HOSTING: logger.log(Level.INFO, "Model version {0} for project {1} is starting.", new Object[] { modelVersion, projectName }); TimeUnit.SECONDS.sleep(60); break; case HOSTING_FAILED: logger.log(Level.SEVERE, "Hosting failed for model version {0} for project {1}.", new Object[] { modelVersion, projectName }); finished = true; break; default: logger.log(Level.SEVERE, "Unexpected error when hosting model version {0} for project {1}: {2}.", new Object[] { projectName, modelVersion, modelDescription.status() }); finished = true; break; } } while (!finished); logger.log(Level.INFO, "Finished starting model version {0} for project {1} status: {2}", new Object[] { modelVersion, projectName, modelDescription.statusMessage() }); return modelDescription; }
  3. コードの出力が Model is hosted and ready for use の場合、このモデルを使用して画像内の異常を検出できます。詳細については、「画像内の異常を検出する」を参照してください。