Comments (11)
Hey, I think I can answer your questions.
- In order to visualize the feature maps, just use the get_weights method of each layer and plot it using matplotlib. I have a working implementation of the same, and hope I'll be able to generalize it soon and create a PR.
- For this, the best method that works for me is to create 2 models. Train the 1st model with your labels. The 2nd model is identical to the 1st except, it does not contain the last (or all fully connected) layer (don't forget to flatten). Using get_weights method above, get the weights of the 1st model and using set_weights assign it to the 2nd model. Then use predict_proba to get the feature vectors.
Hope it helps.
from keras.
As pointed out by pranv, all this is possible : )
To retrieve the output of any layer, you can also check out the answers here: #41
from keras.
Less headache for me was to just "deepcopy" the model and then just .pop() the last few layers and their parameters
from keras.
Thanks!
I try the method `save_weights`after training the model:
model.save_weights("./model.hdf5")
And then create a new model of same architecture, init with the saved weights, and use it to predict the test_data:
model_load = create_model()
model_load.load_weights('./model.hdf5')
test_label = model_load.predict_classes(test_data)
But it shows error:
test_label = model_load.predict_classes(test_data)
File "build/bdist.linux-x86_64/egg/keras/models.py", line 174, in predict_classes
File "build/bdist.linux-x86_64/egg/keras/models.py", line 160, in predict_proba
AttributeError: 'Sequential' object has no attribute '_predict'
from keras.
did you also recompile the model?
from keras.
I added a functionality to the model so it can predict output for a given layer index.
I changed the 'compile' method and added a function named predict_layer. If you are interested i can post the code here so you add it
from keras.
I would be interested I've been fucking around with it for 5 hours with no luck
from keras.
Check the code i posted here. It works well but I would change the design if i had time ...
#456
from keras.
hi @wepe ,I use the graph model.
like this,
model = graph()
model.add_input(name='input0',input_shape=())
model.add_node(Convolution2D(),name='c1',input='input0')
.......
And i want to see the output of the c1
,Then
getFeatureMap = theano.function(model.inputs['input0'].input,model.nodes['c1'].get_output(train=False),
allow_input_downcast=True)
But it show me that
TypeError: list indices must be integers, not str
Do you give me some advices? Thanks.
from keras.
hi @pranv ,I use the graph model.
like this,
model = graph()
model.add_input(name='input0',input_shape=())
model.add_node(Convolution2D(),name='c1',input='input0')
.......
And i want to see the output of the c1
,Then
getFeatureMap = theano.function(model.inputs['input0'].input,model.nodes['c1'].get_output(train=False),
allow_input_downcast=True)
But it show me that
TypeError: list indices must be integers, not str
Do you give me some advices? Thanks.
from keras.
More generally you can visualise the output/activations of every layer of your model. I wrote an example with MNIST to show how here:
https://github.com/philipperemy/keras-visualize-activations
So far it's the less painful I've seen.
from keras.
Related Issues (20)
- Keras deserialization Object Error - from keras.saving.legacy.serialization import deserialize_keras_object ImportError: cannot import name 'deserialize_keras_object' from HOT 4
- ML model is predicting the same output for different inputs HOT 4
- AttributeError: 'KerasHistory' object has no attribute 'layer' HOT 3
- Inconsistent handling of the loss from `add_loss` between jax and other backends HOT 3
- [Contribution Idea] Support OpenVINO as a backend in Keras 3 HOT 3
- Embedding(trainable=False) not working with Keras 3 HOT 1
- Conversion of symbolic tf.Tensor HOT 4
- keras with pytorch backend and mps set to default should use an mps generatir in randperm HOT 9
- Keras with TF backend GaussianDropout gives error with mixed_bfloat16 HOT 3
- Loading model Conv2DTranspose from h5 file results in error complaining about group:1 parameter HOT 11
- [Bug] Custom evaluation don't work in torch (but work in tensorflow). HOT 4
- [bug] keras issue on tpu-vm HOT 3
- How to import existing trained pytorch model to keras 3 HOT 2
- Any plan to add type annotations? HOT 2
- Add AdamWScheduleFree HOT 2
- Support `rar` archive file format extraction in keras.utils.get_file HOT 2
- AttributeError: 'types.SimpleNamespace' object has no attribute 'get_registered_object' from return keras.saving.get_registered_object(config["registered_name"]) in keras_nlp\src\utils\preset_utils.py HOT 4
- A checker is needed in Conv layers HOT 3
- Keras 3 / TF SavedModel export issues HOT 3
- tf.keras.utils.plot_model no longer supports layers with list as output HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keras.