Comments (9)
Oi Tiago,
I'll have a look! Thanks for reporting!
from keract.
Hi Philippe!
In debugging I discovered that "_feed_targets" is assigned when compile/train the net. But with learning transfer this variable isn't setted.
from keract.
@tiagosamaha can you maybe compile your model before making inference? It's usually a good practice to do so.
from keract.
import numpy
from keras.applications import vgg16
from keras.preprocessing.image import load_img, img_to_array
from keract import get_activations, display_activations
img = load_img('/Users/philipperemy/PycharmProjects/keract/eight.png')
img_array = img_to_array(img)
img_array = numpy.expand_dims(img_array, axis=0)
# last vgg16 conv2d layer returns (None, None, None, 512)
feature_model = vgg16.VGG16(include_top=False, input_shape=(512, 512, 3))
feature_model.compile(loss='categorical_crossentropy', optimizer='adam') # <-- Add this line.
result = feature_model.predict(img_array)
activations = get_activations(feature_model, img_array)
display_activations(activations)
That code works.
from keract.
I could always compile the model in the library if not compiled but I guess it's safer to return an error saying model has to be compiled first. The loss somehow matters because it's used to compute the gradients (if you want to look at the activations only then it does not matter!). And Keract does not have any idea whatsoever of which loss was used to train the model. I guess here it's categorical cross entropy. Regarding the optimizer, it can be set to any random optimizer value (default is adam).
from keract.
Something like this could be added:
if feature_model.name == 'vgg16':
feature_model.compile(loss='categorical_crossentropy', optimizer='adam')
else:
raise Exception('Compile your model first.')
from keract.
Just for info I pushed a new code into master with what I discussed just above.
Feel free to try it.
pip install keract --upgrade
https://github.com/philipperemy/keract/pull/25/files
from keract.
Merged 83b2f57
from keract.
It is an alternative. Compile will do nothing, but create the variables.
Thanks for your attention!
from keract.
Related Issues (20)
- Plans to enable eager execution from TF 2.0? HOT 10
- Error when using model.add_loss HOT 5
- Regression CNN HOT 19
- Visualization on image sequence HOT 2
- Layer Import HOT 1
- Keras symbolic input/outputs and layer_names issue HOT 8
- Using an input other than the one provided by the pre-trained model fails. HOT 20
- get_activations: AttributeError when nested=True HOT 6
- Any plans for Pytorch implementation? HOT 2
- Heatmaps - ValueError: X has 20 features, but MinMaxScaler is expecting 1 features as input. HOT 17
- Can not convert a odict_values into a Tensor or Operation HOT 1
- custom loss not working any more
- Example in the README: 'Functional' object has no attribute '_layers' HOT 2
- display_heatmaps() ValueError: X has 28 features, but MinMaxScaler is expecting 1 features as input. HOT 2
- Interaction with submodels? HOT 5
- Trying to use keract.get_activations() for days, keep getting stuck HOT 3
- Implement with GradientTape
- Help with get_activations HOT 4
- display_heatmap error
- Scikit-learn requirement HOT 7
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 keract.