我在 Google AI Platform 上部署了一个模型,如下图所示:
这是一个使用 Keras 构建的模型,并使用save_model
带有标准选项的命令保存。
当我去虚拟测试模型以查看它是否有效时,我将输入一个示例 JSON 请求,如下所示:
{"instances": [
{"values": ["This is my first sentence"], "key": 1}
]}
我正在关注此 URL 中给出的示例: https ://cloud.google.com/ai-platform/prediction/docs/online-predict?hl=en_US#formatting_your_input_for_online_prediction
当我将示例 JSON 请求输入到评估器中时,如下所示:
我收到以下错误消息:
{"error": "{\n \"error\": \"Failed to process element: 0 key: values of 'instances' list. Error: Invalid argument: JSON object: does not have named input: values\"\n}"}
经过一番查看,问题似乎出在 tf.Serving 上,因为 JSON 输入期望除“值”键之外的其他内容来进行预测。
我的问题是我不知道如何访问应该是什么。
我最好的尝试是在本地重新加载模型并调用该get_config()
方法以查看那里是否有任何东西。
这返回了以下字典:
{'name': 'functional_1',
'layers': [{'class_name': 'InputLayer',
'config': {'batch_input_shape': (None, 1),
'dtype': 'string',
'sparse': False,
'ragged': False,
'name': 'input_1'},
'name': 'input_1',
'inbound_nodes': []},
{'class_name': 'TextVectorization',
'config': {'name': 'text_vectorization',
'trainable': True,
'dtype': 'string',
'max_tokens': 12500,
'standardize': 'lower_and_strip_punctuation',
'split': 'whitespace',
'ngrams': None,
'output_mode': 'int',
'output_sequence_length': 250,
'pad_to_max_tokens': True},
'name': 'text_vectorization',
'inbound_nodes': [[['input_1', 0, 0, {}]]]},
{'class_name': 'Embedding',
'config': {'name': 'embedding',
'trainable': True,
'batch_input_shape': (None, None),
'dtype': 'float32',
'input_dim': 12500,
'output_dim': 25,
'embeddings_initializer': {'class_name': 'RandomUniform',
'config': {'minval': -0.05, 'maxval': 0.05, 'seed': None}},
'embeddings_regularizer': None,
'activity_regularizer': None,
'embeddings_constraint': None,
'mask_zero': False,
'input_length': None},
'name': 'embedding',
'inbound_nodes': [[['text_vectorization', 0, 0, {}]]]},
{'class_name': 'Flatten',
'config': {'name': 'flatten',
'trainable': True,
'dtype': 'float32',
'data_format': 'channels_last'},
'name': 'flatten',
'inbound_nodes': [[['embedding', 0, 0, {}]]]},
{'class_name': 'Dense',
'config': {'name': 'dense',
'trainable': True,
'dtype': 'float32',
'units': 50,
'activation': 'relu',
'use_bias': True,
'kernel_initializer': {'class_name': 'GlorotUniform',
'config': {'seed': None}},
'bias_initializer': {'class_name': 'Zeros', 'config': {}},
'kernel_regularizer': None,
'bias_regularizer': None,
'activity_regularizer': None,
'kernel_constraint': None,
'bias_constraint': None},
'name': 'dense',
'inbound_nodes': [[['flatten', 0, 0, {}]]]},
{'class_name': 'Dense',
'config': {'name': 'dense_1',
'trainable': True,
'dtype': 'float32',
'units': 50,
'activation': 'relu',
'use_bias': True,
'kernel_initializer': {'class_name': 'GlorotUniform',
'config': {'seed': None}},
'bias_initializer': {'class_name': 'Zeros', 'config': {}},
'kernel_regularizer': None,
'bias_regularizer': None,
'activity_regularizer': None,
'kernel_constraint': None,
'bias_constraint': None},
'name': 'dense_1',
'inbound_nodes': [[['dense', 0, 0, {}]]]},
{'class_name': 'Dense',
'config': {'name': 'dense_2',
'trainable': True,
'dtype': 'float32',
'units': 1,
'activation': 'sigmoid',
'use_bias': True,
'kernel_initializer': {'class_name': 'GlorotUniform',
'config': {'seed': None}},
'bias_initializer': {'class_name': 'Zeros', 'config': {}},
'kernel_regularizer': None,
'bias_regularizer': None,
'activity_regularizer': None,
'kernel_constraint': None,
'bias_constraint': None},
'name': 'dense_2',
'inbound_nodes': [[['dense_1', 0, 0, {}]]]}],
'input_layers': [['input_1', 0, 0]],
'output_layers': [['dense_2', 0, 0]]}
我希望我正在寻找的一些信息会包含在这里,并且我已经尝试过类似'functional_1'
和input_1
作为使用键的东西,但没有成功。
我也尝试过用于X
数据集中的原始列,但没有奏效。
如何访问 tf.Serving 的元数据以了解将什么放入我的 JSON 请求中?