有什么办法可以将字符串张量转换为小写,而无需在会话中求值?某种tf.string_to_lower
操作?
更具体地说,我从tfrecords
文件中读取数据,因此我的数据由张量组成。然后,我想使用它tf.contrib.lookup.index_table_from_*
来查找数据中单词的索引,并且我需要使它不区分大小写。在将数据写入之前降低数据tfrecords
不是一种选择,因为它需要以原始格式保存。一种选择是同时存储原始图像和降低的图像,但如果可能的话,我想避免这种情况。
您可以使用tf.py_func
python 函数来操作字符串并在图表中执行。
你可以这样做:
# 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)
归档时间: |
|
查看次数: |
1686 次 |
最近记录: |