Skip to content

Instantly share code, notes, and snippets.

View FlorianMuellerklein's full-sized avatar

Florian FlorianMuellerklein

View GitHub Profile
mytheme.scatter = theme_bw() + theme(legend.position = 'none', panel.border = element_blank(), axis.line = element_blank(), axis.title = element_text(size = rel(1.5), face = 'bold'))
mytheme.bar = theme_bw() + theme(panel.grid.minor.x=element_blank(), panel.grid.major.x=element_blank(), axis.text.x = element_text(size = rel(1.1), face = 'bold'), axis.title.x = element_blank(), axis.text.y = element_text(size = rel(1.1), face = 'bold'), axis.title.y = element_text(vjust = 1), legend.position = 'none', panel.border = element_blank(), axis.line = element_blank(), axis.title = element_text(size = rel(1.5), face = 'bold'))
@FlorianMuellerklein
FlorianMuellerklein / gist:d761e09df7c770a93c17
Created January 11, 2015 21:00
gbdt feature tansformation example
import pandas as pd
import numpy as np
from sklearn.ensemble import GradientBoostingClassifier
train_loc = 'train.csv'
test_loc = 'test.csv'
TREES = 30
NODES = 7
import lasagne
from lasagne.nonlinearities import rectify, softmax
from lasagne.layers import InputLayer, DenseLayer, DropoutLayer, batch_norm, BatchNormLayer
from lasagne.layers import ElemwiseSumLayer, NonlinearityLayer, GlobalPoolLayer
from lasagne.layers.dnn import Conv2DDNNLayer as ConvLayer
from lasagne.init import HeNormal
def ResNet_FullPre_Wide(input_var=None, n=3, k=2):
'''
Adapted from https://github.com/Lasagne/Recipes/tree/master/papers/deep_residual_learning.
@FlorianMuellerklein
FlorianMuellerklein / PreResNet_Example.py
Last active June 6, 2016 23:21
Potential Example for Lasagne/Recipes
#!/usr/bin/env python
"""
Lasagne example of ResNet-110 from 'Identity Mappings in Deep Residual Networks', Kaiming He et al. 2016 (https://arxiv.org/abs/1603.05027)
"""
from __future__ import print_function
import sys
@FlorianMuellerklein
FlorianMuellerklein / multiprocess_batch_iter.py
Last active August 17, 2020 08:28
Quick way to multiprocess batch iteration for training deep learning models. Hacked together from Daniel Nouri's batch iterator https://github.com/dnouri/nolearn/blob/master/nolearn/lasagne/base.py#L70 and Jan Schülter's example https://github.com/Lasagne/Lasagne/issues/12#issuecomment-59494251
import multiprocessing as mp
class threaded_batch_iter(object):
'''
Batch iterator to make transformations on the data.
Uses multiprocessing so that batches can be created on CPU while GPU runs previous batch
'''
def __init__(self, batchsize):
self.batchsize = batchsize
from keras.layers import merge, Input, Dropout
from keras.layers import Dense, Activation
from keras.layers import Convolution2D, MaxPooling2D
from keras.layers.pooling import GlobalAveragePooling2D
from keras.layers import BatchNormalization
from keras.models import Model
'''
Adapted from https://arxiv.org/pdf/1611.10080v1.pdf.
It's a wide and deep residual network designed for optimal feature extraction and gradient flow.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@FlorianMuellerklein
FlorianMuellerklein / file.md
Created August 3, 2018 18:03 — forked from chauhan-utk/file.md
PyTorch replace pretrained model layers

This code snippet shows how we can change a layer in a pretrained model. In the following code, we change all the ReLU activation functions with SELU in a resnet18 model.

import torch
from torchvision import model

resnet18 = model.resnet18(pretrained=True)

def funct(list_mods):