Skip to content

Instantly share code, notes, and snippets.

Hannes Hapke hanneshapke

Block or report user

Report or block hanneshapke

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@hanneshapke
hanneshapke / norm_heatmap.py
Last active Apr 16, 2018
Normalize the visualization heat map
View norm_heatmap.py
def norm_heatmap(heatmap):
# element-wise maximum calculation, basically setting all negative values to zero
heatmap = np.maximum(heatmap, 0)
# normalizing the heatmap to values between 0 and 1
norm_heatmap = heatmap / np.max(heatmap)
return norm_heatmap
@hanneshapke
hanneshapke / generate_layer_heat_map.py
Last active Nov 18, 2019
How to generate the layer heat map in Keras 2.1
View generate_layer_heat_map.py
def get_heatmap(model, layer_name, matrix, y_labels):
# obtain probability of the label with the highest certainty
network_output = model.get_output_at(0)[:, np.argmax(y_labels)]
# obtain the output vector and its dimension of the convolutional layer we want to visualize
conv_layer, layer_output_dim = get_conv_layer(model, layer_name)
# Setting up the calculation of the gradients between the output and the conv layer. Will be executed in the iteration step
grads = K.gradients(network_output, conv_layer.output)[0]
# average the gradients across our samples (one sample) and all filters
@hanneshapke
hanneshapke / extract_layer.py
Last active Apr 16, 2018
Extract Keras layers by layer name
View extract_layer.py
def get_conv_layer(model, layer_name):
conv_layer = model.get_layer(layer_name)
output_dim = conv_layer.output_shape[1]
return conv_layer, output_dim
View visualize_conv_nets_for_nlp.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hanneshapke
hanneshapke / model.py
Last active Apr 16, 2018
Model definition for the CNN Visualization Demo
View model.py
sequence_input = Input(shape=(maxlen_text,))
x = Embedding(name='embedding_layer',
input_dim=max_words_to_keep,
output_dim=token_vec_size,
input_length=maxlen_text)(sequence_input)
x = Dropout(.20)(x)
x = Conv1D(64, 5, activation='relu', name='1-conv1d', padding='same')(x)
x = MaxPooling1D(pool_size=4)(x)
View keras_bidirectional_tagger.py
# Keras==1.0.6
from keras.models import Sequential
import numpy as np
from keras.layers.recurrent import LSTM
from keras.layers.core import TimeDistributedDense, Activation
from keras.preprocessing.sequence import pad_sequences
from keras.layers.embeddings import Embedding
from sklearn.cross_validation import train_test_split
from keras.layers import Merge
from keras.backend import tf
View keras_bidirectional_tagger.py
# Keras==1.0.6
from keras.models import Sequential
import numpy as np
from keras.layers.recurrent import LSTM
from keras.layers.core import TimeDistributedDense, Activation
from keras.preprocessing.sequence import pad_sequences
from keras.layers.embeddings import Embedding
from sklearn.cross_validation import train_test_split
from keras.layers import Merge
from keras.backend import tf
@hanneshapke
hanneshapke / celery.sh
Last active Aug 23, 2017 — forked from amatellanes/celery.sh
Celery handy commands
View celery.sh
/* Useful celery config.
app = Celery('tasks',
broker='redis://localhost:6379',
backend='redis://localhost:6379')
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
CELERY_QUEUES=(
Queue('default', routing_key='tasks.#'),
@hanneshapke
hanneshapke / track_celery.py
Created Jul 22, 2016
Decorator for Celery functions to measure the execution time and memory usage
View track_celery.py
import time
from memory_profiler import memory_usage
import logging
celery_logger = logging.getLogger('celery')
def track_celery(method):
"""
@hanneshapke
hanneshapke / Editable Fields with ReactJS and ES2015
Last active Jun 21, 2019
Simple editable field with ReactJS and ES2015
View Editable Fields with ReactJS and ES2015
### Try it out with JSBin
(JSBin)[http://jsbin.com/dijefajalo/edit?html,js,console,output]
You can’t perform that action at this time.