将字符串张量转换为小写

Rad*_*duK 5 tensorflow

有什么办法可以将字符串张量转换为小写,而无需在会话中求值?某种tf.string_to_lower操作?

更具体地说,我从tfrecords文件中读取数据,因此我的数据由张量组成。然后,我想使用它tf.contrib.lookup.index_table_from_*来查找数据中单词的索引,并且我需要使它不区分大小写。在将数据写入之前降低数据tfrecords不是一种选择,因为它需要以原始格式保存。一种选择是同时存储原始图像和降低的图像,但如果可能的话,我想避免这种情况。

nes*_*uno 1

您可以使用tf.py_funcpython 函数来操作字符串并在图表中执行。

你可以这样做:

# I suppose your string tensor is tensorA
lower = tf.py_func(lambda x: x.lower(), [tensorA], tf.string, stateful=False)

# Starting from TF 2.0 `tf.py_func` is deprecated so correct code will be
lower = tf.py_function(lambda x: x.numpy().lower(), [tensorA], tf.string)
Run Code Online (Sandbox Code Playgroud)