Skip to content

Instantly share code, notes, and snippets.

@pannous
pannous / tensorflow_autoencoder.py
Created February 5, 2016 19:17
A simple MNIST classifer AND autoencoder in one
"""A simple MNIST classifer AND autoencoder in one
"""
# Import data
import input_data
mnist = input_data.read_data_sets("/data/mnist/", one_hot=True)
import tensorflow as tf
sess = tf.InteractiveSession()
@pannous
pannous / tensorflow-densenet.py
Last active July 30, 2017 16:15
Implementation of DenseNet: Densely Connected Convolutional Networks https://arxiv.org/abs/1608.06993 in tensorflow
#!/usr/bin/python
from __future__ import print_function
import os
import numpy as np
import tensorflow as tf
from tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets
# mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
mnist = read_data_sets("/tmp/data/", one_hot=True)
import numpy as np
from keras.models import Sequential
from keras.layers.core import Dense, Activation
xoder={
(0,0):0,
(0,1):1,
(1,0):1,
(1,1):0
}
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
num_classes = 10
width, height = 28, 28
(x_train, y_train), (x_test, y_test) = mnist.load_data()
@pannous
pannous / hello_sequence.py
Last active March 22, 2018 17:59
Simple "Hello World" for tensorflow seq2seq model
"""Sequence-to-sequence model with an attention mechanism."""
# see https://www.tensorflow.org/versions/r0.10/tutorials/seq2seq/index.html
# compare https://github.com/tflearn/tflearn/blob/master/examples/nlp/seq2seq_example.py
from __future__ import print_function
import numpy as np
import tensorflow as tf
vocab_size=256 # We are lazy, so we avoid fency mapping and just use one *class* per character/byte
target_vocab_size=vocab_size
learning_rate=0.1
@pannous
pannous / tensorflow_xor_hello_world.py
Created November 11, 2015 14:33
A simple neural network learning the XOR function with the tensorflow framework
#!/usr/bin/env PYTHONIOENCODING="utf-8" python
"""
A simple neural network learning the XOR function
"""
import tensorflow as tf
sess = tf.InteractiveSession()
# Desired input output mapping of XOR function:
x_ = [[0, 0], [0, 1], [1, 0], [1, 1]] # input
#labels=[0, 1, 1, 0] # output =>