TypeError: unsupported operand type(s) for *: 'Dimension' and 'float' in DenseNet using keras

229 views Asked by At

I want to apply DenseNet model using keras on my data but I get this error. I don't know how to solve it.

in transition         
x = tf.keras.layers.Conv2D( np.floor( compression_factor * num_feature_maps ).astype( np.int ) ,
    kernel_size=(1, 1), use_bias=False, padding='same' , kernel_initializer='he_normal' , kernel_regularizer=tf.keras.regularizers.l2( 1e-4 ) )(x)
 TypeError: unsupported operand type(s) for *: 'Dimension' and 'float'

Any help would be appreciated.

code:

def transition(inputs, num_filters , compression_factor , dropout_rate ):
    # compression_factor is the 'θ'
    eps = 1.1e-5
    x = tf.keras.layers.BatchNormalization( epsilon=eps )(inputs)
    x = tf.keras.layers.Activation('relu')(x)
    num_feature_maps = inputs.shape[1] # The value of 'm'

    x = tf.keras.layers.Conv2D( np.floor( compression_factor * num_feature_maps ).astype( np.int ) ,
                               kernel_size=(1, 1), use_bias=False, padding='same' , kernel_initializer='he_normal' , kernel_regularizer=tf.keras.regularizers.l2( 1e-4 ) )(x)
    x = tf.keras.layers.Dropout(rate=dropout_rate)(x)
   
    x = tf.keras.layers.AveragePooling2D(pool_size=(2, 2))(x)
    return x
0

There are 0 answers