【问题标题】:module 'tensorflow.keras.applications' has no attribute 'convnext'模块 \'tensorflow.keras.applications\' 没有属性 \'convnext\'
【发布时间】:2023-01-02 17:54:56
【问题描述】:

我正在尝试使用 ConvNextXLarge 并且我有以下代码:

model = tf.keras.applications.convnext.ConvNeXtXLarge(
  model_name='convnext_xlarge',
  include_top=True,
  include_preprocessing=True,
  weights='imagenet',
  input_tensor=None,
  input_shape=None,
  pooling=None,
  classes=1000,
  classifier_activation='softmax'
)

但是我得到标题中的错误:

模块“tensorflow.keras.applications”没有属性“convnext”

我很确定这与我在 Kaggle 中使用 tensorflow v2.6 但我不知道如何升级有关

【问题讨论】:

  • 对于初学者,尝试重新安装tensorflow。使用pip uninstall tensorflowpip install tensorflow。在您的代码中,存在拼写问题,不是ConvNeXtXLarge,而是ConvNextLarge。你的使用应该是这样的:tf.keras.applications.convnext.ConvNeXtLarge
  • 如果还是不行,那就尝试直接使用from tensorflow.keras.applications import ConvNeXtLarge获取,然后使用。
  • conv-next 可能对 tf 2.10 可用,重新检查。
  • 请再次尝试使用 Tensorflow 2.10 或 2.11 导入 tf.keras.applications.convnext.ConvNeXtXLarge api。您可以使用pip install --upgrade tensorflow 或提供特定版本pip install tensorflow==2.10 来升级tensorflow。

标签: python tensorflow keras kaggle transfer-learning


【解决方案1】:

Attribution convnext 在 v2.11 中来到 TensorFlow,正如你所说的更新是必要的。如果使用 pip 简单,

pip 安装 tensorflow --upgrade

, 如果您没有很多依赖关系,那很好。

【讨论】: