Ejemplo n.º 1
0
    def testEndToEndSizes0d(self):
        """Tests that the output sizes match when training/running real 0d data.

    Uses mnist with dual summarizing LSTMs to reduce to a single value.
    """
        filename = _testdata('mnist-tiny')
        with self.test_session() as sess:
            model = vgsl_model.InitNetwork(
                filename,
                model_spec='4,0,0,1[Cr5,5,16 Mp3,3 Lfys16 Lfxs16]O0s12',
                mode='train')
            tf.initialize_all_variables().run(session=sess)
            coord = tf.train.Coordinator()
            tf.train.start_queue_runners(sess=sess, coord=coord)
            _, step = model.TrainAStep(sess)
            self.assertEqual(step, 1)
            output, labels = model.RunAStep(sess)
            self.assertEqual(len(output.shape), 2)
            self.assertEqual(len(labels.shape), 1)
            self.assertEqual(output.shape[0], labels.shape[0])
            self.assertEqual(output.shape[1], 12)
Ejemplo n.º 2
0
    def testEndToEndSizes1dCTC(self):
        """Tests that the output sizes match when training with CTC.

    Basic bidi LSTM on top of convolution and summarizing LSTM with CTC.
    """
        filename = _testdata('arial-32-tiny')
        with self.test_session() as sess:
            model = vgsl_model.InitNetwork(
                filename,
                model_spec='2,0,0,1[Cr5,5,16 Mp3,3 Lfys16 Lbx100]O1c105',
                mode='train')
            tf.initialize_all_variables().run(session=sess)
            coord = tf.train.Coordinator()
            tf.train.start_queue_runners(sess=sess, coord=coord)
            _, step = model.TrainAStep(sess)
            self.assertEqual(step, 1)
            output, labels = model.RunAStep(sess)
            self.assertEqual(len(output.shape), 3)
            self.assertEqual(len(labels.shape), 2)
            self.assertEqual(output.shape[0], labels.shape[0])
            # This is ctc - the only cast-iron guarantee is labels <= output.
            self.assertLessEqual(labels.shape[1], output.shape[1])
            self.assertEqual(output.shape[2], 105)
Ejemplo n.º 3
0
    def testEndToEndSizes1dFixed(self):
        """Tests that the output sizes match when training/running 1 data.

    Convolution, summarizing LSTM with fwd rev fwd to allow no CTC.
    """
        filename = _testdata('numbers-16-tiny')
        with self.test_session() as sess:
            model = vgsl_model.InitNetwork(
                filename,
                model_spec=
                '8,0,0,1[Cr5,5,16 Mp3,3 Lfys16 Lfx64 Lrx64 Lfx64]O1s12',
                mode='train')
            tf.initialize_all_variables().run(session=sess)
            coord = tf.train.Coordinator()
            tf.train.start_queue_runners(sess=sess, coord=coord)
            _, step = model.TrainAStep(sess)
            self.assertEqual(step, 1)
            output, labels = model.RunAStep(sess)
            self.assertEqual(len(output.shape), 3)
            self.assertEqual(len(labels.shape), 2)
            self.assertEqual(output.shape[0], labels.shape[0])
            # Not CTC, output lengths match.
            self.assertEqual(output.shape[1], labels.shape[1])
            self.assertEqual(output.shape[2], 12)