首页 文章

如何在Google Cloud Machine学习引擎上培训Keras模型

提问于
浏览
3

我可以在谷歌 Cloud 机器学习引擎上培训tensorflow模型 . 但是当我使用Keras代码时,我在google cloud上收到错误 No module named keras .

1 回答

  • 8

    我发现为了在谷歌 Cloud 上使用keras,必须使用setup.py脚本安装它并将其放在运行gcloud命令的同一个文件夹中:

    ├── setup.py
    └── trainer
        ├── __init__.py
        ├── cloudml-gpu.yaml
        ├── example5-keras.py
    

    在setup.py中,您放置了以下内容:

    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)
    

    然后你可以开始在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 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
    

    要使用GPU,请在模块中添加文件,例如 cloudml-gpu.yaml ,其中包含以下内容:

    trainingInput:
      scaleTier: CUSTOM
      # standard_gpu provides 1 GPU. Change to complex_model_m_gpu for 4 
    GPUs
      masterType: standard_gpu
      runtimeVersion: "1.0"
    

相关问题