Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load a model and modify intermediate layers #4450

Closed
jsalbert opened this issue Nov 21, 2016 · 4 comments
Closed

Load a model and modify intermediate layers #4450

jsalbert opened this issue Nov 21, 2016 · 4 comments

Comments

@jsalbert
Copy link

Hi, I am loading a VGG-16 CAM model from json (I attach the json vgg_cam_mod_model.json.zip) with its corresponding weights and I want to edit intermediate layers of the model in order to deal with different image sizes.

I have seen that there is the .pop() function to remove the last layer, but in my case I want to edit the pool size and strides of the 'CAM_pool' layer which is an AveragePooling2D layer, or if it is also necessary the inputlayer, is it possible to do it?

Case of a fixed image

x = np.zeros((1, 3, 720, 1024))

model = model_from_json(open('models/vgg_cam_mod_model.json').read())

screen shot 2016-11-21 at 12 06 59

screen shot 2016-11-21 at 12 06 20

Then I have tried:

pool_layer = model.layers[-5] pool_layer.pool_size = [45, 64] pool_layer.strides = [45, 64]

model.summary()
Not doing anything.

model.layers[-5] = AveragePooling2D(name="CAM_pool", trainable=True, dim_ordering="th", pool_size=[45, 64], strides=[45, 64], border_mode="valid")(model.layers[-6])

Error: 'Activation' object has no attribute 'ndim'

I also tried to define the layer as a GlobalAveragePooling2D in the json:
{"class_name": "GlobalAveragePooling2D", "config": {"name": "CAM_pool", "trainable": true, "dim_ordering": "th"}
Error Input 0 is incompatible with layer CAM_fc_flatten: expected ndim >= 3, found ndim=2

Do I have to change also the shape of Input Data Layer?

model.layers[0] = Input(shape=(None, 3, 720, 1024))
Error: 'TensorVariable' object has no attribute 'inbound_nodes'

Thanks for the help!

@stale stale bot added the stale label May 23, 2017
@stale
Copy link

stale bot commented May 23, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.

@stale stale bot closed this as completed Jun 23, 2017
@AJwgnr
Copy link

AJwgnr commented Feb 22, 2018

Hello,
is there any update on this?

@RamiAwar
Copy link

RamiAwar commented Jun 5, 2018

ping

@adrcaraf
Copy link

adrcaraf commented Jul 31, 2018

I have done the following for changing Input layer shape of a CNN3D of mine. It seems to be working, but I'm not sure if it allows for the alteration of other params of the configuration successfully.

json_file = open(rnn_name, 'r')
loaded_json_model = json_file.read()
json_file.close()
model = model_from_json(loaded_json_model)
tmp = model.get_config()
tmp['layers'][0]['config']['batch_input_shape'] = (None, depth, height, width, 1)
model = Model.from_config(tmp)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants