gpt4 book ai didi

tensorflow2.x - 属性错误 : module 'tensorflow_core.keras.layers.experimental.preprocessing' has no attribute 'RandomFlip'

转载 作者:行者123 更新时间:2023-12-03 21:10:57 30 4
gpt4 key购买 nike

我使用 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)

关于tensorflow2.x - 属性错误 : module 'tensorflow_core.keras.layers.experimental.preprocessing' has no attribute 'RandomFlip' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63899220/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com