|
184 | 184 | "import sagemaker\n", |
185 | 185 | "from sagemaker import get_execution_role\n", |
186 | 186 | "from sagemaker.predictor import csv_serializer, json_deserializer\n", |
| 187 | + "from sagemaker.amazon.amazon_estimator import get_image_uri\n", |
187 | 188 | "\n", |
188 | 189 | "\n", |
189 | 190 | "def trained_estimator_from_hyperparams(s3_train_data, hyperparams, output_path, s3_test_data=None):\n", |
|
192 | 193 | " and return a deployed predictor\n", |
193 | 194 | " \n", |
194 | 195 | " \"\"\"\n", |
195 | | - " # specify algorithm containers. These contain the code for the training job\n", |
196 | | - " containers = {\n", |
197 | | - " 'us-west-2': '174872318107.dkr.ecr.us-west-2.amazonaws.com/knn:1',\n", |
198 | | - " 'us-east-1': '382416733822.dkr.ecr.us-east-1.amazonaws.com/knn:1',\n", |
199 | | - " 'us-east-2': '404615174143.dkr.ecr.us-east-2.amazonaws.com/knn:1',\n", |
200 | | - " 'eu-west-1': '438346466558.dkr.ecr.eu-west-1.amazonaws.com/knn:1',\n", |
201 | | - " 'ap-northeast-1': '351501993468.dkr.ecr.ap-northeast-1.amazonaws.com/knn:1',\n", |
202 | | - " 'ap-northeast-2': '835164637446.dkr.ecr.ap-northeast-2.amazonaws.com/knn:1',\n", |
203 | | - " 'ap-southeast-2': '712309505854.dkr.ecr.ap-southeast-2.amazonaws.com/knn:1'\n", |
204 | | - " }\n", |
205 | 196 | " # set up the estimator\n", |
206 | | - " knn = sagemaker.estimator.Estimator(containers[boto3.Session().region_name],\n", |
| 197 | + " knn = sagemaker.estimator.Estimator(get_image_uri(boto3.Session().region_name, \"knn\"),\n", |
207 | 198 | " get_execution_role(),\n", |
208 | 199 | " train_instance_count=1,\n", |
209 | 200 | " train_instance_type='ml.m5.2xlarge',\n", |
|
397 | 388 | "import sagemaker\n", |
398 | 389 | "from sagemaker import get_execution_role\n", |
399 | 390 | "from sagemaker.predictor import csv_serializer, json_deserializer\n", |
| 391 | + "from sagemaker.amazon.amazon_estimator import get_image_uri\n", |
| 392 | + "\n", |
400 | 393 | "\n", |
401 | 394 | "def trained_estimator_from_hyperparams(s3_train_data, hyperparams, output_path, s3_test_data=None):\n", |
402 | 395 | " \"\"\"\n", |
403 | 396 | " Create an Estimator from the given hyperparams, fit to training data, \n", |
404 | 397 | " and return a deployed predictor\n", |
405 | 398 | " \n", |
406 | 399 | " \"\"\"\n", |
407 | | - " # specify algorithm containers. These contain the code for the training job\n", |
408 | | - " containers = {\n", |
409 | | - " 'us-west-2': '174872318107.dkr.ecr.us-west-2.amazonaws.com/knn:1',\n", |
410 | | - " 'us-east-1': '382416733822.dkr.ecr.us-east-1.amazonaws.com/knn:1',\n", |
411 | | - " 'us-east-2': '404615174143.dkr.ecr.us-east-2.amazonaws.com/knn:1',\n", |
412 | | - " 'eu-west-1': '438346466558.dkr.ecr.eu-west-1.amazonaws.com/knn:1',\n", |
413 | | - " 'ap-northeast-1': '351501993468.dkr.ecr.ap-northeast-1.amazonaws.com/knn:1',\n", |
414 | | - " 'ap-northeast-2': '835164637446.dkr.ecr.ap-northeast-2.amazonaws.com/knn:1',\n", |
415 | | - " 'ap-southeast-2': '712309505854.dkr.ecr.ap-southeast-2.amazonaws.com/knn:1'\n", |
416 | | - " }\n", |
| 400 | + "\n", |
417 | 401 | " # set up the estimator\n", |
418 | | - " knn = sagemaker.estimator.Estimator(containers[boto3.Session().region_name],\n", |
| 402 | + " knn = sagemaker.estimator.Estimator(get_image_uri(boto3.Session().region_name, \"knn\"),\n", |
419 | 403 | " get_execution_role(),\n", |
420 | 404 | " train_instance_count=1,\n", |
421 | 405 | " train_instance_type='ml.m5.2xlarge',\n", |
|
821 | 805 | ], |
822 | 806 | "metadata": { |
823 | 807 | "kernelspec": { |
824 | | - "display_name": "Python 3", |
| 808 | + "display_name": "conda_python3", |
825 | 809 | "language": "python", |
826 | | - "name": "python3" |
| 810 | + "name": "conda_python3" |
827 | 811 | }, |
828 | 812 | "language_info": { |
829 | 813 | "codemirror_mode": { |
|
0 commit comments