當前位置: 首頁>>代碼示例>>Python>>正文


Python sagemaker.Session方法代碼示例

本文整理匯總了Python中sagemaker.Session方法的典型用法代碼示例。如果您正苦於以下問題:Python sagemaker.Session方法的具體用法?Python sagemaker.Session怎麽用?Python sagemaker.Session使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sagemaker的用法示例。


在下文中一共展示了sagemaker.Session方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import sagemaker [as 別名]
# 或者: from sagemaker import Session [as 別名]
def __init__(self, endpoint, sagemaker_session=None):
        """Initializes a SparkMLPredictor which should be used with SparkMLModel
        to perform predictions against SparkML models serialized via MLeap. The
        response is returned in text/csv format which is the default response
        format for SparkML Serving container.

        Args:
            endpoint (str): The name of the endpoint to perform inference on.
            sagemaker_session (sagemaker.session.Session): Session object which
                manages interactions with Amazon SageMaker APIs and any other
                AWS services needed. If not specified, the estimator creates one
                using the default AWS configuration chain.
        """
        sagemaker_session = sagemaker_session or Session()
        super(SparkMLPredictor, self).__init__(
            endpoint=endpoint,
            sagemaker_session=sagemaker_session,
            serializer=csv_serializer,
            content_type=CONTENT_TYPE_CSV,
        ) 
開發者ID:aws,項目名稱:sagemaker-python-sdk,代碼行數:22,代碼來源:model.py

示例2: _is_marketplace

# 需要導入模塊: import sagemaker [as 別名]
# 或者: from sagemaker import Session [as 別名]
def _is_marketplace(self):
        """Placeholder docstring"""
        model_package_name = self.model_package_arn or self._created_model_package_name
        if model_package_name is None:
            return True

        # Models can lazy-init sagemaker_session until deploy() is called to support
        # LocalMode so we must make sure we have an actual session to describe the model package.
        sagemaker_session = self.sagemaker_session or sagemaker.Session()

        model_package_desc = sagemaker_session.sagemaker_client.describe_model_package(
            ModelPackageName=model_package_name
        )
        for container in model_package_desc["InferenceSpecification"]["Containers"]:
            if "ProductId" in container:
                return True
        return False 
開發者ID:aws,項目名稱:sagemaker-python-sdk,代碼行數:19,代碼來源:model.py

示例3: __init__

# 需要導入模塊: import sagemaker [as 別名]
# 或者: from sagemaker import Session [as 別名]
def __init__(self, args):
        """
        Args:
            args:
        """
        self.job_name = args.job_name
        self.bucket = args.bucket_name  # may be None
        self.role_name = args.role_name
        self.python = args.python
        self.data = args.data
        self.script = args.script
        self.instance_type = args.instance_type
        self.instance_count = args.instance_count
        self.hyperparameters = self.load_hyperparameters(args.hyperparameters)

        self.session = sagemaker.Session() 
開發者ID:aws,項目名稱:sagemaker-python-sdk,代碼行數:18,代碼來源:common.py

示例4: sagemaker_session_with_custom_bucket

# 需要導入模塊: import sagemaker [as 別名]
# 或者: from sagemaker import Session [as 別名]
def sagemaker_session_with_custom_bucket(
    boto_session, sagemaker_client_config, sagemaker_runtime_config, custom_bucket_name
):
    sagemaker_client_config.setdefault("config", Config(retries=dict(max_attempts=10)))
    sagemaker_client = (
        boto_session.client("sagemaker", **sagemaker_client_config)
        if sagemaker_client_config
        else None
    )
    runtime_client = (
        boto_session.client("sagemaker-runtime", **sagemaker_runtime_config)
        if sagemaker_runtime_config
        else None
    )

    return Session(
        boto_session=boto_session,
        sagemaker_client=sagemaker_client,
        sagemaker_runtime_client=runtime_client,
        default_bucket=custom_bucket_name,
    ) 
開發者ID:aws,項目名稱:sagemaker-python-sdk,代碼行數:23,代碼來源:test_processing.py

示例5: sagemaker_session

# 需要導入模塊: import sagemaker [as 別名]
# 或者: from sagemaker import Session [as 別名]
def sagemaker_session(sagemaker_client_config, sagemaker_runtime_config, boto_session):
    sagemaker_client_config.setdefault("config", Config(retries=dict(max_attempts=10)))
    sagemaker_client = (
        boto_session.client("sagemaker", **sagemaker_client_config)
        if sagemaker_client_config
        else None
    )
    runtime_client = (
        boto_session.client("sagemaker-runtime", **sagemaker_runtime_config)
        if sagemaker_runtime_config
        else None
    )

    return Session(
        boto_session=boto_session,
        sagemaker_client=sagemaker_client,
        sagemaker_runtime_client=runtime_client,
    ) 
開發者ID:aws,項目名稱:sagemaker-python-sdk,代碼行數:20,代碼來源:conftest.py

示例6: sagemaker_session

# 需要導入模塊: import sagemaker [as 別名]
# 或者: from sagemaker import Session [as 別名]
def sagemaker_session():
    boto_mock = Mock(name="boto_session", region_name=REGION)
    ims = sagemaker.Session(sagemaker_client=Mock(name="sagemaker_client"), boto_session=boto_mock)
    ims.sagemaker_client.describe_model = Mock(
        name="describe_model", side_effect=_raise_does_not_exist_client_error
    )
    ims.sagemaker_client.describe_endpoint_config = Mock(
        name="describe_endpoint_config", side_effect=_raise_does_not_exist_client_error
    )
    ims.sagemaker_client.describe_endpoint = Mock(
        name="describe_endpoint", side_effect=_raise_does_not_exist_client_error
    )
    ims.create_model = Mock(name="create_model")
    ims.create_endpoint_config = Mock(name="create_endpoint_config")
    ims.create_endpoint = Mock(name="create_endpoint")
    return ims 
開發者ID:aws,項目名稱:sagemaker-python-sdk,代碼行數:18,代碼來源:test_endpoint_from_model_data.py

示例7: test_user_agent_injected_with_nbi

# 需要導入模塊: import sagemaker [as 別名]
# 或者: from sagemaker import Session [as 別名]
def test_user_agent_injected_with_nbi(boto_session):
    assert (
        "AWS-SageMaker-Python-SDK" not in boto_session.client("sagemaker")._client_config.user_agent
    )

    with patch("six.moves.builtins.open", mock_open(read_data="120.0-0")) as mo:
        sess = Session(boto_session)

        mo.assert_called_with("/etc/opt/ml/sagemaker-notebook-instance-version.txt")

    assert "AWS-SageMaker-Python-SDK" in sess.sagemaker_client._client_config.user_agent
    assert "AWS-SageMaker-Python-SDK" in sess.sagemaker_runtime_client._client_config.user_agent
    assert "AWS-SageMaker-Notebook-Instance" in sess.sagemaker_client._client_config.user_agent
    assert (
        "AWS-SageMaker-Notebook-Instance" in sess.sagemaker_runtime_client._client_config.user_agent
    ) 
開發者ID:aws,項目名稱:sagemaker-python-sdk,代碼行數:18,代碼來源:test_session.py

示例8: test_user_agent_injected_with_nbi_ioerror

# 需要導入模塊: import sagemaker [as 別名]
# 或者: from sagemaker import Session [as 別名]
def test_user_agent_injected_with_nbi_ioerror(boto_session):
    assert (
        "AWS-SageMaker-Python-SDK" not in boto_session.client("sagemaker")._client_config.user_agent
    )

    with patch("six.moves.builtins.open", MagicMock(side_effect=IOError("File not found"))) as mo:
        sess = Session(boto_session)

        mo.assert_called_with("/etc/opt/ml/sagemaker-notebook-instance-version.txt")

    assert "AWS-SageMaker-Python-SDK" in sess.sagemaker_client._client_config.user_agent
    assert "AWS-SageMaker-Python-SDK" in sess.sagemaker_runtime_client._client_config.user_agent
    assert "AWS-SageMaker-Notebook-Instance" not in sess.sagemaker_client._client_config.user_agent
    assert (
        "AWS-SageMaker-Notebook-Instance"
        not in sess.sagemaker_runtime_client._client_config.user_agent
    ) 
開發者ID:aws,項目名稱:sagemaker-python-sdk,代碼行數:19,代碼來源:test_session.py

示例9: sagemaker_session_ready_lifecycle

# 需要導入模塊: import sagemaker [as 別名]
# 或者: from sagemaker import Session [as 別名]
def sagemaker_session_ready_lifecycle():
    boto_mock = Mock(name="boto_session")
    boto_mock.client("logs").describe_log_streams.return_value = DEFAULT_LOG_STREAMS
    boto_mock.client("logs").get_log_events.side_effect = STREAM_LOG_EVENTS
    ims = sagemaker.Session(boto_session=boto_mock, sagemaker_client=Mock())
    ims.sagemaker_client.describe_training_job.side_effect = [
        IN_PROGRESS_DESCRIBE_JOB_RESULT,
        IN_PROGRESS_DESCRIBE_JOB_RESULT,
        COMPLETED_DESCRIBE_JOB_RESULT,
    ]
    ims.sagemaker_client.describe_transform_job.side_effect = [
        IN_PROGRESS_DESCRIBE_TRANSFORM_JOB_RESULT,
        IN_PROGRESS_DESCRIBE_TRANSFORM_JOB_RESULT,
        COMPLETED_DESCRIBE_TRANSFORM_JOB_RESULT,
    ]
    return ims 
開發者ID:aws,項目名稱:sagemaker-python-sdk,代碼行數:18,代碼來源:test_session.py

示例10: sagemaker_session_full_lifecycle

# 需要導入模塊: import sagemaker [as 別名]
# 或者: from sagemaker import Session [as 別名]
def sagemaker_session_full_lifecycle():
    boto_mock = Mock(name="boto_session")
    boto_mock.client("logs").describe_log_streams.side_effect = LIFECYCLE_LOG_STREAMS
    boto_mock.client("logs").get_log_events.side_effect = STREAM_LOG_EVENTS
    ims = sagemaker.Session(boto_session=boto_mock, sagemaker_client=Mock())
    ims.sagemaker_client.describe_training_job.side_effect = [
        IN_PROGRESS_DESCRIBE_JOB_RESULT,
        IN_PROGRESS_DESCRIBE_JOB_RESULT,
        COMPLETED_DESCRIBE_JOB_RESULT,
    ]
    ims.sagemaker_client.describe_transform_job.side_effect = [
        IN_PROGRESS_DESCRIBE_TRANSFORM_JOB_RESULT,
        IN_PROGRESS_DESCRIBE_TRANSFORM_JOB_RESULT,
        COMPLETED_DESCRIBE_TRANSFORM_JOB_RESULT,
    ]
    return ims 
開發者ID:aws,項目名稱:sagemaker-python-sdk,代碼行數:18,代碼來源:test_session.py

示例11: test_download_folder_points_to_single_file

# 需要導入模塊: import sagemaker [as 別名]
# 或者: from sagemaker import Session [as 別名]
def test_download_folder_points_to_single_file(makedirs):
    boto_mock = Mock(name="boto_session")
    boto_mock.client("sts").get_caller_identity.return_value = {"Account": "123"}

    session = sagemaker.Session(boto_session=boto_mock, sagemaker_client=Mock())

    train_data = Mock()

    train_data.bucket_name.return_value = BUCKET_NAME
    train_data.key = "prefix/train/train_data.csv"

    s3_files = [train_data]
    boto_mock.resource("s3").Bucket(BUCKET_NAME).objects.filter.return_value = s3_files

    obj_mock = Mock()
    boto_mock.resource("s3").Object.return_value = obj_mock

    # all the S3 mocks are set, the test itself begins now.
    sagemaker.utils.download_folder(BUCKET_NAME, "/prefix/train/train_data.csv", "/tmp", session)

    obj_mock.download_file.assert_called()
    calls = [call(os.path.join("/tmp", "train_data.csv"))]
    obj_mock.download_file.assert_has_calls(calls)
    boto_mock.resource("s3").Bucket(BUCKET_NAME).objects.filter.assert_not_called()
    obj_mock.reset_mock() 
開發者ID:aws,項目名稱:sagemaker-python-sdk,代碼行數:27,代碼來源:test_utils.py

示例12: fixture_sagemaker_session

# 需要導入模塊: import sagemaker [as 別名]
# 或者: from sagemaker import Session [as 別名]
def fixture_sagemaker_session(region):
    return Session(boto_session=boto3.Session(region_name=region)) 
開發者ID:aws,項目名稱:sagemaker-xgboost-container,代碼行數:4,代碼來源:conftest.py

示例13: fixture_sagemaker_local_session

# 需要導入模塊: import sagemaker [as 別名]
# 或者: from sagemaker import Session [as 別名]
def fixture_sagemaker_local_session(region):
    return LocalSession(boto_session=boto3.Session(region_name=region)) 
開發者ID:aws,項目名稱:sagemaker-pytorch-training-toolkit,代碼行數:4,代碼來源:conftest.py

示例14: sagemaker_session

# 需要導入模塊: import sagemaker [as 別名]
# 或者: from sagemaker import Session [as 別名]
def sagemaker_session(region):
    return Session(boto_session=boto3.Session(region_name=region)) 
開發者ID:aws,項目名稱:sagemaker-mxnet-inference-toolkit,代碼行數:4,代碼來源:conftest.py

示例15: sagemaker_local_session

# 需要導入模塊: import sagemaker [as 別名]
# 或者: from sagemaker import Session [as 別名]
def sagemaker_local_session(region):
    return LocalSession(boto_session=boto3.Session(region_name=region)) 
開發者ID:aws,項目名稱:sagemaker-mxnet-inference-toolkit,代碼行數:4,代碼來源:conftest.py


注:本文中的sagemaker.Session方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。