Home > other >  Neural Network with inputs of different sizes
Neural Network with inputs of different sizes

Time:07-16

I would like to use a neural network in Keras that takes 2 inputs of different sizes (a vector v and a matrix A) and outputs a vector u, which is v after acted upon by A. My questions are: How do I divide my inputs/outputs into training and test datasets? What types of network in Keras can take inputs of different types/sizes?

CodePudding user response:

The best option in your case zero padding or padding up would likely be the best decision in your situation. Inputs are only zeroed out in these situations to account for the absence of data. It is frequently used for CNN pictures' borders.

An RNN, which is a simpler option and can easily accommodate your variable-length inputs, is another option.

CodePudding user response:

Here is the example code. I think it can help you.

input_layer = Input(shape=(None, None, channels))
  x = Conv2D(16,(4,4), activation = 'relu')(input_layer) 
  x = Conv2D(32,(4,4), activation = 'relu')(x)        
  x = Dropout(0.2)(x)
  x = Conv2D(64,(4,4), activation = 'relu')(x)      
  x = Dropout(0.5)(x)
  x = Conv2D(128, (1,1))(x)                         
  x = GlobalAveragePooling2D()(x)                  
  output_layer = Dense(5, activation = "softmax")(x)
  model = Model(inputs = input_layer, outputs=output_layer)
  model.compile(optimizer = "adam", loss = "categorical_crossentropy",
                metrics=["accuracy"])
  • Related