Code Monkey home page Code Monkey logo

Comments (11)

pranv avatar pranv commented on May 2, 2024 2

Hey, I think I can answer your questions.

  1. 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.
  2. 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.

fchollet avatar fchollet commented on May 2, 2024

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.

lemuriandezapada avatar lemuriandezapada commented on May 2, 2024

Less headache for me was to just "deepcopy" the model and then just .pop() the last few layers and their parameters

from keras.

wepe avatar wepe commented on May 2, 2024

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.

lemuriandezapada avatar lemuriandezapada commented on May 2, 2024

did you also recompile the model?

from keras.

loyeamen avatar loyeamen commented on May 2, 2024

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.

lemuriandezapada avatar lemuriandezapada commented on May 2, 2024

I would be interested I've been fucking around with it for 5 hours with no luck

from keras.

loyeamen avatar loyeamen commented on May 2, 2024

Check the code i posted here. It works well but I would change the design if i had time ...
#456

from keras.

alyato avatar alyato commented on May 2, 2024

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.

alyato avatar alyato commented on May 2, 2024

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.

philipperemy avatar philipperemy commented on May 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.