【问题标题】:Has the "ConvNeXt" family of models been removed from Keras?“ConvNeXt”系列模型是否已从 Keras 中删除?
【发布时间】:2022-11-17 06:42:34
【问题描述】:

尝试使用 Keras 的 ConvNeXtTiny 模型时,出现以下错误:AttributeError: module 'keras.applications' has no attribute 'ConvNeXtTiny'

filename = "ConvNextTiny_firstpass_model"

# layer construction
base_model = applications.ConvNeXtTiny( #preproccing included
    input_shape=(targetWidth, targetHeight, 3),
    include_top=False,
)
base_model.trainable = False

flatten_layer = layers.Flatten()
fc_layer = layers.Dense(1024, activation='relu')
dropout_layer = layers.Dropout(0.3) 

#layer connecting
x = flip_layer(input_layer)
x = base_model(x, training=False)
x = flatten_layer(x)
x = fc_layer(x)
x = dropout_layer(x)
predictions = output_layer(x)
model = keras.Model(input_layer, predictions)

这是我的进口商品:

import tensorflow as tf
import keras 
from keras import layers
from keras import optimizers
from keras import applications
from keras import losses
from keras import callbacks
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import cv2 as cv
import csv
from sklearn.utils import shuffle

可能相关的版本控制:

ipython==8.5.0
tensorflow==2.10.0
keras==2.10.0
Keras-Preprocessing==1.1.2
pandas==1.4.4
numpy==1.23.3
matplotlib==3.6.0
opencv-python==4.6.0.66
sklearn==0.0

【问题讨论】:

  • 这看起来像是 Keras 文档中缺失的一页。其他型号通过tf.keras.applications,还有一个tf.keras.applications.convnext
  • @AlexanderL.Hayes 我尝试用 applications.convnext.ConvNeXtTiny 替换 applications.ConvNeXtTiny,如文档中所示,并收到类似的错误“AttributeError: module 'keras.applications' has no attribute 'convnext'”
  • 我仍然无法重现这个问题。也许你有旧版本的 TensorFlow / Keras?在tensorflow==2.10.0 中,似乎可以这样做:from tensorflow.keras.applications import convnextfrom keras.applications import convnext
  • @AlexanderL.Hayes 我正在使用 tensorflow 版本 2.10.0。我会在早上尝试重新启动我的会话,但现在我在尝试您提到的两个导入时收到相同的错误。
  • @AlexanderL.Hayes 我对损失保持沉默。我重新启动了会话,甚至卸载并重新安装了 tensorflow,结果相同。

标签: tensorflow keras transfer-learning


【解决方案1】:

之前放置在 convnext 导入之上的导入导致了问题。

from tensorflow.keras.applications import convnext 移至所有导入项的顶部使其能够正确导入。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-14
    • 1970-01-01
    • 1970-01-01
    • 2017-01-27
    • 2018-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多