Avvio del modello Amazon Lookout for Vision - Amazon Lookout per Vision

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Avvio del modello Amazon Lookout for Vision

Prima di poter utilizzare un modello Amazon Lookout for Vision per rilevare anomalie, devi prima avviare il modello. Puoi avviare un modello chiamando l'StartModelAPI e passando quanto segue:

  • ProjectName— Il nome del progetto che contiene il modello che desiderate avviare.

  • ModelVersion— La versione del modello che si desidera avviare.

  • MinInferenceUnits— Il numero minimo di unità di inferenza. Per ulteriori informazioni, consulta Unità di inferenza.

  • (Facoltativo) MaxInferenceUnits: il numero massimo di unità di inferenza che Amazon Lookout for Vision può utilizzare per ridimensionare automaticamente il modello. Per ulteriori informazioni, consulta Unità di inferenza con scalabilità automatica.

La console Amazon Lookout for Vision fornisce codice di esempio che puoi usare per avviare e interrompere un modello.

Nota

Ti viene addebitato il tempo di funzionamento del modello. Per interrompere l'esecuzione di un modello, vedereInterruzione del modello Amazon Lookout for Vision.

Puoi utilizzare l'AWSSDK per visualizzare i modelli in esecuzione in tutte le AWS regioni in cui è disponibile Lookout for Vision. Per esempio di codice, vedi find_running_models.py.

Avvio del modello (console)

La console Amazon Lookout for Vision fornisce AWS CLI un comando che puoi usare per avviare un modello. Dopo l'avvio del modello, puoi iniziare a rilevare anomalie nelle immagini. Per ulteriori informazioni, consulta Rilevamento di anomalie in un'immagine.

Per avviare un modello (console)
  1. Se non l'hai già fatto, installa e configura gli AWS CLI AWS SDK. Per ulteriori informazioni, consulta Fase 4: Configurare gli SDK AWS CLI e AWS.

  2. Apri la console Amazon Lookout for Vision all'indirizzo https://console.aws.amazon.com/lookoutvision/.

  3. Scegli Inizia.

  4. Nel riquadro di navigazione a sinistra, scegli Progetti.

  5. Nella pagina delle risorse dei progetti, scegli il progetto che contiene il modello addestrato che desideri avviare.

  6. Nella sezione Modelli, scegli il modello che desideri avviare.

  7. Nella pagina dei dettagli del modello, scegli Usa modello, quindi scegli Integrate API to the cloud.

    Suggerimento

    Se desideri distribuire il tuo modello su un dispositivo edge, scegli Create model packaging job. Per ulteriori informazioni, consulta Imballaggio del modello Amazon Lookout for Vision.

  8. Nei comandi CLI di AWS, copia il comando AWS CLI che chiama. start-model

  9. Al prompt dei comandi, inserisci il start-model comando che hai copiato nel passaggio precedente. Se utilizzate il lookoutvision profilo per ottenere le credenziali, aggiungete il parametro. --profile lookoutvision-access

  10. Nella console, scegli Modelli nella pagina di navigazione a sinistra.

  11. Controlla la colonna Stato per lo stato attuale del modello. Quando lo stato è Ospitato, puoi utilizzare il modello per rilevare anomalie nelle immagini. Per ulteriori informazioni, consulta Rilevamento di anomalie in un'immagine.

Avvio del modello Amazon Lookout for Vision (SDK)

Si avvia un modello chiamando l'StartModeloperazione.

L'avvio di un modello potrebbe richiedere alcuni istanti. Puoi controllare lo stato attuale chiamando DescribeModel. Per ulteriori informazioni, consulta Visualizzazione dei modelli.

Per avviare il modello (SDK)
  1. Se non l'hai già fatto, installa e configura gli AWS CLI AWS SDK. Per ulteriori informazioni, consulta Fase 4: Configurare gli SDK AWS CLI e AWS.

  2. Usa il seguente codice di esempio per avviare un modello.

    CLI

    Modificate i seguenti valori:

    • project-nameal nome del progetto che contiene il modello che desiderate avviare.

    • model-versionalla versione del modello che si desidera avviare.

    • --min-inference-unitsal numero di unità di inferenza che si desidera utilizzare.

    • (Facoltativo) --max-inference-units fino al numero massimo di unità di inferenza che Amazon Lookout for Vision può utilizzare per ridimensionare automaticamente il modello.

    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

    Questo codice è tratto dall'archivio degli esempi di AWS Documentation SDK. GitHub Vedi l'esempio completo qui.

    @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

    Questo codice è tratto dal GitHub repository degli esempi di AWS Documentation SDK. Vedi l'esempio completo qui.

    /** * 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. Se l'output del codice èModel is hosted and ready for use, puoi utilizzare il modello per rilevare anomalie nelle immagini. Per ulteriori informazioni, consulta Rilevamento di anomalie in un'immagine.