How to serialize tensorflow tensor as raw byte string

Viewed 549

I'm trying to get tensorflow to write a tensor to something that would be ingestible by ffmpeg (e.g. PCM 32-bit floating-point little-endian). I'm not seeing a simple way to do this. tf.io.serialize_tensor seems to transform to TensorProto proto.

I can't use tensorflow-io because this needs to work in tensorflow-serving. tf.audio.write_wav doesn't work because it only supports a bit-depth of int16 and I need float32.

I'd like something like:

serialized_foo = magic_encoding(foo)  # foo is a tensor of type float32 and serialized_foo is a string
tf.io.write_file("foo.raw", serialized_foo)

It seems like tf.io.serialize_tensor gets part of the way there. From what I can tell quickly inspecting the file, the protobuf format appears to be the raw byte string plus some sort of short header? Would it be possible just to modify the output of tf.io.serialize_tensor slightly, dropping the header?

0 Answers
Related