titu1994 / keras-efficientnets

Keras Implementation of EfficientNets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

error while using model layers

shubhaminnani opened this issue · comments

i am getting an error while using layer for further operation

base_model =EfficientNetB4((img_height, img_width, 3), weights='imagenet', include_top=False)
base_model.summary()
x = base_model.get_layer('multiply_16').output
x_a = ASPP(x)
x_a = ASPP(x)
Traceback (most recent call last):

File "", line 1, in
x_a = ASPP(x)

File "", line 18, in ASPP
y_pool = AveragePooling2D(pool_size=(dims[1], dims[2]), name='average_pooling')(tensor)

File "C:\Users\Student\Anaconda2\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 696, in call
inputs, outputs, args, kwargs)

File "C:\Users\Student\Anaconda2\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 1795, in set_connectivity_metadata
input_tensors=inputs, output_tensors=outputs, arguments=kwargs)

File "C:\Users\Student\Anaconda2\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 1882, in _add_inbound_node
input_tensors)

File "C:\Users\Student\Anaconda2\lib\site-packages\tensorflow\python\util\nest.py", line 515, in map_structure
structure[0], [func(*x) for x in entries],

File "C:\Users\Student\Anaconda2\lib\site-packages\tensorflow\python\util\nest.py", line 515, in
structure[0], [func(*x) for x in entries],

File "C:\Users\Student\Anaconda2\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 1881, in
inbound_layers = nest.map_structure(lambda t: t._keras_history.layer,

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

I don't understand what is ASPP(x). Is it some custom layer? Or a class ? If you want pooling just pass pooling='avg'

Its atrous spatial pyramid pooling ASPP is a class performing various operation on that layer

def ASPP(tensor): '''atrous spatial pyramid pooling''' dims = K.int_shape(tensor)

y_pool = AveragePooling2D(pool_size=(dims[1], dims[2]), name='average_pooling')(tensor) y_pool = Conv2D(filters=256, kernel_size=1, padding='same',kernel_initializer='he_normal', name='pool_1x1conv2d', use_bias=False)(y_pool) y_pool = BatchNormalization(name=f'bn_1')(y_pool) y_pool = Activation('relu', name=f'relu_1')(y_pool)

`y_pool = Upsample(tensor=y_pool, size=[dims[1], dims[2]])`

` y_1 = Conv2D(filters=256, kernel_size=1, dilation_rate=1, padding='same',kernel_initializer='he_normal', name='ASPP_conv2d_d1', use_bias=False)(tensor)
y_1 = BatchNormalization(name=f'bn_2')(y_1)
y_1 = Activation('relu', name=f'relu_2')(y_1)

y_6 = Conv2D(filters=256, kernel_size=3, dilation_rate=6, padding='same',kernel_initializer='he_normal', name='ASPP_conv2d_d6', use_bias=False)(tensor)
y_6 = BatchNormalization(name=f'bn_3')(y_6)
y_6 = Activation('relu', name=f'relu_3')(y_6)

y_12 = Conv2D(filters=256, kernel_size=3, dilation_rate=12, padding='same',kernel_initializer='he_normal', name='ASPP_conv2d_d12', use_bias=False)(tensor)
y_12 = BatchNormalization(name=f'bn_4')(y_12)
y_12 = Activation('relu', name=f'relu_4')(y_12)

y_18 = Conv2D(filters=256, kernel_size=3, dilation_rate=18, padding='same',kernel_initializer='he_normal', name='ASPP_conv2d_d18', use_bias=False)(tensor)
y_18 = BatchNormalization(name=f'bn_5')(y_18)
y_18 = Activation('relu', name=f'relu_5')(y_18)

y = concatenate([y_pool, y_1, y_6, y_12, y_18], name='ASPP_concat')

y = Conv2D(filters=256, kernel_size=1, dilation_rate=1, padding='same',kernel_initializer='he_normal', name='ASPP_conv2d_final', use_bias=False)(y)
y = BatchNormalization(name=f'bn_final')(y)
y = Activation('relu', name=f'relu_final')(y)
return y`

Here is this class code

Have you tried using your code with other Keras models? I don't see what the error has to do with the model. Tuple object has no attribute Layer? The tuple definition is from your K.int_shape(). So I don't know why it is causing this issue.

Yes I have tried with other keras model and its working fine

I can't seem to find a reason for this crash.