问题描述
我可以在google云机器学习引擎上训练tensorflow模型。但是,当我使用Keras代码时,我在google cloud上得到错误没有名为keras
的模块。我发现为了在谷歌云上使用keras,必须使用setup.py脚本安装它,并将它放在运行gcloud命令的相同位置文件夹中:
├──setup.py
└──教练
├──__init__.py
├──cloudml -gpu.yaml
├──example5-keras.py
并在设置中。 py你把内容,如:
from setuptools import setup,find_packages
setup(name =' example5',
version ='0.1',
packages = find_packages(),
description ='在gcloud ml-engine上运行keras的例子',
author ='Fuyang Liu ',
author_email='fuyang.liu@example.com',
license ='MIT',
install_requires = [
'keras',
'h5py'
],
zip _safe = False)
然后,您可以开始在gcloud上运行作业,例如:
export BUCKET_NAME = tf-learn-simple-sentiment
export JOB_NAME =example_5_train _ $(date +%Y%m%d_%H %M%S)
export JOB_DIR = gs:// $ BUCKET_NAME / $ JOB_NAME
export REGION = europe-west1
gcloud ml-engine作业提交培训$ JOB_NAME \\ \\
--job-dir gs:// $ BUCKET_NAME / $ JOB_NAME \
--runtime-version 1.0 \
--module-name trainer.example5-keras \
- 软件包路径./trainer \
--region $ REGION \
--config = trainer / cloudml-gpu.yaml \
- \
--train-file gs://tf-learn-simple-sentiment/sentiment_set.pickle
要使用GPU,然后在模块中添加一个文件,例如 cloudml-gpu.yaml
,其中包含以下内容:
trainingInput:
scaleTier:CUSTOM
#standard_gpu提供1个GPU。更改为complex_model_m_gpu 4
GPU
masterType:standard_gpu
runtimeVersion:1.0
I can train tensorflow models on google cloud machine learning engine. But when I use Keras code, I get error No module named keras
on google cloud.
I found out that in order to use keras on google cloud one has to install it with a setup.py script and put it on the same place folder where you run the gcloud command:
├── setup.py
└── trainer
├── __init__.py
├── cloudml-gpu.yaml
├── example5-keras.py
And in the setup.py you put content such as:
from setuptools import setup, find_packages
setup(name='example5',
version='0.1',
packages=find_packages(),
description='example to run keras on gcloud ml-engine',
author='Fuyang Liu',
author_email='fuyang.liu@example.com',
license='MIT',
install_requires=[
'keras',
'h5py'
],
zip_safe=False)
Then you can start your job running on gcloud such as:
export BUCKET_NAME=tf-learn-simple-sentiment
export JOB_NAME="example_5_train_$(date +%Y%m%d_%H%M%S)"
export JOB_DIR=gs://$BUCKET_NAME/$JOB_NAME
export REGION=europe-west1
gcloud ml-engine jobs submit training $JOB_NAME \
--job-dir gs://$BUCKET_NAME/$JOB_NAME \
--runtime-version 1.0 \
--module-name trainer.example5-keras \
--package-path ./trainer \
--region $REGION \
--config=trainer/cloudml-gpu.yaml \
-- \
--train-file gs://tf-learn-simple-sentiment/sentiment_set.pickle
To use GPU then add a file such as cloudml-gpu.yaml
in your module with the following content:
trainingInput:
scaleTier: CUSTOM
# standard_gpu provides 1 GPU. Change to complex_model_m_gpu for 4
GPUs
masterType: standard_gpu
runtimeVersion: "1.0"
这篇关于如何在Google Cloud Machine Learning Engine上培训Keras模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!