问题描述
我正在使用一个 ML 库,它迫使我将输入作为带有 dtype float32
的 numpy 数组提供。
但是在 Tensorflow 方面,我想输入包含字符串的张量。因此,我将字符串存储到 float32
numpy 数组中。 ML 库然后将其转换为 float32
张量,我想将其转换回字符串张量。
在代码中我想做什么:
# Convert the input string to a numpy array
np_buf = np.frombuffer(input_string)
# Pad the array so they have the same length.
buf_size = np.size(np_buf)
np_buf = np.pad(np_buf,(0,self.topdown_binary_max_size - buf_size),mode="constant",)
# My ML library stacks multiple arrays and converts them to a tensor of shape (batchsize,self.topdown_binary_max_size). This is outside my control
stack = tf.convert_to_tensor([np_buf,np_buf,...,np_buf])
# Now I want to convert stack (which is of dtype `float32`) back to a tensor which contains [input_string,input_string,input_string]
我怎么能这样做?最好我不想将其作为 tf 操作。
我想在 tensorflow 之外我会遍历堆栈并使用 numpy.recarray.tobytes
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)