0
$\begingroup$

I would like to use AutoEncoder or VAE in order to learn set of features which I can use to initialize training procedure of a custom CNN architecture that I've build. Here is the code:

class DeepCNN:
  @staticmethod
  def conv_block(input, filters, pool, reg):
    output = tf.keras.layers.SeparableConv2D(filters, 3, activation="relu",
                                             padding="same", kernel_regularizer=l2(reg))(input)
    output = tf.keras.layers.BatchNormalization()(output)
    if pool == True:
      output = tf.keras.layers.MaxPool2D((2,2))(output)
    
    return output

  @staticmethod
  def dense_block(input, units, dropout_rate, reg):
    output = tf.keras.layers.Dense(units, activation="relu", kernel_regularizer=l2(reg))(input)
    output = tf.keras.layers.BatchNormalization()(output)
    output = tf.keras.layers.Dropout(dropout_rate)(output)

    return output

  @staticmethod
  def build(width, height, depth, classes, filter_bank = None, dense_units = None, reg=0.0002, include_top=True):
     assert filter_bank is not None, "Filter bank should not be empty ..."
     assert dense_units is not None, "Top of the network architecture must contain atleast 1 Dense layer"

     inputShape = (height, width, depth)
     chanDim = -1
     
     if K.image_data_format() == "channels_first":
            inputShape = (depth, height, width)
            chanDim = 1
            
     inputs = Input(shape=inputShape)

     output = DeepCNN.conv_block(inputs, filter_bank[0][0], filter_bank[0][1], reg=reg)
     for idx in range(1, len(filter_bank)):
       output = DeepCNN.conv_block(output, filter_bank[idx][0], filter_bank[idx][1], reg=reg)
    
     output = tf.keras.layers.Dropout(0.2)(output)

     if include_top == True:
          output = tf.keras.layers.Flatten()(output)
          for idx in range(0, len(dense_units)):
              output = DeepCNN.dense_block(output, dense_units[idx][0], dense_units[idx][1], reg=reg)
          output = tf.keras.layers.Dense(classes, activation="softmax", name="classification")(output)
    
     model = Model(inputs, output, name="deep_cnn")
     return model

model = DeepCNN.build(150, 150, 1, 2,
                      filter_bank=[(32, True), (64, True), (128, True), (256, True)],
                      dense_units=[(512, 0.4)], reg=0.0005)

I am confused how I should configure AutoEncoder or VAE in order to generate such weights that are compatible for custom CNN architectures. Any help would be appreciated. Thanks in advance!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.