如何从自定义AI平台模型登录 [英] How to log from a custom ai platform model

查看:86
本文介绍了如何从自定义AI平台模型登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在Google Cloud的AI平台上部署了自定义模型,并且尝试调试预处理逻辑的某些部分.但是,我的打印语句未记录到stackdriver输出中.我也尝试使用从google.cloud导入的日志记录客户端,但无济于事.这是我的自定义预测文件:

I recently deployed a custom model to google cloud's ai-platform, and I am trying to debug some parts of my preprocessing logic. However, My print statements are not being logged to the stackdriver output. I have also tried using the logging client imported from google.cloud, to no avail. Here is my custom prediction file:

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 "[]"
    else:
      return [self._class_names[index] for index in np.argmax(outputs.tolist(), axis=1)]

  @classmethod
  def from_path(cls, model_dir):
    model_path = os.path.join(model_dir, 'model.h5')
    model = tf.keras.models.load_model(model_path, custom_objects={"adam": tf.keras.optimizers.Adam, 
 "categorical_crossentropy":tf.keras.losses.categorical_crossentropy, "lr":0.01, "name": "Adam"})

    preprocessor_path = os.path.join(model_dir, 'preprocessor.pkl')
    with open(preprocessor_path, 'rb') as f:
      preprocessor = pickle.load(f)

    return cls(model, preprocessor)

我无法在线找到任何有关为什么我的日志未显示在堆栈驱动程序中的信息(打印语句和日志记录库调用均未显示).有人遇到过这个问题吗?

I can't find anything online for why my logs are not showing up in stackdriver (neither print statements nor the logging library calls). Has anyone faced this issue?

谢谢, 尼基塔(Nikita)

Thanks, Nikita

注意:如果您有足够的代表来创建标签,请在此帖子中添加google-ai-platform标签.我认为这确实可以帮助处于我位置的人.谢谢!

NOTE: If you have enough rep to create tags please add the google-ai-platform tag to this post. I think it would really help people who are in my position. Thanks!

推荐答案

如果您只希望打印工作而不使用上方的日志记录方法,则可以在打印文件中添加冲洗标志,

If you just want your print to work and not use the logging method above me you can just add flush flag to your print,

print("logged",flush=True)

这篇关于如何从自定义AI平台模型登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆