Layer.get_weights() returns wrong output with shape(1, 1, 1, 2080, 1536)

133 views Asked by At

I have only added the output layers of the default keras imported inceptionresnetv2 and am trying to visualize the filters present in it ,to do this i am trying to extract the weights and biases using the code below but am getting an array with the shape(1, 1, 1, 2080, 1536) instead of being able to extract the weights and biases into two separate variables, the code returns the error

not enough values to unpack (expected 2, got 1)

please let me know how i can extract the weights and biases for a specific layer

Code:

layer_name='conv_7b'
layer_dict = dict([(layer.name, layer) for layer in model.layers[0].layers])
filters, biases = np.array(layer_dict[layer_name].get_weights())

Model:


resnet = InceptionResNetV2(
    input_shape=(img_width,img_height,3),
    include_top=False,
    weights="imagenet"
)

model = tf.keras.models.Sequential([
    resnet,
    
    Flatten(),LeakyReLU(alpha=0.05),
    Dense(512,activation="relu"),
    BatchNormalization(),
    Dropout(0.5),
    
    Dense(64,activation="relu"),
    BatchNormalization(),
    Dropout(0.5),
    Dense(7, activation='softmax')
])
0

There are 0 answers