Tensorflow 2 / Google Colab / EfficientNet培训-AttributeError:“节点”对象没有属性“输出掩码”

问题描述 投票:0回答:1

[我正在尝试在Google Colab上训练EfficientNetB1,并使用来自Keras或Tensorflow.Keras的正确导入语句不断遇到不同的问题,目前这就是我的导入效果

import tensorflow as tf
from tensorflow.keras import backend as K 
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.python.keras.layers.pooling import AveragePooling2D
from tensorflow.keras.applications import ResNet50
from tensorflow.keras.models import Model
from tensorflow.keras.optimizers import SGD
from sklearn.preprocessing import LabelBinarizer
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
from imutils import paths
import matplotlib.pyplot as plt
import numpy as np
import argparse
import pickle
import cv2
import os
from sklearn.metrics import confusion_matrix
from sklearn.utils.multiclass import unique_labels
import efficientnet.keras as enet
from tensorflow.keras.layers import Dense, Dropout, Activation, BatchNormalization, Flatten, Input

这就是我的模型的样子

 load the ResNet-50 network, ensuring the head FC layer sets are left
# off
baseModel = enet.EfficientNetB1(weights="imagenet", include_top=False, input_tensor=Input(shape=(224, 224, 3)), pooling='avg')

# Adding 2 fully-connected layers to B0.
x = baseModel.output
x = BatchNormalization()(x)
x = Dropout(0.7)(x)

x = Dense(512)(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = Dropout(0.5)(x)

x = Dense(512)(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)


# Output layer
predictions = Dense(len(lb.classes_), activation="softmax")(x)

model = Model(inputs = baseModel.input, outputs = predictions)

# loop over all layers in the base model and freeze them so they will
# *not* be updated during the training process
for layer in baseModel.layers:
    layer.trainable = False

但是对于我的一生,我无法弄清楚为什么我得到以下错误

AttributeError                            Traceback (most recent call last)
<ipython-input-19-269fe6fc6f99> in <module>()
----> 1 baseModel = enet.EfficientNetB1(weights="imagenet", include_top=False, input_tensor=Input(shape=(224, 224, 3)), pooling='avg')
      2 
      3 # Adding 2 fully-connected layers to B0.
      4 x = baseModel.output
      5 x = BatchNormalization()(x)

5 frames
/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py in _collect_previous_mask(input_tensors)
   1439             inbound_layer, node_index, tensor_index = x._keras_history
   1440             node = inbound_layer._inbound_nodes[node_index]
-> 1441             mask = node.output_masks[tensor_index]
   1442             masks.append(mask)
   1443         else:

AttributeError: 'Node' object has no attribute 'output_masks'
tensorflow keras tensorflow2.0 keras-layer efficientnet
1个回答
0
投票

不确定,但是此错误可能是由错误的TF版本引起的。默认情况下,Google Colab现在附带TF1.x。尝试此操作以更改TF版本,然后查看是否可以解决问题。

try:
    %tensorflow_version 2.x
except:
    print("Failed to load")
© www.soinside.com 2019 - 2024. All rights reserved.