google-cloud-platform - 如何在谷歌云机器学习引擎上训练 Keras 模型

标签 google-cloud-platform keras

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

最佳答案

我发现为了在谷歌云上使用 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"

关于google-cloud-platform - 如何在谷歌云机器学习引擎上训练 Keras 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43322886/

相关文章:

python-3.x - Keras 'flow_from_directory' 非常慢

docker - 是否可以使用 docker 作为 golang 应用引擎标准环境的开发环境?

ruby-on-rails - 访问部署在 Google Cloud Run 中的应用程序的 Rails 控制台

python - 如何将 Keras 模型加载到内存中并在需要时使用它?

python - 检查输入 : expected conv2d_1_input to have shape (3, 32, 32) 时出错,但得到形状为 (32, 32, 3) 的数组

python - Keras 中的自定义层 : def call

google-cloud-platform - 如何将静态 ip 转移到另一个 gcloud 项目

node.js - pg.Pool 不是构造函数

https - HTTPS负载均衡器以在Google Kubernetes上公开工作负载

python - keras:ValueError:检查模型目标时出错:预期activation_1具有形状(无,60)但得到形状为(10、100)的数组