Exemplo n.º 1
0
    def test_get_xs_ys_consistent_wh(self):
        xs = MomentRandomForestTrainTestModel.get_xs_from_results(
            self.features, [0, 1, 2])
        ys = MomentRandomForestTrainTestModel.get_ys_from_results(
            self.features, [0, 1, 2])
        xys = MomentRandomForestTrainTestModel.get_xys_from_results(
            self.features, [0, 1, 2])

        expected_ys = {'label': [2.5, 3.9, 5.0], 'content_id': [0, 1, 2]}

        self.assertEqual(xs['dis_y'][0].shape, (1, 321, 481))
        self.assertEqual(xs['dis_y'][1].shape, (1, 321, 481))
        self.assertEqual(xs['dis_y'][2].shape, (1, 321, 481))
        self.assertEqual(xs['dis_u'][0].shape, (1, 321, 481))
        self.assertEqual(xs['dis_u'][1].shape, (1, 321, 481))
        self.assertEqual(xs['dis_u'][2].shape, (1, 321, 481))
        self.assertEqual(xs['dis_v'][0].shape, (1, 321, 481))
        self.assertEqual(xs['dis_v'][1].shape, (1, 321, 481))
        self.assertEqual(xs['dis_v'][2].shape, (1, 321, 481))
        self.assertAlmostEqual(np.mean(xs['dis_y']),
                               128.26146851380497,
                               places=4)
        self.assertEqual(list(ys['label']), expected_ys['label'])
        self.assertEqual(list(ys['content_id']), expected_ys['content_id'])

        self.assertAlmostEqual(np.mean(xys['dis_y']),
                               128.26146851380497,
                               places=4)
        self.assertEqual(list(xys['label']), expected_ys['label'])
        self.assertEqual(list(xys['content_id']), expected_ys['content_id'])
Exemplo n.º 2
0
    def test_get_xs_ys_inconsistent_wh(self):
        xs = MomentRandomForestTrainTestModel.get_xs_from_results(
            self.features, [0, 8])
        ys = MomentRandomForestTrainTestModel.get_ys_from_results(
            self.features, [0, 8])
        xys = MomentRandomForestTrainTestModel.get_xys_from_results(
            self.features, [0, 8])

        expected_ys = {'label': [2.5, 4.7], 'content_id': [0, 13]}

        self.assertEqual(xs['dis_y'][0].shape, (1, 321, 481))
        self.assertEqual(xs['dis_y'][1].shape, (1, 486, 720))
        self.assertEqual(xs['dis_u'][0].shape, (1, 321, 481))
        self.assertEqual(xs['dis_u'][1].shape, (1, 486, 720))
        self.assertEqual(xs['dis_v'][0].shape, (1, 321, 481))
        self.assertEqual(xs['dis_v'][1].shape, (1, 486, 720))
        self.assertAlmostEqual(np.mean(xs['dis_y'][0]),
                               160.617204551784,
                               places=4)
        self.assertAlmostEqual(np.mean(xs['dis_y'][1]),
                               35.8163894604481,
                               places=4)
        self.assertEqual(list(ys['label']), expected_ys['label'])
        self.assertEqual(list(ys['content_id']), expected_ys['content_id'])

        self.assertEqual(xys['dis_y'][0].shape, (1, 321, 481))
        self.assertEqual(xys['dis_y'][1].shape, (1, 486, 720))
        self.assertEqual(xys['dis_u'][0].shape, (1, 321, 481))
        self.assertEqual(xys['dis_u'][1].shape, (1, 486, 720))
        self.assertEqual(xys['dis_v'][0].shape, (1, 321, 481))
        self.assertEqual(xys['dis_v'][1].shape, (1, 486, 720))
        self.assertEqual(list(xys['label']), expected_ys['label'])
        self.assertEqual(list(xys['content_id']), expected_ys['content_id'])
Exemplo n.º 3
0
    def test_get_xs_ys_inconsistent_wh(self):
        xs = MomentRandomForestTrainTestModel.get_xs_from_results(self.features, [0, 8])
        ys = MomentRandomForestTrainTestModel.get_ys_from_results(self.features, [0, 8])
        xys = MomentRandomForestTrainTestModel.get_xys_from_results(self.features, [0, 8])

        expected_ys = {'label': [2.5, 4.7], 'content_id': [0, 13]}

        self.assertEqual(xs['dis_y'][0].shape, (1, 321, 481))
        self.assertEqual(xs['dis_y'][1].shape, (1, 486, 720))
        self.assertEqual(xs['dis_u'][0].shape, (1, 321, 481))
        self.assertEqual(xs['dis_u'][1].shape, (1, 486, 720))
        self.assertEqual(xs['dis_v'][0].shape, (1, 321, 481))
        self.assertEqual(xs['dis_v'][1].shape, (1, 486, 720))
        self.assertAlmostEqual(np.mean(xs['dis_y'][0]), 160.617204551784, places=4)
        self.assertAlmostEqual(np.mean(xs['dis_y'][1]), 35.8163894604481, places=4)
        self.assertEqual(list(ys['label']), expected_ys['label'])
        self.assertEqual(list(ys['content_id']), expected_ys['content_id'])

        self.assertEqual(xys['dis_y'][0].shape, (1, 321, 481))
        self.assertEqual(xys['dis_y'][1].shape, (1, 486, 720))
        self.assertEqual(xys['dis_u'][0].shape, (1, 321, 481))
        self.assertEqual(xys['dis_u'][1].shape, (1, 486, 720))
        self.assertEqual(xys['dis_v'][0].shape, (1, 321, 481))
        self.assertEqual(xys['dis_v'][1].shape, (1, 486, 720))
        self.assertEqual(list(xys['label']), expected_ys['label'])
        self.assertEqual(list(xys['content_id']), expected_ys['content_id'])
Exemplo n.º 4
0
    def test_train_save_load_predict(self):

        xs = MomentRandomForestTrainTestModel.get_xs_from_results(
            self.features)
        ys = MomentRandomForestTrainTestModel.get_ys_from_results(
            self.features)
        xys = MomentRandomForestTrainTestModel.get_xys_from_results(
            self.features)

        # using dis_y only
        del xs['dis_u']
        del xs['dis_v']
        del xys['dis_u']
        del xys['dis_v']

        model = MomentRandomForestTrainTestModel({
            'norm_type': 'normalize',
            'random_state': 0
        })
        model.train(xys)

        model.to_file(self.model_filename)
        self.assertTrue(os.path.exists(self.model_filename))

        loaded_model = TrainTestModel.from_file(self.model_filename)

        result = loaded_model.evaluate(xs, ys)
        self.assertAlmostEquals(result['RMSE'], 0.17634739353518517, places=4)
Exemplo n.º 5
0
    def test_train_predict_using_yuv(self):
        xs = MomentRandomForestTrainTestModel.get_xs_from_results(self.features)
        ys = MomentRandomForestTrainTestModel.get_ys_from_results(self.features)
        xys = MomentRandomForestTrainTestModel.get_xys_from_results(self.features)

        model = MomentRandomForestTrainTestModel({'norm_type':'normalize', 'random_state':0})
        model.train(xys)

        result = model.evaluate(xs, ys)
        self.assertAlmostEquals(result['RMSE'], 0.51128487038576109, places=4)
Exemplo n.º 6
0
    def test_train_predict_using_yuv(self):
        xs = MomentRandomForestTrainTestModel.get_xs_from_results(
            self.features)
        ys = MomentRandomForestTrainTestModel.get_ys_from_results(
            self.features)
        xys = MomentRandomForestTrainTestModel.get_xys_from_results(
            self.features)

        model = MomentRandomForestTrainTestModel({
            'norm_type': 'normalize',
            'random_state': 0
        })
        model.train(xys)

        result = model.evaluate(xs, ys)
        self.assertAlmostEquals(result['RMSE'], 0.51128487038576109, places=4)
Exemplo n.º 7
0
    def test_get_xs_ys_consistent_wh(self):
        xs = MomentRandomForestTrainTestModel.get_xs_from_results(self.features, [0, 1, 2])
        ys = MomentRandomForestTrainTestModel.get_ys_from_results(self.features, [0, 1, 2])
        xys = MomentRandomForestTrainTestModel.get_xys_from_results(self.features, [0, 1, 2])

        expected_ys = {'label': [2.5, 3.9, 5.0], 'content_id': [0, 1, 2]}

        self.assertEqual(xs['dis_y'][0].shape, (1, 321, 481))
        self.assertEqual(xs['dis_y'][1].shape, (1, 321, 481))
        self.assertEqual(xs['dis_y'][2].shape, (1, 321, 481))
        self.assertEqual(xs['dis_u'][0].shape, (1, 321, 481))
        self.assertEqual(xs['dis_u'][1].shape, (1, 321, 481))
        self.assertEqual(xs['dis_u'][2].shape, (1, 321, 481))
        self.assertEqual(xs['dis_v'][0].shape, (1, 321, 481))
        self.assertEqual(xs['dis_v'][1].shape, (1, 321, 481))
        self.assertEqual(xs['dis_v'][2].shape, (1, 321, 481))
        self.assertAlmostEqual(np.mean(xs['dis_y']), 128.26146851380497, places=4)
        self.assertEqual(list(ys['label']), expected_ys['label'])
        self.assertEqual(list(ys['content_id']), expected_ys['content_id'])

        self.assertAlmostEqual(np.mean(xys['dis_y']), 128.26146851380497, places=4)
        self.assertEqual(list(xys['label']), expected_ys['label'])
        self.assertEqual(list(xys['content_id']), expected_ys['content_id'])
Exemplo n.º 8
0
    def test_train_predict(self):
        xs = MomentRandomForestTrainTestModel.get_xs_from_results(self.features)
        ys = MomentRandomForestTrainTestModel.get_ys_from_results(self.features)
        xys = MomentRandomForestTrainTestModel.get_xys_from_results(self.features)

        # using dis_y only
        del xs['dis_u']
        del xs['dis_v']
        del xys['dis_u']
        del xys['dis_v']

        model = MomentRandomForestTrainTestModel({'norm_type':'normalize', 'random_state':0})
        model.train(xys)

        result = model.evaluate(xs, ys)
        self.assertAlmostEquals(result['RMSE'], 0.17634739353518517, places=4)
Exemplo n.º 9
0
    def test_train_predict(self):
        xs = MomentRandomForestTrainTestModel.get_xs_from_results(
            self.features)
        ys = MomentRandomForestTrainTestModel.get_ys_from_results(
            self.features)
        xys = MomentRandomForestTrainTestModel.get_xys_from_results(
            self.features)

        # using dis_y only
        del xs['dis_u']
        del xs['dis_v']
        del xys['dis_u']
        del xys['dis_v']

        model = MomentRandomForestTrainTestModel({
            'norm_type': 'normalize',
            'random_state': 0
        })
        model.train(xys)

        result = model.evaluate(xs, ys)
        self.assertAlmostEquals(result['RMSE'], 0.17634739353518517, places=4)
Exemplo n.º 10
0
    def test_train_save_load_predict(self):

        xs = MomentRandomForestTrainTestModel.get_xs_from_results(self.features)
        ys = MomentRandomForestTrainTestModel.get_ys_from_results(self.features)
        xys = MomentRandomForestTrainTestModel.get_xys_from_results(self.features)

        # using dis_y only
        del xs['dis_u']
        del xs['dis_v']
        del xys['dis_u']
        del xys['dis_v']

        model = MomentRandomForestTrainTestModel({'norm_type':'normalize', 'random_state':0})
        model.train(xys)

        model.to_file(self.model_filename)
        self.assertTrue(os.path.exists(self.model_filename))

        loaded_model = TrainTestModel.from_file(self.model_filename)

        result = loaded_model.evaluate(xs, ys)
        self.assertAlmostEquals(result['RMSE'], 0.17634739353518517, places=4)