如何解决AttributeError:模块“ tensorflow_core.keras.layers.experimental.preprocessing”没有属性“ RandomFlip”
我使用Tensorflow 2.1.0 在这段代码中
data_augmentation = tf.keras.Sequential([
tf.keras.layers.experimental.preprocessing.RandomFlip('horizontal'),tf.keras.layers.experimental.preprocessing.RandomRotation(0.3)
])
我发现此错误:
AttributeError: module 'tensorflow_core.keras.layers.experimental.preprocessing' has no attribute 'RandomFlip'
那么如何在不更改tensorflow版本的情况下进行更改
解决方法
要按预期工作代码,首先必须将Tensorflow升级到最新版本
! pip install tensorflow --upgrade
如果您正在TF 2.1.0中寻找解决方案,那么有两个选项可用
第一个解决方案:tf.image.random_flip_left_right(水平翻转)
tf.image.random_flip_left_right(
image,seed=None)
第二个解决方案:tf.keras.preprocessing.image.ImageDataGenerator
tf.keras.preprocessing.image.ImageDataGenerator(
rotation_range=30,horizontal_flip=True)
,
! pip install tensorflow --upgrade --user
--user
选项可以在没有权限问题的情况下为您提供帮助
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。