在Google Cloud ML(机器学习)中,我提交了一份作业,但由于代码中出现Python错误而失败.
修复错误后,如何重新运行该作业?我应该提交一份新工作吗?
当我完成后,如何删除这份工作?
在线文档不完整.
谢谢
设置Google Cloud ML的文档建议安装Tensorflow版本r0.11.我观察到在r0.12中新提供的TensorFlow函数在Cloud ML上运行时会引发异常.Cloud ML是否支持r0.12的时间表?r0.11和r0.12之间的切换是可选的还是强制的?
我正在尝试在google cloud ml-engine上部署一个初始模型的重新训练版本.从SavedModel文档,此参考和rhaertel80的这篇文章中收集信息,我成功地将我的再培训模型导出到SavedModel,将其上传到存储桶并尝试将其部署到ml-engine版本.
最后一个任务实际上创建了一个版本,但它输出了这个错误:
Create Version failed. Bad model detected with error: "Error loading the model: Unexpected error when loading the model"
当我尝试通过命令行从模型中获得预测时,我收到以下错误消息:
"message": "Field: name Error: Online prediction is unavailable for this version. Please verify that CreateVersion has completed successfully."
我曾经多次尝试,尝试不同的method_name和tag选择,但没有奏效.
添加到原始初始代码的代码是
### DEFINE SAVED MODEL SIGNATURE
in_image = graph.get_tensor_by_name('DecodeJpeg/contents:0')
inputs = {'image_bytes': tf.saved_model.utils.build_tensor_info(in_image)}
out_classes = graph.get_tensor_by_name('final_result:0')
outputs = {'prediction': tf.saved_model.utils.build_tensor_info(out_classes)}
signature = tf.saved_model.signature_def_utils.build_signature_def(
inputs=inputs,
outputs=outputs,
method_name='tensorflow/serving/predict'
)
### …Run Code Online (Sandbox Code Playgroud) 我正在使用Tensorflow使用我自己的数据集进行神经网络预测.我做的第一个是与我的计算机中的小数据集一起使用的模型.在此之后,我更改了代码,以便使用具有更大数据集的Google Cloud ML-Engine在ML-Engine中实现列车和预测.
我正在规范熊猫数据框中的功能,但这引入了偏差,我的预测结果很差.
我真正想要的是使用库tf-transform来规范化图中的数据.为此,我想创建一个函数preprocessing_fn 并使用' tft.scale_to_0_1'.https://github.com/tensorflow/transform/blob/master/getting_started.md
我发现的主要问题是当我试图做预测时.我正在寻找互联网,但我没有找到任何导出模型的例子,其中数据在训练中被标准化.在我发现的所有示例中,数据未在任何地方进行标准化.
我想知道的是,如果我对训练中的数据进行规范化,并发送一个带有新数据的新实例来进行预测,那么如何对这些数据进行归一化?
¿可能在Tensorflow数据管道中?进行规范化的变量是否保存在某个地方?
总结:我正在寻找一种方法来规范化我的模型的输入,然后新实例也变得标准化.
python google-cloud-platform tensorflow google-cloud-ml tensorflow-transform
我不明白如何使用TensorFlow Estimator API进行单一预测 - 我的代码导致无限循环,不断预测相同的输入.
根据文档,当input_fn引发StopIteration异常时,预测应该停止:
input_fn:返回功能的输入函数,它是Tensor或SparseTensor的字符串功能名称字典.如果它返回一个元组,则第一个项目被提取为特征.预测将继续,直到input_fn引发输入结束异常(OutOfRangeError或StopIteration).
这是我的代码中的相关部分:
classifier = tf.estimator.Estimator(model_fn=image_classifier, model_dir=output_dir,
config=training_config, params=hparams)
def make_predict_input_fn(filename):
queue = [ filename ]
def _input_fn():
if len(queue) == 0:
raise StopIteration
image = model.read_and_preprocess(queue.pop())
return {'image': image}
return _input_fn
predictions = classifier.predict(make_predict_input_fn('garden-rose-red-pink-56866.jpeg'))
for i, p in enumerate(predictions):
print("Prediction %s: %s" % (i + 1, p["class"]))
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
我正在使用Keras预测图像类.它适用于Google Cloud ML(GCML),但为了提高效率,需要将其更改为传递base64字符串而不是json数组. 相关文档
我可以轻松运行python代码将base64字符串解码为json数组,但是当使用GCML时,我没有机会运行预处理步骤(除非在Keras中使用Lambda层,但我认为不是正确的方法).
另一个答案建议添加tf.placeholder类型tf.string,这是有道理的,但如何将其纳入Keras模型?
以下是培训模型和保存GCML导出模型的完整代码...
import os
import numpy as np
import tensorflow as tf
import keras
from keras import backend as K
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras.preprocessing import image
from tensorflow.python.platform import gfile
IMAGE_HEIGHT = 138
IMAGE_WIDTH = 106
NUM_CLASSES = 329
def preprocess(filename):
# decode the image file starting from the filename
# end up with pixel values that …Run Code Online (Sandbox Code Playgroud) 我想以超快的速度将TFRecords输入我的模型.但是,目前,我的GPU(GCP上的单K80)负载为0%,这在CloudML上速度非常慢.
我在GCS中有TFRecords train_directory = gs://bucket/train/*.tfrecord:(大约100个文件,大小为30mb-800mb),但由于某种原因,它很难将数据快速地输入到我的模型中以便GPU.
有趣的是,将数据加载到内存中并使用numpy数组使用fit_generator()速度提高了7倍.在那里,我可以指定多处理和多工人.
我当前的设置解析tf记录并加载无限tf.Dataset.理想情况下,解决方案可以在内存中保存/完善一些批次,以便按需使用gpu.
def _parse_func(record):
""" Parses TF Record"""
keys_to_features = {}
for _ in feature_list: # 300 features ['height', 'weights', 'salary']
keys_to_features[_] = tf.FixedLenFeature([TIME_STEPS], tf.float32)
parsed = tf.parse_single_example(record, keys_to_features)
t = [tf.manip.reshape(parsed[_], [-1, 1]) for _ in feature_list]
numeric_tensor = tf.concat(values=t, axis=1)
x = dict()
x['numeric'] = numeric_tensor
y = ...
w = ...
return x, y, w
def input_fn(file_pattern, b=BATCH_SIZE):
"""
:param file_pattern: GCS bucket to read …Run Code Online (Sandbox Code Playgroud) 我知道可以在Google Cloud上部署用于培训作业的自定义容器,并且我已经能够使用command来运行相同的容器。
gcloud ai-platform jobs submit training infer name --region some_region --master-image-uri=path/to/docker/image --config config.yaml
Run Code Online (Sandbox Code Playgroud)
训练工作已成功完成,并且模型已成功获得。现在,我想使用该模型进行推理,但是问题是我的代码具有系统级依赖关系,因此我必须对体系结构进行一些修改才能让它一直运行。这就是首先要为培训工作提供定制容器的原因。
该文档仅适用于培训部分和推断部分(如果可能的话),而据我所知,尚未使用自定义容器进行探索。
培训部分的文档可在此链接上找到
我的问题是,是否可以在Google Cloud-ml上出于推理目的部署自定义容器?
google-cloud-platform google-cloud-ml gcp-ai-platform-notebook
我gcloud local prediction用来测试我导出的模型。该模型是在自定义数据集上训练过的 TensorFlow 对象检测模型。我正在使用以下 gcloud 命令:
gcloud ml-engine local predict --model-dir=/path/to/saved_model/ --json-instances=input.json --signature-name="serving_default" --verbosity debug
Run Code Online (Sandbox Code Playgroud)
当我不使用 verbose 时,该命令不输出任何内容。将详细设置为调试后,我得到以下回溯:
DEBUG: [Errno 32] Broken pipe
Traceback (most recent call last):
File "/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 984, in Execute
resources = calliope_command.Run(cli=self, args=args)
File "/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 784, in Run
resources = command_instance.Run(args)
File "/google-cloud-sdk/lib/surface/ai_platform/local/predict.py", line 83, in Run
signature_name=args.signature_name)
File "/google-cloud-sdk/lib/googlecloudsdk/command_lib/ml_engine/local_utils.py", line 103, in RunPredict
proc.stdin.write((json.dumps(instance) + '\n').encode('utf-8'))
IOError: [Errno 32] Broken pipe
Run Code Online (Sandbox Code Playgroud)
我的导出模型的详细信息:
MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs: …Run Code Online (Sandbox Code Playgroud) 我最近在谷歌云的人工智能平台上部署了一个自定义模型,我正在尝试调试我的预处理逻辑的某些部分。但是,我的打印语句没有被记录到 stackdriver 输出中。我也尝试使用从 google.cloud 导入的日志客户端,但无济于事。这是我的自定义预测文件:
import os
import pickle
import numpy as np
from sklearn.datasets import load_iris
import tensorflow as tf
from google.cloud import logging
class MyPredictor(object):
def __init__(self, model, preprocessor):
self.logging_client = logging.Client()
self._model = model
self._preprocessor = preprocessor
self._class_names = ["Snare", "Kicks", "ClosedHH", "ClosedHH", "Clap", "Crash", "Perc"]
def predict(self, instances, **kwargs):
log_name = "Here I am"
logger = self.logging_client.logger(log_name)
text = 'Hello, world!'
logger.log_text(text)
print('Logged: {}'.format(text), kwargs.get("sr"))
inputs = np.asarray(instances)
outputs = self._model.predict(inputs)
if kwargs.get('probabilities'):
return outputs.tolist()
#return …Run Code Online (Sandbox Code Playgroud)