我正在尝试使用以下深度学习 CNN 架构:DenseNet169 & EfficientNet with transfer learning。我已经安装了以下库 bu PyCharm 并调用了以下导入库:
from keras.models import Model
from keras.layers import Dense, GlobalAveragePooling2D
from keras.preprocessing.image import ImageDataGenerator
from keras.optimizers import SGD, RMSprop
from keras.callbacks import ModelCheckpoint
from keras.callbacks import History
from keras import applications
import keras_applications
#Transfer Learning Networks Models
# 5 - DensNet family
import densenet
from keras.applications.densenet.DenseNet121 import DenseNet121
from keras.applications.densenet.DenseNet169 import DenseNet169
from keras.applications.densenet.DenseNet201 import DenseNet201
from keras_applications.densenet.DenseNet121 import DenseNet121
from keras_applications.densenet.DenseNet169 import DenseNet169
from keras_applications.densenet.DenseNet201 import DenseNet201
# 6 - EfficientNet Alone
import efficientnet.keras as efn
# 6 - EfficientNet family
from efficientnet import EfficientNetB0
from efficientnet import EfficientNetB1
from efficientnet import EfficientNetB2
from efficientnet import EfficientNetB3
from efficientnet import EfficientNetB4
from efficientnet import EfficientNetB5
from efficientnet import EfficientNetB6
from efficientnet import EfficientNetB7
我称之为以下架构:
下载预训练模型和权重
elif model_tl_name == 'DenseNet169':
print("base_model = DenseNet169")
base_model = densenet.DenseNetImageNet169(include_top=True, input_shape=(224, 224, 3), input_tensor=None, pooling=None, classes=1000)
#base_model = DenseNet169(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
elif model_tl_name == 'EfficientNetB5':
print("base_model = EfficientNetB5")
#base_model = EfficientNetB5(include_top=False, weights='imagenet')
base_model = efn.EfficientNetB5(include_top=False, weights='imagenet')
# model = EfficientNetB3(weights='imagenet', include_top=False, input_shape=(img_size, img_size, 3))
# Changing last layer to adapt to two classes
model = add_new_last_layer(base_model, nb_classes)
但我总是收到以下错误消息:
对于 DenseNet169:mask = node.output_masks[tensor_index] AttributeError: 'Node' object has no attribute 'output_masks'
对于来自 keras.applications 的 EfficientNetB5 导入 EfficientNetB5 文件“C:\Users\QTR7701\AppData\Local\Programs\Python\Python37\lib\site-packages\efficientnet\initializers.py”,第 44 行,调用 return tf.random_normal( AttributeError:模块“tensorflow”没有属性“random_normal”
如果有人可以帮助我。