Keras 1.2 Functional API 'GraphModel' object has no attribute 'get_layers'
See original GitHub issueI’m using the Keras 1.2 w/ TF (dev-tf branch) functional API & updated to use kc.convert_functional_model
.
Here’s the error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-10-262bf3b052dd> in <module>()
4
5 deeplift_model = revealcancel_model
----> 6 deeplift_prediction_func = compile_func([deeplift_model.get_layers()[0].get_activation_vars()],
7 deeplift_model.get_layers()[-1].get_activation_vars())
8 original_model_predictions = keras_model.predict(X_test.values, batch_size=200)
AttributeError: 'GraphModel' object has no attribute 'get_layers'
Here’s the code snippet I’m running…
...
revealcancel_model = kc.convert_functional_model(model=keras_model, nonlinear_mxts_mode=NonlinearMxtsMode.RevealCancel)
from deeplift.util import compile_func
import numpy as np
from keras import backend as K
deeplift_model = revealcancel_model
deeplift_prediction_func = compile_func([deeplift_model.get_layers()[0].get_activation_vars()],
deeplift_model.get_layers()[-1].get_activation_vars())
original_model_predictions = keras_model.predict(X_test.values, batch_size=200)
converted_model_predictions = deeplift.util.run_function_in_batches(
input_data_list=[X_test.values],
func=deeplift_prediction_func,
batch_size=200,
progress_update=None)
print("difference in predictions:",np.max(np.array(converted_model_predictions)-np.array(original_model_predictions)))
assert np.max(np.array(converted_model_predictions)-np.array(original_model_predictions)) < 10**-5
predictions = converted_model_predictions
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
Keras AttributeError: 'Functional' object has no attribute 'shape'
The reason why you get that error is that you need to provide the input_shape of the base_model , instead of the base_model...
Read more >Model (functional API) - Keras 1.2.2 Documentation
Scalar test loss (if the model has a single output and no metrics) or list of scalars (if the model has multiple outputs...
Read more >The Model class - Keras
Model groups layers into an object with training and inference features. ... 1 - With the "Functional API", where you start from Input...
Read more >errors in merging two layers output - Google Groups
to Keras-users. Hi, dear all, I have problem about merging two layers output, ... AttributeError: 'TensorVariable' object has no attribute ...
Read more >3 ways to create a Keras model with TensorFlow 2.0 ...
Keras and TensorFlow 2.0 provide you with three methods to implement your own neural network architectures:, Sequential API, Functional API, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@AvantiShri It works now.
In summary in case anyone would like to use the Keras Functional API…
deeplift_model.get_name_to_blob().keys()
compile_func
to use layer name, example…get_target_contribs_func
to use layer names as well, note you’ll need the pre-activation layer here…UPDATE: deeplift_model.get_name_to_layer().keys()