简体   繁体   English

Google Cloud Machine Learning Engine无法找到用于本地执行的教练模块

[英]Google Cloud Machine Learning Engine cannot find trainer module for local execution

I try to get my feet wet with Google Cloud Machine Learning (ML) Engine by attempting to run a local trainer. 我尝试通过运行本地培训师来尝试使用Google Cloud Machine Learning(ML)引擎 I have followed Google's setup instructions and issued this command: 我已遵循Google的设置说明并发出了以下命令:

gcloud ml-engine local train \
  --module-name trainer \
  --package-path $(pwd) \
  --job-dir $JOB_DIR

My trainer exists in a file $(pwd)/trainer.py , yet I receive this error message: 我的培训师存在于文件$(pwd)/trainer.py ,但我收到以下错误消息:

~/cmle-quickstart/bin/python: No module named trainer

What am I doing wrong? 我究竟做错了什么?

The code must be in a valid Python package , which will require you to have an __init__.py , which can be blank. 该代码必须位于有效的Python包中 ,这将要求您具有__init__.py ,可以为空。

First, create the __init__.py . 首先,创建__init__.py From the same directory as above run: 在与上述相同的目录中运行:

touch __init__.py

To run local training, you'll need to refer to module by its fully qualified name, which now includes the parent directory of the module. 要进行本地培训,您需要使用模块的完全限定名称来引用该模块,该名称现在包括模块的父目录。 So if your directory structure looks like this: 因此,如果您的目录结构如下所示:

- my_model
  - __init__.py
  - trainer.py

Then the package name is my_model and the module name is, of course, trainer . 然后,程序包名称为my_model ,模块名称当然为trainer So to run training, you would use the following commands: 因此,要进行培训,您将使用以下命令:

gcloud ml-engine local train \
  --module-name my_model.trainer \
  --package-path $(pwd) \
  --job-dir $JOB_DIR

Here, you're telling gcloud : I have a valid Python package at $(pwd) . 在这里,您告诉gcloud :我在$(pwd)有一个有效的Python包。 The fully-qualified module name within that package that I want you run is my_model.trainer 我要您运行的程序包中的标准模块名称为my_model.trainer

Note that this is equivalent to the following command: 请注意,这等效于以下命令:

(cd $PACKAGE_PATH/.. && python -m my_model.trainer)

Where PACKAGE_PATH points to the my_model directory. PACKAGE_PATH指向my_model目录。

See also the documentation on recommended project structure . 另请参阅有关建议项目结构的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM