遇到Call initializer instance with the dtype argument instead of passing it to the constructor问题

在mask rcnn中训练自己的数据集到时候遇到

img


应该是过期用法的问题,到警告中相对应的文件里面找到对应的代码

    if dtype is None:
        dtype = floatx()
    tf_dtype = _convert_string_dtype(dtype)
    return variable(tf.constant_initializer(0., dtype=tf_dtype)(shape),
                    dtype, name)

这该怎么改啊?

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 这篇博客: TensorFlow 参数初始化方法中的 tf.ones_initializer(dtype) 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:

    生成一个初始值全为1的tensor对象

     


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^

该回答通过自己思路及引用到GPTᴼᴾᴱᴺᴬᴵ搜索,得到内容具体如下:
这个警告是因为 TensorFlow 2.x 中 tf.Variable 的构造函数中不再支持 dtype 参数。正确的方式是在传递张量时指定数据类型,或者在构造函数中使用 dtype 参数进行初始化。如果你的代码中使用了过期的 dtype 参数,可以将其替换为 tf.dtypes.as_dtype() 函数,如下所示:

if dtype is None:
    dtype = floatx()
tf_dtype = tf.dtypes.as_dtype(dtype)
return variable(tf.constant_initializer(0., dtype=tf_dtype)(shape),
                dtype=tf_dtype, name=name)

这样就可以避免这个警告了。但是在修改代码之前,建议先了解 TensorFlow 2.x 中 tf.Variable 的使用方式和最佳实践。


如果以上回答对您有所帮助,点击一下采纳该答案~谢谢