This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import SimpleHTTPServer | |
from SimpleHTTPServer import SimpleHTTPRequestHandler | |
class RangeHTTPRequestHandler(SimpleHTTPRequestHandler): | |
"""RangeHTTPRequestHandler is a SimpleHTTPRequestHandler | |
with HTTP 'Range' support""" | |
def send_head(self): | |
"""Common code for GET and HEAD commands. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# summarize model | |
from collections import OrderedDict | |
import pandas as pd | |
import torch | |
from torch import nn | |
from torch.autograd import Variable | |
class TorchSummarizeDf(object): | |
def __init__(self, model, weights=False, input_shape=True, nb_trainable=False, debug=False): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Another way, note this one will load the whole array into memory .""" | |
from keras.preprocessing.image import ImageDataGenerator | |
import h5py | |
from keras.utils.io_utils import HDF5Matrix | |
seed=0 | |
batch_size=32 | |
# we create two instances with the same arguments | |
data_gen_args = dict( | |
rotation_range=90., |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras import backend as K | |
def jaccard_distance_loss(y_true, y_pred, smooth=100): | |
""" | |
Jaccard = (|X & Y|)/ (|X|+ |Y| - |X & Y|) | |
= sum(|A*B|)/(sum(|A|)+sum(|B|)-sum(|A*B|)) | |
The jaccard distance loss is usefull for unbalanced datasets. This has been | |
shifted so it converges on 0 and is smoothed to avoid exploding or disapearing | |
gradient. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# sudo apt-get install id3v2 ffmpeg | |
# | |
# USAGE: | |
# cd /book title/ | |
# bash ~/this_script_path.sh | |
# rm *.m4b (you need to manually remove the original in case something goes wrong) | |
# | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib | |
import matplotlib.pyplot as plt | |
def colorize(words, color_array): | |
# words is a list of words | |
# color_array is an array of numbers between 0 and 1 of length equal to words | |
cmap = matplotlib.cm.get_cmap('RdBu') | |
template = '<span class="barcode"; style="color: black; background-color: {}">{}</span>' | |
colored_string = '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/system/xbin/bash | |
#Based on https://github.com/termux/termux-app/issues/77 | |
export PREFIX='/data/data/com.termux/files/usr' | |
export HOME='/data/data/com.termux/files/home' | |
export LD_LIBRARY_PATH='/data/data/com.termux/files/usr/lib' | |
export PATH="/data/data/com.termux/files/usr/bin:/data/data/com.termux/files/usr/bin/applets:$PATH" | |
export LANG='en_US.UTF-8' | |
export SHELL='/data/data/com.termux/files/usr/bin/bash' | |
export BIN='/data/data/com.termux/files/usr/bin' | |
export TERM=vt220 |
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 4.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Book Id,Title,Author,Author l-f,Additional Authors,ISBN,ISBN13,My Rating,Average Rating,Publisher,Binding,Number of Pages,Year Published,Original Publication Year,Date Read,Date Added,Bookshelves,Bookshelves with positions,Exclusive Shelf,My Review,Spoiler,Private Notes,Read Count,Recommended For,Recommended By,Owned Copies,Original Purchase Date,Original Purchase Location,Condition,Condition Description,BCID | |
13278990,The Housing Monster,prole.info,"prole.info, prole.info",,"=""160486530X""","=""9781604865301""",0,3.77,PM Press,Paperback,160,2012,2011,,2017/12/07,currently-reading,currently-reading (#3),currently-reading,,,,1,,,0,,,,, | |
7805,Pale Fire,Vladimir Nabokov,"Nabokov, Vladimir",,"=""0141185260""","=""9780141185262""",0,4.19,Penguin Books Ltd,Paperback,246,2000,1962,,2013/10/09,to-read,to-read (#26),to-read,,,,0,,,0,,,,, | |
34220725,Never Use Futura,Doug Thomas,"Thomas, Doug",Ellen Lupton,"=""1616895721""","=""9781616895723""",4,4.29,Princeton Architectural Press,Paperback,208,2017,,,2017/11/12,,,read,"Pr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A noisy convolution 2d for pytorch | |
Adapted from: | |
- https://raw.githubusercontent.com/Scitator/Run-Skeleton-Run/master/common/modules/NoisyLinear.py | |
- https://github.com/pytorch/pytorch/pull/2103/files#diff-531f4c06f42260d699f43dabdf741b6d | |
More details can be found in the paper `Noisy Networks for Exploration` | |
Original: https://gist.github.com/wassname/001aff274c7c8196055fabfc06cf80c5 | |
""" | |
import math |