0

I have a VGG16 style model (i.e. CNN with fully connected layers) saved as json file and weights as h5 file.

I want to load this model and convert it to an FCN (Fully Convolutional Model) which can accept variable size RGB images as inputs.

From my understanding there are 4 main steps: 1) Change the input layer to accept variable size inputs RGB inputs. 2) Remove the fully connected layers from VGG16 style model with fully connected layers. 3) Add appropriate convolution layers equivalent to fully connected layers. 4) Reshape & set weights for the new convolution layers.

I believe I know how to do steps 2-4. However, I'm having problems doing those with step 1.

I've read posts like Keras replacing input layer, but haven't found a solution which works for me.

Here is what I'd like to do:

#load model & weights
with open(model_json_file, 'r') as json_file:
    model_json = json_file.read()

vgg16_model = model_from_json(model_json)
vgg16_model.load_weights(model_h5_file)

#remove input layer
vgg16_model.layers.pop(0)

x = vgg16_model.get_layer('block5_pool').output
x = Conv2D(4096, (7,7), strides=1, padding='same', data_format='channels_last', activation='relu', use_bias=True)(x)
x = Conv2D(1000, (7,7), strides=1, padding='same', data_format='channels_last', activation='relu', use_bias=True)(x)
x = Conv2D(2, (7,7), strides=1, padding='same', data_format='channels_last', activation='relu', use_bias=True)(x)

new_input = Input(shape=(None,None,3), batch_shape=None, name='fcn_input')
vgg16_model.layers[0](new_input)
fcn_model_fixed_input = Model(inputs=vgg16_model.input, outputs=x)

However then:

fcn_model_fixed_input.summary()

gives:

wind_turbine_fcn_model_fixed_input.summary()

user3731622
  • 4,844
  • 8
  • 45
  • 84
  • can you elaborate on the problem space? would normalizing the input data be acceptable? – olympia Mar 15 '19 at 20:58
  • I'm not sure why normalizing the input data would come be useful? I tried to be detailed on my description (hence the long description). – user3731622 Mar 15 '19 at 21:10

0 Answers0