AttributeError: ‘tuple‘ object has no attribute ‘layer‘

AttributeError: 'tuple' object has no attribute 'layer'


Error display :
Insert picture description here

inbound_layers = nest.map_structure(lambda t: t._keras_history.layer,
AttributeError:'tuple' object has no attribute'layer'
and the input and output of your test data are correct .
Insert picture description here
Possible reason : the network layer added by the same model in the code From tensorflow.keras, and keras two places.
Suggestions: 1. If you use tensorflow 2.0 or higher, use tenorflow's own keras to model.
Among them, the corresponding module of keras corresponds to tf.keras in the location of tensorflow.keras . Find it They are all replaced with those that come with tenorflow.
Commonly used ones are:

from tensorflow.keras.layers import (
    Input, Dense, Conv2D, MaxPooling2D, AveragePooling2D, ZeroPadding2D,
    Flatten, Activation, GlobalAveragePooling2D, GlobalMaxPooling2D, add)
# from keras.layers.normalization import BatchNormalization
from tensorflow.keras.layers import BatchNormalization
from tensorflow.keras.models import Model
from tensorflow.keras import initializers
# from keras.engine import Layer, InputSpec
from tensorflow.keras.layers import Layer, InputSpec
# from keras.engine.topology import get_source_inputs
from tensorflow.keras.utils import get_source_inputs

2. If the problem is not solved, please check whether the replacement is complete. You can also refer to the forum StackOverflow :

Guess you like

Origin blog.csdn.net/beauthy/article/details/107564095