Justin-Tan / high-fidelity-generative-compression

Pytorch implementation of High-Fidelity Generative Image Compression + Routines for neural image compression
Apache License 2.0
420 stars 79 forks source link

Issues with pop() function in ans.py #54

Open daniel-bogdoll opened 1 year ago

daniel-bogdoll commented 1 year ago

Hey Justin,

thanks for the repo, great work! When I run your decoder, it works just fine for a while, but every once in a while I get the following message:

image_compression_container_decoder  | [ERROR] [1696691601.057191]: bad callback: <bound method GANDecoder.decoder_callback of <__main__.GANDecoder object at 0x7fafa6c79dc0>>
image_compression_container_decoder  | Traceback (most recent call last):
image_compression_container_decoder  |   File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 750, in _invoke_callback
image_compression_container_decoder  |     cb(msg)
image_compression_container_decoder  |   File "/home/carpc/catkin_ws/src/generative_models/scripts/demo_decoder_image_gan.py", line 34, in decoder_callback
image_compression_container_decoder  |     decoded_img = self.decode(in_encoded_img)
image_compression_container_decoder  |   File "/home/carpc/catkin_ws/src/generative_models/scripts/demo_decoder_image_gan.py", line 55, in decode
image_compression_container_decoder  |     output_decoder = decompress(self.gan, in_encoded_img)
image_compression_container_decoder  |   File "/home/carpc/catkin_ws/src/generative_models/scripts/gan_compression.py", line 22, in decompress
image_compression_container_decoder  |     compressed_output = model.decompress(data)
image_compression_container_decoder  |   File "/home/carpc/catkin_ws/src/generative_models/scripts/high_fidelity_generative_compression/gan_compression/src/model.py", line 327, in decompress
image_compression_container_decoder  |     latents_decoded = self.Hyperprior.decompress_forward(compression_output, device=utils.get_device())
image_compression_container_decoder  |   File "/home/carpc/catkin_ws/src/generative_models/scripts/high_fidelity_generative_compression/gan_compression/src/hyperprior.py", line 269, in decompress_forward
image_compression_container_decoder  |     latents_decoded, _ = self.prior_entropy_model.decompress(latents_encoded, means=latent_means,
image_compression_container_decoder  |   File "/home/carpc/catkin_ws/src/generative_models/scripts/high_fidelity_generative_compression/gan_compression/src/compression/prior_model.py", line 240, in decompress
image_compression_container_decoder  |     decoded = compression_utils.ans_decompress(encoded, indices, cdf, cdf_length, cdf_offset,
image_compression_container_decoder  |   File "/home/carpc/catkin_ws/src/generative_models/scripts/high_fidelity_generative_compression/gan_compression/src/compression/compression_utils.py", line 184, in ans_decompress
image_compression_container_decoder  |     decoded = entropy_coding.vec_ans_index_decoder(
image_compression_container_decoder  |   File "/home/carpc/catkin_ws/src/generative_models/scripts/high_fidelity_generative_compression/gan_compression/src/compression/entropy_coding.py", line 620, in vec_ans_index_decoder
image_compression_container_decoder  |     message, value = symbol_pop(message)
image_compression_container_decoder  |   File "/home/carpc/catkin_ws/src/generative_models/scripts/high_fidelity_generative_compression/gan_compression/src/compression/entropy_coding.py", line 40, in pop
image_compression_container_decoder  |     return pop_fun(start, freq), symbol
image_compression_container_decoder  |   File "/home/carpc/catkin_ws/src/generative_models/scripts/high_fidelity_generative_compression/gan_compression/src/compression/ans.py", line 85, in pop
image_compression_container_decoder  |     tail, new_head = stack_slice(tail_, n)
image_compression_container_decoder  |   File "/home/carpc/catkin_ws/src/generative_models/scripts/high_fidelity_generative_compression/gan_compression/src/compression/ans.py", line 35, in stack_slice
image_compression_container_decoder  |     arr, stack = stack
image_compression_container_decoder  | ValueError: not enough values to unpack (expected 2, got 0)
image_compression_container_decoder  

My setup is a bit complicated to reproduce, as I have embedded the code in a ROS node as part of a larger stack. The decoder (mostly) actually continues working, but I have also seen it crashing. Do you have any suggestions on how to fix it? Would it be sufficient to simply check if tail_ is not empty, so that the slice function cannot fail? As the error occurs so deep "inside" the code, I find it a bit hard to detect the root cause.

itsianmac commented 1 year ago

I encountered the same issue when decoding with compress.load_and_decompress(). Interestingly, compress_and_decompress() seems to work without any issues. I only encounter this error when trying to decompress a saved representation. It is difficult to diagnose, but I hope this extra context can help solve the mystery.