WARNING:tensorflow:AutoGraph could not transform xxx and will run it as-is 的一种解决思路

警告内容:
WARNING:tensorflow:AutoGraph could not transform <bound method TensorflowDataset.load_and_preprocess_image of <__main__.TensorflowDataset object at 0x7fc8d36be3d0>> and will run it as-is.
Cause: mangled names are not yet supported
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert

一般来说,警告可以被忽视。但是相关操作时比较重要的一环,因此不希望其出现任何问题。
不过百度、谷歌得到的解决方案并不尽人意。

结合自己的代码特征,考虑是因为私有方法格式的原因。
如下所示:

# 类中的内容
image_ds = path_ds.map(self.__load_and_preprocess_image, num_parallel_calls=tf.data.AUTOTUNE)

def __preprocess_image(self, image):
    image = tf.image.decode_jpeg(image, channels=3)
    image = tf.image.resize(image, self.initialMeta["presize"])
    image /= 255.0  # normalize to [0,1] range
    return image

def __load_and_preprocess_image(self, path):
    image = tf.io.read_file(path)
    return self.__preprocess_image(image)

最后,我放弃使用私有方法,消除了警告内容。
即:

image_ds = path_ds.map(self.load_and_preprocess_image, num_parallel_calls=tf.data.AUTOTUNE)

def preprocess_image(self, image):
    image = tf.image.decode_jpeg(image, channels=3)
    image = tf.image.resize(image, self.initialMeta["presize"])
    image /= 255.0  # normalize to [0,1] range
    return image

def load_and_preprocess_image(self, path):
    image = tf.io.read_file(path)
    return self.preprocess_image(image)

以上说明,tensorflow框架中的tf.dataAPI中的方法使用,可以比较稳定的在类中进行,但是涉及到私有方法时可能会出现一些问题,因此平时编写代码时应该努力这种写法。

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值