1 class PtbReaderTest(tf.test.TestCase):
2
3 def setUp(self):
4 self._string_data = "\n".join(
5 [" hello there i am",
6 " rain as day",
7 " want some cheesy puffs ?"])
8
9 def testPtbRawData(self):
10 tmpdir = tf.test.get_temp_dir()
11 for suffix in "train", "valid", "test":
12 filename = os.path.join(tmpdir, "ptb.%s.txt" % suffix)
13 with tf.gfile.GFile(filename, "w") as fh:
14 fh.write(self._string_data)
15 # Smoke test
16 output = reader.ptb_raw_data(tmpdir)
17 self.assertEqual(len(output), 4)
18
19 def testPtbProducer(self):
20 raw_data = [4, 3, 2, 1, 0, 5, 6, 1, 1, 1, 1, 0, 3, 4, 1]
21 batch_size = 3
22 num_steps = 2
23 x, y = reader.ptb_producer(raw_data, batch_size, num_steps)
24 with self.test_session() as session:
25 coord = tf.train.Coordinator()
26 tf.train.start_queue_runners(session, coord=coord)
27 try:
28 xval, yval = session.run([x, y])
29 self.assertAllEqual(xval, [[4, 3], [5, 6], [1, 0]])
30 self.assertAllEqual(yval, [[3, 2], [6, 1], [0, 3]])
31 xval, yval = session.run([x, y])
32 self.assertAllEqual(xval, [[2, 1], [1, 1], [3, 4]])
33 self.assertAllEqual(yval, [[1, 0], [1, 1], [4, 1]])
34 finally:
35 coord.request_stop()
36 coord.join()

Figure. 1: Schematic of class PtbReaderTest

results matching ""

    No results matching ""