Google cloud platform 向Google Cloud ML提交培训作业

Google cloud platform 向Google Cloud ML提交培训作业,google-cloud-platform,google-cloud-ml,Google Cloud Platform,Google Cloud Ml,我有一个代码如下,我想提交给谷歌云ml。我已经测试了他们的例子,并得到了结果 from __future__ import absolute_import from __future__ import division from __future__ import print_function import tensorflow as tf import numpy as np # Data sets I_TRAINING = "/home/android/Desktop/training.

我有一个代码如下,我想提交给谷歌云ml。我已经测试了他们的例子,并得到了结果

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf
import numpy as np

# Data sets
I_TRAINING = "/home/android/Desktop/training.csv"
I_TEST = "/home/android/Desktop/test.csv"

# Load datasets.
training_set = tf.contrib.learn.datasets.base.load_csv(filename=I_TRAINING, target_dtype=np.int)
test_set = tf.contrib.learn.datasets.base.load_csv(filename=I_TEST, target_dtype=np.int)

# Specify that all features have real-value data
feature_columns = [tf.contrib.layers.real_valued_column("", dimension=2)]

# Build 3 layer DNN with 10, 20, 10 units respectively.
classifier = tf.contrib.learn.DNNClassifier(feature_columns=feature_columns,
                                            hidden_units=[10, 20, 10],
                                            n_classes=2,
                                            model_dir="/tmp/my_model")

# Fit model.
classifier.fit(x=training_set.data, y=training_set.target, steps=2000)

# Evaluate accuracy.
accuracy_score = classifier.evaluate(x=test_set.data, y=test_set.target)["accuracy"]
print('Accuracy: {0:f}'.format(accuracy_score))

# Classify two new flower samples.
#new_samples = np.array(
 #   [[6.4, 3.2, 4.5, 1.5], [5.8, 3.1, 5.0, 1.7]], dtype=float)
#y = classifier.predict(new_samples)
#print('Predictions: {}'.format(str(y)))
这是在tensorflow中训练和创建DNN模型的代码。我已经在本地进行了测试,并收到了结果。我将此代码与init.py文件一起放在名为trainer的文件夹中,并将该文件夹上载到gs://bucket ml/second\u job/trainer。第二个作业是作业名称

然后,当我想将其作为作业提交时,我执行此操作并得到以下错误:

gcloud beta ml jobs submit training ${JOB_NAME}  \ 
--package-path=trainer   \
--module-name=trainer.trainer   \
--staging-bucket="${TRAIN_BUCKET}"   \
--region=us-central1   \
--train_dir="${TRAIN_PATH}/train"

ERROR: (gcloud.beta.ml.jobs.submit.training) 
    Packaging of user python code failed with message:
      running sdist
running egg_info
creating trainer.egg-info
writing trainer.egg-info/PKG-INFO
writing top-level names to trainer.egg-info/top_level.txt
writing dependency_links to trainer.egg-info/dependency_links.txt
writing manifest file 'trainer.egg-info/SOURCES.txt'
error: package directory 'trainer' does not exist
    Try manually writing a setup.py file at your package root
    and rerunning the command
我不确定包路径和模块名是否正确。请告诉我该怎么办。谢谢 在这方面,

gcloud命令的
--package path
参数应该指向一个有效Python包的目录,即包含
\uuu init\uuuu.py
文件(通常是空文件)的目录。请注意,它应该是本地目录,而不是GCS上的目录

--module
参数将是该包中有效Python模块的完全限定名。您可以随意组织目录,但为了保持一致性,所有示例都有一个名为
trainer
的Python包,其中要运行的模块名为
task.py

示例的目录结构如下所示:

trainer/
  __init__.py
  task.py
\uuuu init\uuuuu.py
很可能是一个空文件<代码>任务。py包含您的代码。然后,您可以按如下方式提交您的作业:

gcloud beta ml jobs submit training ${JOB_NAME}  \ 
  --package-path=trainer   \
  --module-name=trainer.task   \
  --staging-bucket="${TRAIN_BUCKET}"   \
  --region=us-central1   \
  -- \
  --train_dir="${TRAIN_PATH}/train"
您可以为包和模块选择任何名称,只需确保磁盘上的名称与gcloud参数匹配:顶级目录为
--包路径
,运行代码的文件为
--模块
(不带
.py
后缀)

请注意:

  • 请注意额外的“--\”。这表示应将以下所有参数传递给程序。也就是说,-train_dir不是gcloud beta ml jobs提交培训的参数,它将作为一个标志传递给您的程序
  • 如果您打算使用train_dir,则需要在代码中添加一些标志解析,例如使用argparse
  • 您在云中读取的文件需要在GCS上
  • 虽然标记解析为您提供了更大的灵活性,但这不是必需的。您可以对文件名的路径进行硬编码。只需确保它们指向GCS上的对象(然后从gcloud呼叫中删除
    --train_dir

请注意,这与您的问题直接相关,但我发现您已经硬编码了数据集的路径,这些路径是本地目录。在提交到云之前,您需要确保这些指向GCS对象。非常感谢!现在我知道--package path相对于我来说是本地的(在我的机器上是本地的),而不是相对于谷歌云。关于--package path=trainer,我应该如何将路径写入package(trainer文件夹)?我正在使用windows。我试过C:\trainer,“C:\trainer”,但不起作用。它说找不到目录。我一直在使用gcloud shell在线版本。我应该安装云sdk并从我的机器提交作业吗?我这样做了,已经两个小时了,python.exe使用了我100%的磁盘,但仍然没有答案。这正常吗?有人能帮我吗?谢谢。很遗憾,目前不支持Windows。快速入门建议您使用Cloud Shell。你有这种可能性吗?看见