Skip to content

Instantly share code, notes, and snippets.

@leechanwoo
leechanwoo / cnn_example.py
Last active September 12, 2017 16:56
Convolutional Neural Network example
import tensorflow as tf
import matplotlib.pyplot as plt
import os
%matplotlib inline
tf.reset_default_graph()
images = "dataset/test_dataset_png/"
image_dir = os.path.join(os.getcwd(), images)
imagenames = [os.path.join(image_dir, f) for f in os.listdir(image_dir)]
@leechanwoo
leechanwoo / cnn_with_tensorboard.py
Last active August 25, 2017 08:49
cnn with tensorboard
import tensorflow as tf
import matplotlib.pyplot as plt
import os
%matplotlib inline
tf.reset_default_graph()
images = "dataset/test_dataset_png/"
image_dir = os.path.join(os.getcwd(), images)
imagenames = [os.path.join(image_dir, f) for f in os.listdir(image_dir)]
@leechanwoo
leechanwoo / estimator_example.py
Last active August 24, 2017 14:06
estimator train example code
import tensorflow as tf
def input_fn():
up = [i for i in range(10)]
down = [9-i for i in range(10)]
features = tf.constant([up if i%2 == 0 else down for i in range(1000)], tf.float32)
label = tf.constant([[1] if i%2 == 0 else [0] for i in range(1000)], tf.float32)
return features, label
def model(features, labels, mode):
@leechanwoo
leechanwoo / input_fn.py
Created August 24, 2017 14:08
input function
def input_fn():
up = [i for i in range(10)]
down = [9-i for i in range(10)]
features = tf.constant([up if i%2 == 0 else down for i in range(1000)], tf.float32)
label = tf.constant([[1] if i%2 == 0 else [0] for i in range(1000)], tf.float32)
return features, label
@leechanwoo
leechanwoo / model_fn.py
Created August 24, 2017 14:21
model function example
def model(features, labels, mode):
layer1 = tf.layers.dense(features, 10)
layer2 = tf.layers.dense(layer1, 10)
layer3 = tf.layers.dense(layer2, 10)
layer4 = tf.layers.dense(layer3, 10)
out = tf.layers.dense(layer4, 1)
global_step = tf.train.get_global_step()
loss = tf.losses.sigmoid_cross_entropy(labels, out)
train_op = tf.train.GradientDescentOptimizer(0.01).minimize(loss, global_step)
@leechanwoo
leechanwoo / estimator_obj.py
Created August 24, 2017 15:06
estimator object
est = tf.estimator.Estimator(model)
est.train(input_fn, steps=5)
@leechanwoo
leechanwoo / rnn_example.py
Last active September 13, 2017 05:55
rnn example
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
tf.reset_default_graph()
sample = 1000
x = np.array([0.01*float(i) for i in range(sample+1)], np.float32)
y = np.sin(x)
@leechanwoo
leechanwoo / signal_classification.py
Last active August 25, 2017 06:08
rnn example data
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
tf.reset_default_graph()
# hyper parameters
samples = 1000
time_step = 100
@leechanwoo
leechanwoo / safe_queue_runners.py
Created August 25, 2017 08:06
key value batch
import tensorflow as tf
import numpy as np
import os
import matplotlib.pyplot as plt
%matplotlib inline
file_dir = os.path.join(os.getcwd(), "dataset/test_dataset_png")
image_paths = [os.path.join(file_dir, i) for i in os.listdir(file_dir)]
@leechanwoo
leechanwoo / gen_dataset.py
Last active August 31, 2017 10:16
gen dataset
def gen_dataset():
up = [i for i in range(10)]
down = [9-i for i in range(10)]
with open("./test.csv", 'w') as f:
writer = csv.writer(f, delimiter=",")
for i in range(5):
writer.writerow([1] + up)
writer.writerow([0] + down)