Make any keras network convolutional

142 Views Asked by At

The circumstances remaining an abstraction, I need to train a convolutional network and then run this convolutional network over a sliding window on an image. The goal will be to build a heatmap for making pixel perfect detection boundaries for certain objects.

I'm wondering if there is an easy way in keras to train a network and then turn it into a convolutional network without needing to run loops over an image, which is very slow?

I'm thinking I can just copy the trained convolutional filters into a larger convolutional network.

If not, I'll need to go directly to tensorflow.

1

There are 1 best solutions below

0
On

This is easily done in Keras, as long as you use a fully convolutional net, i.e. replace any dense layers by a convolutional layer with kernel size 1.

The easiest way to get started is to use one of the pre-trained nets included in Keras, see https://keras.io/applications/ how this is done for custom input size. If you've trained your own fully convolutional net 'old_model', just do:

    new_input = Input(new_size)

    new_model = Model(new_input, old_model.output)

    old_model.save_weights('w.h5')

    new_model.get_weights('w.h5')