Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/data/experimental/ops/compression_ops.py: 42%
12 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
1# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Ops for compressing and uncompressing dataset elements."""
16from tensorflow.python.data.util import structure
17from tensorflow.python.ops import gen_experimental_dataset_ops as ged_ops
20def compress(element):
21 """Compress a dataset element.
23 Args:
24 element: A nested structure of types supported by Tensorflow.
26 Returns:
27 A variant tensor representing the compressed element. This variant can be
28 passed to `uncompress` to get back the original element.
29 """
30 element_spec = structure.type_spec_from_value(element)
31 tensor_list = structure.to_tensor_list(element_spec, element)
32 return ged_ops.compress_element(tensor_list)
35def uncompress(element, output_spec):
36 """Uncompress a compressed dataset element.
38 Args:
39 element: A scalar variant tensor to uncompress. The element should have been
40 created by calling `compress`.
41 output_spec: A nested structure of `tf.TypeSpec` representing the type(s) of
42 the uncompressed element.
44 Returns:
45 The uncompressed element.
46 """
47 flat_types = structure.get_flat_tensor_types(output_spec)
48 flat_shapes = structure.get_flat_tensor_shapes(output_spec)
49 tensor_list = ged_ops.uncompress_element(
50 element, output_types=flat_types, output_shapes=flat_shapes)
51 return structure.from_tensor_list(output_spec, tensor_list)