提问人:Jane Sully 提问时间:5/11/2021 最后编辑:InnatJane Sully 更新时间:5/12/2021 访问量:416
在 tensorflow 中加载 tiff 图像来抑制警告似乎不起作用?
Suppress warnings with loading tiff images in tensorflow doesn't seem to work?
问:
使用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')
如何禁止显示此警告,或者解决产生警告的问题?
答:
1赞
furas
5/12/2021
#1
如果你想抑制所有警告,那么你可以使用
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")
评论
0赞
Jane Sully
5/12/2021
感谢您的帮助!我有一个后续问题。我可以使用相同的格式来指定/禁止显示多个警告吗?我的理解是,我会为每个警告复制最小示例。还有和 和有什么不一样?我试图过滤另一个警告,但这似乎不起作用。filterwarnings
warn
PNG warning: iCCP: known incorrect sRGB profile
message=.*known incorrect sRGB profile
0赞
furas
5/12/2021
warn
生成警告。我用它来证明它正在工作。如果要过滤所有警告,请使用 .仅当消息由 生成并在之前使用时,所有这些操作才有效。如果你在之后使用,那么它就无法阻止它。如果导入的模块中有警告,则必须在导入之前使用fiter。有些警告可能是正常的,然后你就无法阻止它。filterwarnings
warnings.filterwarnings("ignore")
warn()
filterwarnings()
warn
filterwarnings
warn
print()
上一个:了解编译指示
下一个:禁用来自特定模块的所有警告
评论
warnings