Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
'''Train a simple deep CNN on the CIFAR10 small images dataset.
GPU run command:
THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python cifar10_cnn.py
It gets down to 0.65 test logloss in 25 epochs, and down to 0.55 after 50 epochs.
(it's still underfitting at that point, though).
Note: the data was pickled with Python 2, and some encoding issues might prevent you
from loading it in Python 3. You might have to load it in Python 2,
@dansbecker
dansbecker / autoencoder.py
Created April 14, 2016 23:22
Non-functioning autoencoder, with an error that surprises me.
import numpy as np
from keras.models import Model
from keras.layers import Input, Dense
input_size = 1000
n_obs = 200
encoding_size = 50
x = Input(shape=(input_size,))
z = Dense(encoding_size, activation='sigmoid', name='z')(x)
@dansbecker
dansbecker / readme.md
Created May 16, 2016 06:17 — forked from baraldilorenzo/readme.md
VGG-16 pre-trained model for Keras

##VGG16 model for Keras

This is the Keras model of the 16-layer network used by the VGG team in the ILSVRC-2014 competition.

It has been obtained by directly converting the Caffe model provived by the authors.

Details about the network architecture can be found in the following arXiv paper:

Very Deep Convolutional Networks for Large-Scale Image Recognition

K. Simonyan, A. Zisserman

@dansbecker
dansbecker / keras_round_trip_model_saving.py
Created May 23, 2016 20:32
Gist showing a weird caveat in model saving and model loading in keras. Uncommenting lines 25-26 causes an error.
from keras.layers import Input, Dense, merge, Flatten
from keras.layers.convolutional import Convolution2D
from keras.models import Model, model_from_json
from keras import backend as K
def make_model(img_edge_size):
img_shape = (3, img_edge_size, img_edge_size)
mask_shape = (1, img_edge_size, img_edge_size)
$ cat CMakeFiles/CMakeOutput.log
The system is: CYGWIN - 2.6.0(0.304/5/3) - x86_64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: /usr/bin/cc
Build flags:
Id flags:
The output was:
0
Determining if the function dgettext exists failed with the following output:
Change Dir: /home/powersju/Madeline_2.0_PDE/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make.exe" "cmTC_872e9/fast"
/usr/bin/make -f CMakeFiles/cmTC_872e9.dir/build.make CMakeFiles/cmTC_872e9.dir/build
make[1]: Entering directory '/home/powersju/Madeline_2.0_PDE/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_872e9.dir/CheckFunctionExists.c.o
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=dgettext -o CMakeFiles/cmTC_872e9.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.6.2/Modules/CheckFunctionExists.c
<command-line>:0:23: warning: conflicting types for built-in function ‘dgettext’
/usr/share/cmake-3.6.2/Modules/CheckFunctionExists.c:7:3: note: in expansion of macro ‘CHECK_FUNCTION_EXISTS’
@dansbecker
dansbecker / featurize.py
Last active April 28, 2017 20:55
Use a pretrained network to featurize data for cats vs dogs
from keras.applications.resnet50 import ResNet50, preprocess_input
from keras.preprocessing.image import load_img, img_to_array
import numpy as np
from os import listdir
from os.path import join
import pandas as pd
def featurize(fpath, model, img_size):
'''Use trained model to convert image to vector describing content
@dansbecker
dansbecker / predict_from_text.py
Last active July 19, 2017 16:29 — forked from tyarkoni/predict_from_text.py
simple example predicting binary outcome from text features with sklearn (with extra comments for Alon)
from sklearn.datasets import fetch_20newsgroups
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
# A pipeline "stitches together" the various steps of a modeling process into a single piece. You should either try to get a separate explanation of this, or try to do without it.
# In general pipelines are pretty cool. But, one more thing to learn.
from sklearn.pipeline import Pipeline
import pandas as pd
import numpy as np
@dansbecker
dansbecker / predict_from_text.py
Created July 19, 2017 16:07 — forked from tyarkoni/predict_from_text.py
simple example predicting binary outcome from text features with sklearn
from sklearn.datasets import fetch_20newsgroups
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline
import pandas as pd
import numpy as np
# Grab just two categories from the 20 newsgroups dataset
categories=['sci.space', 'rec.autos']