将元数据添加到tensorflow服务api调用

问题描述 投票:2回答:1

是否可以将元数据添加到服务于servable的张量流中,以便此元数据也填充在来自servable的响应中?

如果我有一个文件结构的servable:

my_servable/ 
           1541778457/ 
                     variables/ 
                     saved_model.pb 

例如:

```
outputs {
  key: "classes"
  value {
    dtype: DT_STRING
    tensor_shape {
      dim {
        size: 8
      }
    }
    string_val: "a"
    string_val: "b"
    string_val: "c"
    string_val: "d"
    string_val: "e"
    string_val: "f"
    string_val: "g"
    string_val: "h"
  }
}
outputs {
  key: "scores"
  value {
    dtype: DT_FLOAT
    tensor_shape {
      dim {
        size: 1
      }
      dim {
        size: 8
      }
    }
    float_val: 1.212528104588273e-06
    float_val: 5.094948463124638e-08
    float_val: 0.0009737954242154956
    float_val: 0.9988483190536499
    float_val: 3.245145592245535e-07
    float_val: 0.00010837535955943167
    float_val: 4.101086960872635e-05
    float_val: 2.676981057447847e-05
  }
}
model_spec {
  name: "my_model"
  version {
    value: 1541778457
  }
  signature_name: "prediction"
}

如果我有类似git哈希或生成此可服务的代码的唯一标识符(如f6ca434910504532a0d50dfd12f22d4c),是否可以在客户端请求中获取此数据?

理想情况如下:

```
outputs {
  key: "classes"
  value {
    dtype: DT_STRING
    tensor_shape {
      dim {
        size: 8
      }
    }
    string_val: "a"
    string_val: "b"
    string_val: "c"
    string_val: "d"
    string_val: "e"
    string_val: "f"
    string_val: "g"
    string_val: "h"
  }
}
outputs {
  key: "scores"
  value {
    dtype: DT_FLOAT
    tensor_shape {
      dim {
        size: 1
      }
      dim {
        size: 8
      }
    }
    float_val: 1.212528104588273e-06
    float_val: 5.094948463124638e-08
    float_val: 0.0009737954242154956
    float_val: 0.9988483190536499
    float_val: 3.245145592245535e-07
    float_val: 0.00010837535955943167
    float_val: 4.101086960872635e-05
    float_val: 2.676981057447847e-05
  }
}
model_spec {
  name: "my_model"
  version {
    value: 1541778457
  }
  hash {
    value: f6ca434910504532a0d50dfd12f22d4c
 }
  signature_name: "prediction"
}

我尝试将目录从1541778457更改为哈希,但这给了:

W tensorflow_serving/sources/storage_path/file_system_storage_path_source.cc:268] No versions of servable default found under base path

tensorflow-serving
1个回答
0
投票

我想你可以通过几种方式解决这个问题。如果您希望更改文件夹名称的想法,请记住在这种情况下文件夹名称描述您的模型版本,我认为必须是整数。因此,我假设您需要将哈希值转换为二进制或十进制,然后在收到它时将其转换回来。

我认为更好的解决方案是,如果您能够更改模型并添加包含哈希值的变量。并将其添加到模型signature_def中。在python中看起来像:

// create your field
hash = tf.placeholder("f6ca434910504532a0d50dfd12f22d4c",tf.string, name="HASH")

// build tensor
hash_info = tf.saved_model.utils.build_tensor_info(hash)

// add hash_info in your output in signature_def

// then you should be able to receive that data in your request
© www.soinside.com 2019 - 2024. All rights reserved.