TensorFlow 集成
MLeap TensorFlow 的 Transformer 被编译在一个 TensorFlow Graph 文件当中,这个文件通过调用 方法生成。当第一个请求要求转换 Leap Frame 的时候,这个 Transformer 会被惰性初始化。会话一旦已经开始,就会维持打开状态,直到 Transformer 的 close
方法被调用。
TensorFlow Transformer 处理 Leap Frame 之前,需要保证 Leap Frame 中的数据的格式正确。参见类型转换小节了解如何将数据转换为 TensorFlow 类型。
MLeap TensorFlow 模型负责维护 TensorFlow 会话,它是一个 Java Closeable
实现,需要在 MLeap Transformer 和其他控制对象不再需要资源之后关闭。模型也会在 finalized
阶段关闭会话,以防用户忘记调用该方法。模型的输出是 MLeap 对象的 Seq
序列,Tensor
对象包含按照对应 shape 指定顺序排序的输出数据。
为了让 TensorFlow 支持兼容 MLeap 数据类型的 Transformer,我们需要以下信息:
下表为我们目前所支持的 TensorFlow 数据类型。
Tensorflow 数据类型 | MLeap 数据类型 |
---|---|
DT_BOOLEAN | BooleanType |
DT_STRING | StringType |
DT_INT32 | IntegerType |
DT_INT64 | LongType |
DT_FLOAT | FloatType |
DT_DOUBLE | DoubleType |
Tensor | TensorType |
因为 Swig 封装器目前还未支持所有的数据类型,我们建议为你的 MLeap TensorFlow Graph 添加一个强制转换操作。
Notes | 注意
- Swig 封装器尚未支持无符号整形,8 位和 16 位整型。
- Swig 封装器尚未支持复杂类型。
实例
数据类型
Field | Data Type |
---|---|
double1 | DoubleType() |
tensor1 | TensorType(DoubleType(false)) |
如果我们使用一个 TensorFlow Transformer 来处理以上的 Leap Frame,这个 Transformer 使用 double1
来归一化 tensor1
向量,并指定了我们的结果 Tensor,那么输出的 Leap Frame 会类似于:
数据类型
Field | Data Type | Notes |
---|---|---|
double1 | DoubleType() | |
tensor1 | TensorType(DoubleType(false)) | |
raw_tf_tensors | ListType(AnyType(false)) | 返回类型未知,不允许为 null 值 |
output1 | TensorType(DoubleType(false)) | 底层数据类型此时已知,并反射为 LeapFrame 中的数据类型。 |