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)
- import keras error (V3.3.2) (kaggle Notebook) HOT 1
- Keras 3 with Pytorch backend ERROR - Layer 'lstm_cell' expected 3 variables, but received 0 variables during loading. Expected: ['kernel', 'recurrent_kernel', 'bias'] HOT 4
- The source code URL in the documentation leads to a non-existent page. HOT 1
- keras.ops.linalg.cholesky can't JIT HOT 1
- Model fails to train with Linux and Keras 3.3.2 HOT 9
- Compatible with .ogg format HOT 2
- keras autocast casts numpy int types to float HOT 2
- bug in TF _keepdims? HOT 3
- keras.ops.cross doesn't propagate input sizes HOT 1
- GSOC '24 Project? HOT 1
- Dice loss - incorrect HOT 1
- The loss becomes neagative from positive values dring taining loop HOT 3
- Unusual behavior of `predict` for JAX backend HOT 17
- Layernorm not supporting axis [-2, 3] HOT 2
- LSTM layer with dropout does not use fast CuDNN implementation in Keras 3 HOT 1
- RaggedTensor HOT 4
- [Proposal] API tuning for use_cudnn in LSTM/other layers HOT 5
- The torch backend for jnp.cholesky should use torch.linalg.cholesky, not torch.cholesky HOT 1
- Numeric diff of BatchNormalization layer when migrate from Keras2 to keras3 HOT 5
- How to save Scikit-Learn-Keras Model into a Persistence File (pickle/hd5/json/yaml) with Keras 3 HOT 12
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.