【问题标题】:Correctly formatting JSON for tensorflow serving LSTM为 tensorflow 服务 LSTM 正确格式化 JSON
【发布时间】:2021-07-06 09:41:16
【问题描述】:

我有一个 tensorflow LSTM 模型,其中预测函数的输入是 100 行 5 列。 numpy数组为1,100,5时的形状。

我正在努力解决如何正确格式化 JSON 请求以将其发送到 tensorflow 服务端点。当前托管在谷歌云上,但可能最终成为 tensorflow 服务 docker 镜像。

任何关于如何正确格式化数据以发送到 TF 的帮助都会非常有用,因为我正在努力在他们的文档中找到正确的格式。

谢谢!

【问题讨论】:

    标签: python tensorflow google-cloud-platform


    【解决方案1】:

    可以将 json 文件作为 dict 加载。因此,假设您有 5 个功能,您可以像这样格式化它:

      {
       "feature1": [...],
       "feature2": [...],
       "feature3": [...],
       "feature4": [...],
       "feature5": [...]
      }
    

    然后您可以将 dict 转换为列表列表,然后将其转换为 numpy 数组。注意:如果您将数组存储为字符串,您可以使用列表推导来转换它们。

    with open('data.json') as json_file:
        data = json.load(json_file)
        # if list of strings
        f1 = [float(i) for i in data['feature1']]
        f2 = [float(i) for i in data['feature2']]
        f3 = [float(i) for i in data['feature3']]
        f4 = [float(i) for i in data['feature3']]
        f5 = [float(i) for i in data['feature5']]
    
        sample = np.array([f1,f2,f3,f4,f5])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-05
      • 1970-01-01
      • 2016-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-02
      相关资源
      最近更新 更多