Comments (4)
Can you post a gist or sample to reproduce the issue?
from keras-vis.
When I want to run keras-vis, got this error.
python packages:
keras=='2.0.0'
theano=='0.9.0'
from keras-vis.
What did you run? Your own code or some example?
from keras-vis.
run examples are exist in your Github:
import numpy as np
from matplotlib import pyplot as plt
from vis.utils import utils
from vis.utils.vggnet import VGG16
from vis.visualization import visualize_activation
import keras
def visualize_random(num_categories=10, show=True):
"""Example to show how to visualize multiple filters via activation maximization.
Args:
num_categories: The number of random categories to visualize. (Default Value = 5)
"""
# Build the VGG16 network with ImageNet weights
model = VGG16(weights='imagenet', include_top=True)
print('Model loaded.')
# The name of the layer we want to visualize
# (see model definition in vggnet.py)
layer_name = 'predictions'
layer_idx = [idx for idx, layer in enumerate(model.layers) if layer.name == layer_name][0]
# Visualize couple random categories from imagenet.
indices = np.random.permutation(1000)[:num_categories]
images = []
for idx in indices:
img = visualize_activation(model, layer_idx, filter_indices=idx, max_iter=500)
img = utils.draw_text(img, utils.get_imagenet_label(idx))
images.append(img)
# Easily stitch images via `utils.stitch_images`
stitched = utils.stitch_images(images)
if show:
plt.axis('off')
plt.imshow(stitched)
plt.title('Random imagenet categories')
plt.show()
def visualize_multiple_same_filter(num_runs=3, show=True):
"""Example to show how to visualize same filter multiple times via different runs.
Args:
num_runs: The number of times the same filter is visualized
"""
# Build the VGG16 network with ImageNet weights
model = VGG16(weights='imagenet', include_top=True)
print('Model loaded.')
# The name of the layer we want to visualize
# (see model definition in vggnet.py)
layer_name = 'predictions'
layer_idx = [idx for idx, layer in enumerate(model.layers) if layer.name == layer_name][0]
# 20 is the imagenet category for 'ouzel'
indices = [20] * num_runs
images = []
for idx in indices:
img = visualize_activation(model, layer_idx, filter_indices=idx, max_iter=500)
img = utils.draw_text(img, utils.get_imagenet_label(idx))
images.append(img)
# Easily stitch images via `utils.stitch_images`
stitched = utils.stitch_images(images)
if show:
plt.axis('off')
plt.imshow(stitched)
plt.title('Multiple runs of ouzel')
plt.show()
def visualize_multiple_categories(show=True):
"""Example to show how to visualize images that activate multiple categories
"""
# Build the VGG16 network with ImageNet weights
model = VGG16(weights='imagenet', include_top=True)
print('Model loaded.')
# The name of the layer we want to visualize
# (see model definition in vggnet.py)
layer_name = 'predictions'
layer_idx = [idx for idx, layer in enumerate(model.layers) if layer.name == layer_name][0]
# Visualize [20] (ouzel) and [20, 71] (An ouzel-scorpion :D)
indices = [20, [20, 71]]
images = []
for idx in indices:
img = visualize_activation(model, layer_idx, filter_indices=idx, max_iter=500)
img = utils.draw_text(img, utils.get_imagenet_label(idx))
images.append(img)
# Easily stitch images via `utils.stitch_images`
stitched = utils.stitch_images(images)
if show:
plt.axis('off')
plt.imshow(stitched)
plt.title('Multiple category visualization')
plt.show()
if name == 'main':
print (keras.version)
print('Visualizing random imagenet output categories')
visualize_random(3)
print('Visualizing same filter over multiple runs')
visualize_multiple_same_filter()
print('Visualizing multiple categories')
visualize_multiple_categories()
from keras-vis.
Related Issues (20)
- [question] electrode contribution in EEG input
- Is there any reason why no demo for activation maximization for resnet?
- Is the project still maintained? HOT 2
- Exact gradient values
- Memory increases and iterations slow down while using visualize_saliency
- 3D MRI Image
- How to clip the positive gradients when using visualization_cam?
- AttributeError: module 'tensorflow' has no attribute 'get_default_graph' HOT 1
- AttributeError: 'list'/integer/float object has no attribute 'build_loss' in visualize_saliency_with_losses
- ImportError: cannot import name '_Conv' from 'keras.layers.convolutional' HOT 19
- Generated Image Color
- Issue - "ImportError: cannot import name '_Conv' from 'keras.layers.convolutional'" HOT 2
- Tensorflow version? HOT 1
- Problem with custom CNN VGG16 (unsupported operand type(s) for *: 'int' and 'NoneType')
- scipy 1.5.2 ImportError: cannot import name 'imresize' HOT 3
- Cannot convert a symbolic Keras input/output to a numpy array... HOT 1
- v
- Is this also working for Faster R-CNN or Mask R-CNN?
- Why is pre-activation output used for computing vanilla saliency map?
- AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'
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-vis.