-
Notifications
You must be signed in to change notification settings - Fork 19.4k
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
Comments
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. |
Hello, |
ping |
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) |
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())
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!
The text was updated successfully, but these errors were encountered: