Пригородный поезд на платформе gcloud с ошибкой TypeError - PullRequest
0 голосов
/ 23 февраля 2020

Я просто пытаюсь выполнить простой локальный тренировочный тест. Код, который я использую, взят из этого репозитория:

cloudacademy ml обучающий курс .

Это код тренера / iris.py:


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

import os
import pandas as pd
import tensorflow as tf

def main():

  TRAIN_URL = "http://download.tensorflow.org/data/iris_training.csv"
  TEST_URL = "http://download.tensorflow.org/data/iris_test.csv"

  CSV_COLUMN_NAMES = ['SepalLength', 'SepalWidth',
                    'PetalLength', 'PetalWidth', 'Species']
  SPECIES = ['Setosa', 'Versicolor', 'Virginica']

  def maybe_download():
    train_path = tf.keras.utils.get_file(TRAIN_URL.split('/')[-1], TRAIN_URL)
    test_path = tf.keras.utils.get_file(TEST_URL.split('/')[-1], TEST_URL)

    return train_path, test_path

  def load_data(y_name='Species'):
    """Returns the iris dataset as (train_x, train_y), (test_x, test_y)."""
    train_path, test_path = maybe_download()

    train = pd.read_csv(train_path, names=CSV_COLUMN_NAMES, header=0)
    train_x, train_y = train, train.pop(y_name)

    test = pd.read_csv(test_path, names=CSV_COLUMN_NAMES, header=0)
    test_x, test_y = test, test.pop(y_name)

    import pdb; pdb.set_trace()

    return (train_x, train_y), (test_x, test_y)

  (train_x, train_y), (test_x, test_y) = load_data()


  # Feature columns describe how to use the input.
  feature_columns = []
  for key in train_x.keys():
      feature_columns.append(tf.feature_column.numeric_column(key=key))

  # Build 3-layer DNN with 10, 20, 10 units respectively.
  classifier = tf.estimator.DNNClassifier(
    feature_columns=feature_columns,
    # Three hidden layers
    hidden_units=[10, 20, 10],
    # The model must choose between 3 classes.
    n_classes=3)

  def train_input_fn(features, labels):
    """An input function for training"""
    # Convert the inputs to a Dataset.
    dataset = tf.data.Dataset.from_tensor_slices((dict(features), labels))

    # Shuffle, repeat, and batch the examples.
    dataset = dataset.shuffle(1000).repeat().batch(100)

    # Return the dataset.
    return dataset

  classifier.train(
      input_fn=lambda:train_input_fn(train_x, train_y),
      steps=2000)


  # Define the test inputs
  def eval_input_fn(features, labels):
    """An input function for evaluation or prediction"""
    features=dict(features)
    if labels is None:
        # No labels, use only features.
        inputs = features
    else:
        inputs = (features, labels)

    # Convert the inputs to a Dataset.
    dataset = tf.data.Dataset.from_tensor_slices(inputs)

    # Batch the examples
    dataset = dataset.batch(100)

    # Return the dataset.
    return dataset

  # Evaluate the model.
  eval_result = classifier.evaluate(
    input_fn=lambda:eval_input_fn(test_x, test_y))

  print('\nTest set accuracy: {accuracy:0.3f}\n'.format(**eval_result))


  # Generate predictions from the model
  expected = ['Setosa', 'Versicolor', 'Virginica']
  predict_x = {
    'SepalLength': [5.1, 5.9, 6.9],
    'SepalWidth': [3.3, 3.0, 3.1],
    'PetalLength': [1.7, 4.2, 5.4],
    'PetalWidth': [0.5, 1.5, 2.1],
  }

  predictions = classifier.predict(
    input_fn=lambda:eval_input_fn(predict_x, labels=None))

  template = ('\nPrediction is "{}" ({:.1f}%), expected "{}"')

  for pred_dict, expec in zip(predictions, expected):
    class_id = pred_dict['class_ids'][0]
    probability = pred_dict['probabilities'][class_id]

    print(template.format(SPECIES[class_id],
                          100 * probability, expec))


if __name__ == "__main__":
  # os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
  # tf.logging.set_verbosity(tf.logging.ERROR)
  # main()
  print("hi")

Команда выглядит следующим образом:

 gcloud ai-platform local train --module-name trainer.iris

Я получаю эту ошибку:

ERROR: gcloud crashed (TypeError): startswith first arg must be bytes or a tuple of bytes, not str

Я попытался сократить код до простого:

if __name__ == "__main__":
  print("hi")

И все равно получаю ту же ошибку. Так что, похоже, проблема не в коде, а скорее в инструментах.

Я использую:

Gcloud:

Google Cloud SDK 278.0.0
alpha 2020.01.24
beta 2020.01.24
bq 2.0.52
core 2020.01.24
gsutil 4.47
kubectl 2020.01.24

Python 3.6.5

pip freeze:

absl-py==0.9.0
astor==0.8.1
gast==0.3.3
google-pasta==0.1.8
grpcio==1.27.2
h5py==2.10.0
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.0
Markdown==3.2.1
numpy==1.18.1
pandas==1.0.1
protobuf==3.11.3
python-dateutil==2.8.1
pytz==2019.3
six==1.14.0
tensorboard==1.14.0
tensorflow==1.14.0
tensorflow-estimator==1.14.0
termcolor==1.1.0
Werkzeug==1.0.0
wrapt==1.12.0

Есть идеи или предложения о том, что может быть не так?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...