如何解决在 tensorflow 中通过加载 tiff 图像抑制警告似乎不起作用?
我在使用 tfio.experimental.image.decode_tiff 时不断收到以下警告。我发现它工作正常,但不断发出这些警告,我想抑制这些警告。
TIFFFetchnormalTag: Warning,ASCII value for tag "DateTime" contains null byte in value; value incorrectly truncated during reading due to implementation limitations.
我使用它如下:
string = tf.io.read_file(filename)
image = tfio.experimental.image.decode_tiff(string) # this line produces warning
如果我尝试使用 warning
抑制警告,它似乎不起作用?它没有给我一个错误,但它没有做任何事情。
import warnings
warnings.filterwarnings('ignore',message='ASCII value for tag "DateTime" contains null byte in value; value incorrectly truncated during reading due to implementation limitations')
我怎样才能抑制这个警告,或者解决产生警告的问题?
解决方法
如果你想抑制所有警告,那么你可以使用
warnings.filterwarnings("ignore")
如果要抑制某些消息,则必须在消息开头使用 message=...
或在开头使用 .*
warnings.filterwarnings("ignore",message=".*ASCII value for tag")
最小示例:
import warnings
warnings.filterwarnings("ignore",message=".*ASCII value for tag")
# some tests - it should be supressed by `filterwarnings()`
warnings.warn('TIFFFetchNormalTag: Warning,ASCII value for tag "DateTime" contains null byte in value; value incorrectly truncated during reading due to implementation limitations.')
print("Hello World")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。