如何通过 React Native 访问 Amazon Sagemaker?
How do I access Amazon Sagemaker through React Native?
我目前正在使用 react-native 构建移动应用程序。我需要访问机器学习模型才能发送图片进行分割。我希望能够将分割后的图片接收回来,以便将图片的背景剪掉。我正在尝试使用 Amazon Sagemaker(因为它似乎很容易使用包,但如果有其他方法可以做到这一点,请告诉我)。
在 this Sagemaker 快速入门指南的第 5a 步中,它指出:
5a. To deploy the model on a server and create an endpoint that you can access, copy the following code into the next code cell and select Run:
xgb_predictor = xgb.deploy(initial_instance_count=1,instance_type='ml.m4.xlarge')
我想在 AWS 上托管所有内容,而不必 运行 单独的服务器。我可以使用什么 service/process 来创建一个可以通过 react-native 访问的端点?
在评论中总结对话:
训练、调整和部署模型后(这不是一个简单的过程),您可以使用安装的 AWS SDK for JavaScript 调用模型的端点:
npm install aws-sdk
var AWS = require('aws-sdk/dist/aws-sdk-react-native');
您在 HTML 中包括:
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.538.0.min.js"></script>
当你想调用端点时,你可以这样调用它:
var params = {
Body: Buffer.from('...') || 'STRING_VALUE' /* Strings will be Base-64 encoded on your behalf */, /* required */
EndpointName: 'STRING_VALUE', /* required */
Accept: 'STRING_VALUE',
ContentType: 'STRING_VALUE',
CustomAttributes: 'STRING_VALUE'
};
sagemakerruntime.invokeEndpoint(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
您可以查看 Amplify Library,它可以完成一些繁重的工作,例如获取调用 API 的 IAM 权限、用户登录等。
我目前正在使用 react-native 构建移动应用程序。我需要访问机器学习模型才能发送图片进行分割。我希望能够将分割后的图片接收回来,以便将图片的背景剪掉。我正在尝试使用 Amazon Sagemaker(因为它似乎很容易使用包,但如果有其他方法可以做到这一点,请告诉我)。
在 this Sagemaker 快速入门指南的第 5a 步中,它指出:
5a. To deploy the model on a server and create an endpoint that you can access, copy the following code into the next code cell and select Run: xgb_predictor = xgb.deploy(initial_instance_count=1,instance_type='ml.m4.xlarge')
我想在 AWS 上托管所有内容,而不必 运行 单独的服务器。我可以使用什么 service/process 来创建一个可以通过 react-native 访问的端点?
在评论中总结对话:
训练、调整和部署模型后(这不是一个简单的过程),您可以使用安装的 AWS SDK for JavaScript 调用模型的端点:
npm install aws-sdk
var AWS = require('aws-sdk/dist/aws-sdk-react-native');
您在 HTML 中包括:
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.538.0.min.js"></script>
当你想调用端点时,你可以这样调用它:
var params = {
Body: Buffer.from('...') || 'STRING_VALUE' /* Strings will be Base-64 encoded on your behalf */, /* required */
EndpointName: 'STRING_VALUE', /* required */
Accept: 'STRING_VALUE',
ContentType: 'STRING_VALUE',
CustomAttributes: 'STRING_VALUE'
};
sagemakerruntime.invokeEndpoint(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
您可以查看 Amplify Library,它可以完成一些繁重的工作,例如获取调用 API 的 IAM 权限、用户登录等。