google-research
56 строк · 2.0 Кб
1# coding=utf-8
2# Copyright 2024 The Google Research Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16"""Tests for criteo.data_lib."""
17
18from __future__ import absolute_import
19from __future__ import division
20from __future__ import print_function
21
22from absl.testing import absltest
23import six
24from six.moves import range
25import tensorflow.compat.v2 as tf
26
27from uq_benchmark_2019.criteo import data_lib
28
29
30class DataLibTest(absltest.TestCase):
31
32def test_build_dataset(self):
33config = data_lib.DataConfig(split='train', fake_data=True)
34dataset = data_lib.build_dataset(config, batch_size=8,
35is_training=False, fake_training=False)
36
37# Check output_shapes.
38features_shapes, label_shape = dataset.output_shapes
39self.assertEqual([None], label_shape.as_list())
40expected_keys = [data_lib.feature_name(i)
41for i in range(1, data_lib.NUM_TOTAL_FEATURES+1)]
42self.assertSameElements(expected_keys, list(features_shapes.keys()))
43for key, shape in six.iteritems(features_shapes):
44self.assertEqual([None], shape.as_list(), 'Unexpected shape at key='+key)
45
46# Check output_types.
47features_types, label_type = tf.compat.v1.data.get_output_types(dataset)
48self.assertEqual(tf.float32, label_type)
49for idx in data_lib.INT_FEATURE_INDICES:
50self.assertEqual(tf.float32, features_types[data_lib.feature_name(idx)])
51for idx in data_lib.CAT_FEATURE_INDICES:
52self.assertEqual(tf.string, features_types[data_lib.feature_name(idx)])
53
54
55if __name__ == '__main__':
56absltest.main()
57