Commit 6a6d00cd authored by Yuxin Wu's avatar Yuxin Wu

unittest in models/

parent 06643a86
...@@ -8,4 +8,5 @@ In development. No document, don't use. ...@@ -8,4 +8,5 @@ In development. No document, don't use.
+ Provide callbacks to control training behavior (as in [Keras](http://keras.io)). + Provide callbacks to control training behavior (as in [Keras](http://keras.io)).
+ Use `Dataflow` to gain fine-grained control on data preprocessing. + Use `Dataflow` to gain fine-grained control on data preprocessing.
+ Automatically use the Queue operator in tensorflow to speed up input. + Automatically use the Queue operator in tensorflow to speed up input.
+ Training and testing graph are modeled together, automatically. Just need to follow the conventions to setup stuffs. + Training and testing graph are modeled together. Just need to follow the conventions to setup stuffs.
+ Use tensorboard easily.
...@@ -25,7 +25,7 @@ CAPACITY = MIN_AFTER_DEQUEUE + 3 * BATCH_SIZE ...@@ -25,7 +25,7 @@ CAPACITY = MIN_AFTER_DEQUEUE + 3 * BATCH_SIZE
def get_model(inputs, is_training): def get_model(inputs, is_training):
""" """
Args: Args:
inputs: a list of input variable, inputs: a list of input variable for training
e.g.: [image_var, label_var] with: e.g.: [image_var, label_var] with:
image_var: bx28x28 image_var: bx28x28
label_var: bx1 integer label_var: bx1 integer
......
## Dataflow ## Dataflow
Dataflow: use `yield` to build a efficient data processing pipeline. Dataflow: use `yield` to build a simple and efficient data processing pipeline.
NOTE: Dataflow aims to be independent of tensorflow. NOTE: Dataflow aims to be independent of tensorflow.
It should be useful for other python-based learning libraries. It should be useful for other python-based learning libraries.
Documents to be done.
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
# File: _test.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
import tensorflow as tf
import numpy as np
from . import *
import unittest
subs = unittest.TestCase.__subclasses__()
def run_test_case(case):
suite = unittest.TestLoader().loadTestsFromTestCase(case)
unittest.TextTestRunner(verbosity=2).run(suite)
for cls in subs:
if 'tensorpack.models' in str(cls):
run_test_case(cls)
...@@ -57,3 +57,23 @@ def FixedUnPooling(x, shape, unpool_mat=None): ...@@ -57,3 +57,23 @@ def FixedUnPooling(x, shape, unpool_mat=None):
input_shape[2] * shape[1], input_shape[2] * shape[1],
input_shape[3]]) input_shape[3]])
return prod return prod
import unittest
class TestPool(unittest.TestCase):
def test_fixed_unpooling(self):
h, w = 3, 4
mat = np.random.rand(h, w).astype('float32')
inp = tf.Variable(mat)
inp = tf.reshape(inp, [1, h, w, 1])
output = FixedUnPooling('unpool', inp, 2)
sess = tf.Session()
sess.run(tf.initialize_all_variables())
res = sess.run([output])[0]
self.assertEqual(res.shape, (1, 2*h, 2*w, 1))
# mat is on cornser
ele = res[0,::2,::2,0]
self.assertTrue((ele == mat).all())
# the rest are zeros
res[0,::2,::2,0] = 0
self.assertTrue((res == 0).all())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment