Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SageMaker Tensorflow-如何编写我的服务输入_Tensorflow_Amazon Sagemaker - Fatal编程技术网

SageMaker Tensorflow-如何编写我的服务输入

SageMaker Tensorflow-如何编写我的服务输入,tensorflow,amazon-sagemaker,Tensorflow,Amazon Sagemaker,我对Tensorflow和SageMaker还很陌生,我正试图弄清楚如何编写我的服务输入

我对Tensorflow和SageMaker还很陌生,我正试图弄清楚如何编写我的
服务输入
。我试过很多方法,但都没有用

“我的输入”函数有3个功能列:
amount\u normalized、x\u month和y\u month

def construct_feature_columns():
    amount_normalized = tf.feature_column.numeric_column(key='amount_normalized')
    x_month = tf.feature_column.numeric_column(key='x_month')
    y_month = tf.feature_column.numeric_column(key='y_month')
    return set([amount_normalized, x_month, y_month])
我希望能够使用
deployed\u model.predict([1.23,0.3,0.8])之类的东西调用我的部署模型。

其中第一个元素是
amount\u normalized
,第二个元素是
x\u月
第三个元素是
y\u月

我试过这个:

FEATURES = ['amount_normalized', 'x_month', 'y_month']
def serving_input_fn(params):
    feature_placeholders = {
      key : tf.placeholder(tf.float32, [None]) \
        for key in FEATURES
    }
return tf.estimator.export.build_raw_serving_input_receiver_fn(feature_placeholders)()
但我得到的只是:
调用InvokeEndpoint操作时发生错误(ModelError):从模型接收到服务器错误(500),消息为“”。


非常感谢您的帮助

在此处发布此消息,以防其他人有此问题

经过一系列的尝试和错误,我通过编写如下的服务输入函数来解决我的问题:

FEATURES = ['amount_normalized', 'x_month', 'y_month']
def serving_input_fn(hyperparameters):
    feature_spec = {
        key : tf.FixedLenFeature(shape=[], dtype = tf.float32) \
          for key in FEATURES
    }
    return tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)()
然后,我可以通过传入散列来调用部署的模型:

deployed_model.predict({"amount_normalized": 2.3, "x_month": 0.2, "y_month": -0.3})