[英]Training keras model in AWS Sagemaker
I have keras training script on my machine.我的机器上有 keras 训练脚本。 I am experimenting to run my script on AWS sagemaker container.
我正在尝试在 AWS sagemaker 容器上运行我的脚本。 For that I have used below code.
为此,我使用了以下代码。
from sagemaker.tensorflow import TensorFlow
est = TensorFlow(
entry_point="caller.py",
source_dir="./",
role='role_arn',
framework_version="2.3.1",
py_version="py37",
instance_type='ml.m5.large',
instance_count=1,
hyperparameters={'batch': 8, 'epochs': 10},
)
est.fit()
here caller.py
is my entry point.这里
caller.py
是我的入口点。 After executing the above code I am getting keras is not installed
.执行上述代码后,我得到
keras is not installed
。 Here is the stacktrace.这是堆栈跟踪。
Traceback (most recent call last):
File "executor.py", line 14, in <module>
est.fit()
File "/home/thasin/Documents/python/venv/lib/python3.8/site-packages/sagemaker/estimator.py", line 682, in fit
self.latest_training_job.wait(logs=logs)
File "/home/thasin/Documents/python/venv/lib/python3.8/site-packages/sagemaker/estimator.py", line 1625, in wait
self.sagemaker_session.logs_for_job(self.job_name, wait=True, log_type=logs)
File "/home/thasin/Documents/python/venv/lib/python3.8/site-packages/sagemaker/session.py", line 3681, in logs_for_job
self._check_job_status(job_name, description, "TrainingJobStatus")
File "/home/thasin/Documents/python/venv/lib/python3.8/site-packages/sagemaker/session.py", line 3240, in _check_job_status
raise exceptions.UnexpectedStatusException(
sagemaker.exceptions.UnexpectedStatusException: Error for Training job tensorflow-training-2021-06-09-07-14-01-778: Failed. Reason: AlgorithmError: ExecuteUserScriptError:
Command "/usr/local/bin/python3.7 caller.py --batch 4 --epochs 10
ModuleNotFoundError: No module named 'keras'
Note: I have tried with my own container uploading to ECR and successfully run my code.注意:我已经尝试将自己的容器上传到 ECR 并成功运行我的代码。 I am looking for AWS's existing container capability.
我正在寻找 AWS 现有的容器功能。
Keras is now part of tensorflow, so you can just reformat your code to use tf.keras
instead of keras
. Keras 现在是 tensorflow 的一部分,因此您只需重新格式化代码以使用
tf.keras
而不是keras
Since version 2.3.0 of tensorflow they are in sync, so it should not be that difficult.由于 tensorflow 的 2.3.0 版本是同步的,所以应该没那么难。 You container is this , as you can see from the list of the packages, there is no
Keras
.你的容器就是这个,从包列表中可以看出,没有
Keras
。 If you instead want to extend a pre-built container you can take a look here but I don't recommend in this specific use-case, because also for future code maintainability you should go for tf.keras
如果您想扩展预构建的容器,您可以查看此处,但我不建议在此特定用例中使用,因为为了将来的代码可维护性,您应该为 tf.keras 提供
tf.keras
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.