tensorflow / compression

Data compression in TensorFlow
Apache License 2.0
850 stars 248 forks source link

how to read a tfci file #198

Open LZVSDY opened 1 month ago

LZVSDY commented 1 month ago

Describe the bug How can I read a tfci file? I've tried several times, but all attempts result in an error: 'Error during unpacking: Unexpected dtype: '<dtype: 'bool'>'.

To Reproduce Steps to reproduce the behavior: Generate the result by running python tfci.py compress hific-lo /data1/wsk/prj/PerCo/res/data/MSCOCO30k/000000410482.jpg, and then proceed to read the output.

System (please complete the following information):

Additional context

code

import numpy as np
import tensorflow as tf
import tensorflow_compression as tfc

def convert_bool_to_int(bitstring):

    byte_data = np.frombuffer(bitstring, dtype=np.uint8)

    converted_data = byte_data  

    new_bitstring = converted_data.tobytes()
    return new_bitstring

def read_tfci_file(tfci_file_path):
    with open(tfci_file_path, 'rb') as file:
        bitstring = file.read()

    bitstring = convert_bool_to_int(bitstring)

    packed = tfc.PackedTensors()

    try:
        packed.unpack(bitstring)
        tensors = packed.unpack()
        return tensors
    except Exception as e:
        print(f"Error during unpacking: {e}")
        return None

tfci_file_path = '/data1/wsk/prj/hific/models/1_11zon.png.tfci'
tensors = read_tfci_file(tfci_file_path)
if tensors:
    for tensor in tensors:
        print(tensor)
else:
    print("Failed to read tensors.")