TensorBoard 使用 get_app_url函數作為estimator類別方法開啟 - Amazon SageMaker

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

TensorBoard 使用 get_app_url函數作為estimator類別方法開啟

如果您正在執行使用 SageMaker Python estimator類別的訓練任務,SDK且具有estimator類別的作用中物件,您也可以使用estimator類別的get_app_url類別方法存取函數。透過URL執行 get_app_url方法開啟 TensorBoard 應用程式或擷取未簽署的 ,如下所示。get_app_url 類別方法會從估算器提取訓練任務名稱,並使用指定的任務開啟 TensorBoard 應用程式。

注意

此功能可在 SageMaker Python v2SDK.184.0 及更新版本中使用。若要使用此功能,請務必執行 SDK來升級 pip install sagemaker --upgrade

選項 1:適用於 SageMaker Studio Classic

開啟 TensorBoard 應用程式

下列程式碼會自動從 get_app_url()方法在環境的預設 Web 瀏覽器中傳回URL的未簽署 開啟 TensorBoard 應用程式。

estimator.get_app_url( app_type=SupportedInteractiveAppTypes.TENSORBOARD # Required. )

若要擷取未簽署的應用程式URL,並手動開啟 TensorBoard應用程式

下列程式碼會列印未簽署的 URL ,您可以複製到 Web 瀏覽器並開啟 TensorBoard 應用程式。

print( estimator.get_app_url( app_type=SupportedInteractiveAppTypes.TENSORBOARD, # Required. open_in_default_web_browser=False, # Optional. Set to False to print the URL to terminal. ) )

請注意,如果您在 SageMaker Studio Classic 環境之外執行上述兩個程式碼範例,函數會將 傳回URL至 TensorBoard SageMaker 主控台中的登陸頁面,因為這些範例不會將登入資訊傳回至您的網域和使用者設定檔。如需建立預先簽章的 URL,請參閱下一節中的選項 2。

選項 2:適用於非 Studio Classic 環境

如果您使用非 Studio Classic 環境,例如 SageMaker 筆記本執行個體和 Amazon EC2,並想要產生預先簽章URL來開啟 TensorBoard 應用程式,請使用 get_app_url方法搭配您的網域和使用者設定檔資訊,如下所示。

請注意,此選項需要網域使用者擁有 sagemaker:CreatePresignedDomainUrl許可。如果沒有許可,網域使用者將收到例外錯誤。

重要

請勿共用任何預先簽章的 URLs。get_app_url 函數會建立預先簽章的 URLs,它會自動使用您的網域和使用者設定檔進行身分驗證,並可讓您存取與網域相關聯的任何應用程式和檔案。

print( estimator.get_app_url( app_type=SupportedInteractiveAppTypes.TENSORBOARD, # Required create_presigned_domain_url=True, # Reguired to be set to True for creating a presigned URL. domain_id="your-domain-id", # Required if creating a presigned URL (create_presigned_domain_url=True). user_profile_name="your-user-profile-name", # Required if creating a presigned URL (create_presigned_domain_url=True). open_in_default_web_browser=False, # Optional. Set to False to print the URL to terminal. optional_create_presigned_url_kwargs={} # Optional. Add any additional args for Boto3 create_presigned_domain_url ) )