Skip to content

Instantly share code, notes, and snippets.

View wassname's full-sized avatar
🙃

wassname (Michael J Clark) wassname

🙃
View GitHub Profile
@wassname
wassname / pick_image features.ipynb
Created August 12, 2016 00:07
example of interactive labeling images in jupyter/ipython notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wassname
wassname / visualising keras.ipynb
Created September 9, 2016 03:03
Visualising keras weights and output using matplotlib
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wassname
wassname / dice_loss_for_keras.py
Created September 26, 2016 08:32
dice_loss_for_keras
"""
Here is a dice loss for keras which is smoothed to approximate a linear (L1) loss.
It ranges from 1 to 0 (no error), and returns results similar to binary crossentropy
"""
# define custom loss and metric functions
from keras import backend as K
def dice_coef(y_true, y_pred, smooth=1):
@wassname
wassname / keras_weighted_categorical_crossentropy.py
Last active October 10, 2024 00:52
Keras weighted categorical_crossentropy (please read comments for updated version)
"""
A weighted version of categorical_crossentropy for keras (2.0.6). This lets you apply a weight to unbalanced classes.
@url: https://gist.github.com/wassname/ce364fddfc8a025bfab4348cf5de852d
@author: wassname
"""
from keras import backend as K
def weighted_categorical_crossentropy(weights):
"""
A weighted version of keras.objectives.categorical_crossentropy
@wassname
wassname / dataset_cmudict.py
Last active November 4, 2016 01:57
Loader for cmudict dataset (CMU Pronouncing Dictionary) for keras
"""
Load cmudict/CMU Pronouncing Dictionary as a dataset for keras
author: wassname
url : https://gist.github.com/wassname/ce0ac72c50832b0a27e67bd97ba36080
"""
from keras.utils.data_utils import get_file
from sklearn.model_selection import train_test_split
import numpy as np
@wassname
wassname / keras_attention_wrapper.py
Created November 1, 2016 08:06
A keras attention layer that wraps RNN layers.
"""
A keras attention layer that wraps RNN layers.
Based on tensorflows [attention_decoder](https://github.com/tensorflow/tensorflow/blob/c8a45a8e236776bed1d14fd71f3b6755bd63cc58/tensorflow/python/ops/seq2seq.py#L506)
and [Grammar as a Foreign Language](https://arxiv.org/abs/1412.7449).
date: 20161101
author: wassname
url: https://gist.github.com/wassname/5292f95000e409e239b9dc973295327a
"""
@wassname
wassname / to_filename.py
Last active March 14, 2025 09:54
python convert string to safe filename
"""
Url: https://gist.github.com/wassname/1393c4a57cfcbf03641dbc31886123b8
"""
import unicodedata
import string
valid_filename_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
char_limit = 255
def clean_filename(filename, whitelist=valid_filename_chars, replace=' '):
@wassname
wassname / classification_report_parse.py
Last active March 10, 2017 04:25
Digitize scikit-learn's classification_report
from io import StringIO
import pandas as pd
import numpy as np
import sklearn
def parse_classification_report(classification_report):
"""Parses sklearn classification report into a pandas dataframe."""
return pd.read_fwf(StringIO(classification_report),lineterminator='\n', index_col=0, colspecs=[(0,12),(12,22),(22,32),(32,42),(42,52)]).dropna()
target_names['leak','no leak']
@wassname
wassname / find_best_dummy_classification.py
Last active August 27, 2017 05:56
Try all dummy models in sklearn
# from https://gist.github.com/wassname/00b94dc7eb7220c136685fce782be3a4
from io import StringIO
import pandas as pd
import numpy as np
from sklearn import metrics
import sklearn
def parse_classification_report(classification_report):
"""Parse a sklearn classification report to a dict."""
return pd.read_fwf(