标签: amazon-sagemaker

sagemaker中的逻辑回归

我正在使用 aws sagemaker 进行逻辑回归。为了在测试数据上验证模型,使用以下代码

runtime= boto3.client('runtime.sagemaker')

payload = np2csv(test_X)
response = runtime.invoke_endpoint(EndpointName=linear_endpoint,
                                   ContentType='text/csv',
                                   Body=payload)
result = json.loads(response['Body'].read().decode())
test_pred = np.array([r['score'] for r in result['predictions']])
Run Code Online (Sandbox Code Playgroud)

结果包含预测值和概率分数。我想知道如何运行预测模型来根据两个特定特征预测结果。例如。我在模型中有 30 个特征,并使用这些特征训练了模型。现在对于我的预测,我想知道 feature1='x' 和 feature2='y' 时的结果。但是当我将数据过滤到这些列并在相同的代码中传递时,我收到以下错误。

Customer Error: The feature dimension of the input: 4 does not match the feature dimension of the model: 30. Please fix the input and try again.
Run Code Online (Sandbox Code Playgroud)

在 AWS Sagemaker 实现中,R 中的 say glm.predict('feature1','feature2') 相当于什么?

amazon-web-services amazon-sagemaker

3
推荐指数
1
解决办法
1181
查看次数

如何确保使用 sagemaker 安装库?

我有一个带有标准模板代码的 jupyter 笔记本,就像这样

从 sagemaker.tensorflow 导入 TensorFlow

import sagemaker
from sagemaker import get_execution_role
sagemaker_session = sagemaker.Session()
role = get_execution_role()

tf_estimator = TensorFlow(entry_point='sagemaker_predict_2.py', role=role,
                          training_steps=10000, evaluation_steps=100,
                          train_instance_count=1, train_instance_type='ml.p2.xlarge',
                          framework_version='1.10.0')
tf_estimator.fit('s3://XXX-sagemaker/XXX')
Run Code Online (Sandbox Code Playgroud)

这开始很好,但最终会引发错误

2018-11-27 06:21:12 Starting - Starting the training job...
2018-11-27 06:21:15 Starting - Launching requested ML instances.........
2018-11-27 06:22:44 Starting - Preparing the instances for training...
2018-11-27 06:23:35 Downloading - Downloading input data...
2018-11-27 06:24:03 Training - Downloading the training image......
2018-11-27 06:25:12 Training - Training image download completed. Training in …
Run Code Online (Sandbox Code Playgroud)

keras tensorflow amazon-sagemaker

3
推荐指数
1
解决办法
3372
查看次数

AWS SageMaker:CapacityError:无法预配请求的 ML 计算容量。

我们正在运行类型为 (1) ml.p3.8xlarge和 (2) ml.p3.2xlarge的两个 TrainingJob 实例。

每个训练作业都使用 Tensorflow 和 Keras 后端运行自定义算法。

实例 (1) 运行正常,而实例 (2) 在报告的 1 小时训练时间后,在 CloudWatch 中进行任何日志记录(任何文本拖曳日志)时,都会退出并出现以下错误:

Failure reason
CapacityError: Unable to provision requested ML compute capacity. Please retry using a different ML instance type.
Run Code Online (Sandbox Code Playgroud)

我不确定这条消息的含义。

keras tensorflow amazon-sagemaker

3
推荐指数
1
解决办法
6867
查看次数

在 Amazon SageMaker 中进行预测之前预处理输入数据

我有一个我们自己训练的 Keras/tensorflow 模型,它可以进行图像相关的预测。我已经按照这个训练有素的 keras 模型教程在 Sagemaker 中部署模型,并且可以调用端点进行预测。

现在在我的客户端代码中,在通过调用 Sagemaker 端点进行预测之前,我需要下载图像并进行一些预处理。我想在 SageMaker 中完成整个过程,而不是在客户端执行此操作。我怎么做?

看来我需要更新train.py这里提到的入口点python代码:

sagemaker_model = TensorFlowModel(model_data = 's3://' + sagemaker_session.default_bucket() + '/model/model.tar.gz',
                                  role = role,
                                  entry_point = 'train.py')
Run Code Online (Sandbox Code Playgroud)

其他文章表明我需要覆盖input_fn函数来捕获预处理。但是这些文章指的是使用 MXNet 框架时使用的步骤。但是我的模型是基于 Keras/tensorflow 框架的。

所以我不确定如何覆盖该input_fn功能。任何人都可以请建议吗?

python machine-learning keras tensorflow amazon-sagemaker

3
推荐指数
1
解决办法
1016
查看次数

MissingRequiredParameter:参数中缺少必需的键“FunctionName”

我正在研究一个受监督的机器学习问题,我正在设置一个自定义标签任务以发送到 Amazon Mechanical Turk 以进行人工注释。

我已.jsonl按照 AWS 文档https://docs.aws.amazon.com/sagemaker/latest/dg/sms-data 中指定的说明以json-lines ( ) 格式将数据上传到 AWS S3,如下所示-input.html :

{"source": "value0"}
{"source": "value1"}    
{"source": "value2"}
...
{"source": "value2"}
Run Code Online (Sandbox Code Playgroud)

当我点击默认的文本分类模板时,我可以看到我的数据通过,一切似乎都在工作。

但是,当我尝试使用自定义注释任务模板界面时出现以下错误: MissingRequiredParameter: Missing required key 'FunctionName' in params

该错误类似于 AWS Lambda 错误,但奇怪的是我没有使用 AWS Lambda。关于如何进行的建议?

mechanicalturk amazon-web-services amazon-sagemaker

3
推荐指数
1
解决办法
5627
查看次数

没有这样的文件或目录:'docker': 在本地模式下运行 sagemaker studio 时的 'docker'

我尝试在 amazon sagemaker studio 上训练一个 pytorch 模型。

当我使用 EC2 进行以下培训时,它可以正常工作:

estimator = PyTorch(entry_point='train_script.py',
                role=role,
                sagemaker_session = sess,
                train_instance_count=1,
                train_instance_type='ml.c5.xlarge',
                framework_version='1.4.0', 
                source_dir='.',
                git_config=git_config, 
               )
estimator.fit({'stockdata': data_path})
Run Code Online (Sandbox Code Playgroud)

它在经典 sagemaker 笔记本(非工作室)中使用本地模式:

 estimator = PyTorch(entry_point='train_script.py',
                role=role,
                train_instance_count=1,
                train_instance_type='local',
                framework_version='1.4.0', 
                source_dir='.',
                git_config=git_config, 
               )
estimator.fit({'stockdata': data_path})
Run Code Online (Sandbox Code Playgroud)

但是,当我在 sagemaker studio 上使用相同的代码(使用 train_instance_type='local')时,它不起作用,并且出现以下错误:没有这样的文件或目录:'docker':'docker'

我尝试使用 pip install 安装 docker,但是如果在终端中使用它,则找不到 docker 命令

docker pytorch amazon-sagemaker

3
推荐指数
1
解决办法
738
查看次数

孤立森林与鲁棒随机切割森林在异常值检测中的比较

我正在研究异常值检测中的不同方法。我遇到了 sklearn 的 Isolation Forest 实现和 Amazon sagemaker 的 RRCF(Robust Random Cut Forest)实现。两者都是基于决策树的集成方法,旨在隔离每个点。隔离步骤越多,该点就越有可能成为内点,反之亦然。

但是,即使查看了算法的原始论文,我也无法准确理解两种算法之间的区别。它们的工作方式有何不同?它们中的一个比另一个更有效吗?

编辑:我正在添加研究论文的链接以获取更多信息,以及一些讨论这些主题的教程。

隔离森林:

论文 教程

健壮的随机砍伐森林:

论文 教程

python outliers scikit-learn anomaly-detection amazon-sagemaker

3
推荐指数
1
解决办法
3259
查看次数

语法错误(amazon-sagemaker-object-has-no-attribute)

我正在 SageMaker Notebook 实例上运行下面的代码单元。

pd.concat([train_data['y_yes'], train_data.drop(['y_no', 'y_yes'], axis=1)], axis=1).to_csv('train.csv', index=False, header=False)
boto3.Session().resource('s3').Bucket(bucket_name).Object(os.path.join(prefix, 'train/train.csv')).upload_file('train.csv')
s3_input_train = sagemaker.s3_input(s3_data='s3://{}/{}/train'.format(bucket_name, prefix), content_type='csv')
Run Code Online (Sandbox Code Playgroud)

如果我点击,则会出现以下错误:

AttributeError: 'SageMaker' object has no attribute 's3_input'
Run Code Online (Sandbox Code Playgroud)

amazon-web-services amazon-sagemaker

3
推荐指数
2
解决办法
2384
查看次数

Terraform - 无法在字符串模板中包含给定值:需要字符串

我正在尝试按照此页面使用 terraform 在 SageMaker 上创建模型, 由于权限限制,我无法为 sagemaker 角色分配完整的访问策略,因此我创建了一个角色并附加了具有部分权限的策略

当我测试时Terraform plan,它给了我这个:

Error: Invalid template interpolation value
...
Run Code Online (Sandbox Code Playgroud)
..........................
 141:                 "ecr:GetRepositoryPolicy"
 142:             ],
 143:             "Resource": [
 144:                 "arn:aws:s3:::${aws_s3_bucket.xx_xxxxxxxxxx_xxx_bucket}",
 145:                 "arn:aws:s3:::${local.binaries_bucket_name}",
 146:                 "arn:aws:s3:::${aws_s3_bucket.xx_xxxxxxxxxx_xxx_bucket}/*",
 147:                 "arn:aws:s3:::${local.binaries_bucket_name}/*",
 148:                 "arn:aws:ecr:us-east-1:*:repository/*",
 149.....................
 157:         }
 158:     ]
 159: }
 160: POLICY
    |----------------
    | aws_s3_bucket.xx_xxxxxxxxxx_xxx_bucket is object with 25 attributes

Cannot include the given value in a string template: string required.
Run Code Online (Sandbox Code Playgroud)

我对此很陌生,只是想知道这是在抱怨存储桶名称太长还是其他原因?我该怎么办才能解决这个问题,我有点困惑。非常感谢。

(PS:Terraform版本v0.13.4+提供商registry.terraform.io/hashicorp/aws v3.20.0

amazon-s3 amazon-web-services terraform amazon-sagemaker terraform-provider-aws

3
推荐指数
1
解决办法
2万
查看次数

AWS Sagemaker 推理端点未利用所有 vCPU

我在 sagemaker 推理端点(单实例)上部署了一个自定义模型,在进行负载测试时,我观察到 CPU 利用率指标达到了 100% 的最大值,但根据这篇文章,它应该达到 #vCPU*100% 的最大值。我已确认推理端点未使用 clowdwatch 日志中的所有核心。

因此,如果一个预测调用需要一秒钟处理才能给出响应,则部署的模型每秒只能处理一个 API 调用,如果使用所有 vCPU,则可能会增加到每秒 8 个调用。

AWS Sagemaker部署中是否有任何设置可以使用所有vCPU来提高并发性?

或者我们可以inference.py在部署时在文件内使用多处理 python 包,以便每次调用都到达默认核心,然后所有计算/预测都在任何其他核心中完成,无论该核心在该实例中是空的吗?

python machine-learning amazon-web-services amazon-sagemaker

3
推荐指数
1
解决办法
1764
查看次数