Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No compression happened #3

Closed
sanjeetsahoo opened this issue Jul 24, 2019 · 35 comments
Closed

No compression happened #3

sanjeetsahoo opened this issue Jul 24, 2019 · 35 comments

Comments

@sanjeetsahoo
Copy link

sanjeetsahoo commented Jul 24, 2019

I tested two of the pre trained models on an image directory with JPEG images of the size 50-70KB. The output images in the sample folder were of the size 600-800KB. So basically no compression. Am I doing something wrong?

@fab-jul
Copy link
Owner

fab-jul commented Jul 26, 2019

What kind of images did you compress? The models are trained on natural images. And when you say 600-800KB, you mean the .l3c files generated with --write_to_file or the bpsp outputted by test.py?

@fab-jul
Copy link
Owner

fab-jul commented Jul 29, 2019

Or are you using l3c.py?

@BUAAHugeGun
Copy link

After I update my gcc, I can run the codes now.
But I also find that when I run l3c.py on a .jpg file of the size 100kB, the out.l3c becomes to 850kB and the out.png becomes to 1.6M :P (the bpsp of output is great:2.68, but the file is so big...)
Then I tried larger pictures but it allocated more than 10G memory of GPU and it was been killed.
uh...I don't know if it is normal...

@fab-jul
Copy link
Owner

fab-jul commented Jul 31, 2019

@BUAAHugeGun This is because it's a JPG, a lossy format :) So if you feed a .jpg to L3C you are asking it to compress the artefacts from JPG losslessly. The number you should care about is how L3C compares to PNG, which is also lossless.

Regarding the GPU: this is the problem of using CNNs. I think this could be optimized but I did not spend the time. If you have more RAM, you can also try the CPU version of torchac.

@BUAAHugeGun
Copy link

@fab-jul thanks a lot for your response. 👍
I made the mistake because I thought it could conpress any picture sRGB images.
thx

@BUAAHugeGun
Copy link

uh...I'm coming back here for your help.
Today I tried .png & .NEF files.
But I found that the output image(out.png) was full of blur and noise. :(
I used:
python l3c.py 'logs dir' 0524_0001 enc 'input dir' out.l3c
and
python l3c.py 'logs dir' 0524_0001 dec out.l3c out.png

@fab-jul
Copy link
Owner

fab-jul commented Aug 2, 2019

the output will always be equal to the input. what kind of images are in input dir?

@BUAAHugeGun
Copy link

First I tried .jpg as I said. They were the same, Though the size of output is much larger than input.
Then I tried a .png image from Internet, a .png image from kodak test dataset, two .NEF images from the test dataset mentioned in your paper and got outputs of them which were full of noise and blur.
I'm sorry if this will trouble you. : (

@fab-jul
Copy link
Owner

fab-jul commented Aug 2, 2019

Can you post one such .png that produces noise here?

@BUAAHugeGun
Copy link

kodim01

@fab-jul
Copy link
Owner

fab-jul commented Aug 2, 2019

I just downloaded this image and ran it through L3C:

python l3c.py $RELEASED_CKPTS 0524_0001 enc ~/62377157-db349180-b574-11e9-851d-b79e5efc8067.png out.l3c
python l3c.py $RELEASED_CKPTS 0524_0001 dec out.l3c ~/decoded_github.png

And I get the same image back, as expected, i.e. decoded_github.png is exactly the same image I put in.

In theory, the code will always produce the same image. I'm really confused by what you get. Can you post the blurred result as well?

@BUAAHugeGun
Copy link

out

@fab-jul
Copy link
Owner

fab-jul commented Aug 4, 2019

This is very unexpected. It looks very much like you are getting a sampled version of the image. Some questions:

  1. Are you putting in exactly the image you posted above? I.e. what happens when you download that image and feed it?
  2. Are you using the command you posted above? I.e. no --sample or anything?
  3. Are you on the latest git commit?

@BUAAHugeGun
Copy link

I'm sure about the 3 questions. And I tried some times again.
It is strange that I succeeded once using the image above.
And then it failed again.
I noticed that the size of out.l3c is constant, so I guess there is something wrong when using decoder?

@BUAAHugeGun
Copy link

...I downloaded the code again.
And then I installed torchac(GPU).
Now when I use a .jpg image, I also get a blurred image...

@fab-jul
Copy link
Owner

fab-jul commented Aug 7, 2019

Maybe something with torchac is wrong. Can you try to run

python test.py /path/to/logdir 0524_0001 /some/imgdir --write_to_files=files_out_dir

because that runs multiscale_tester.py's _write_to_file which has an assert to check decoding works.

@fab-jul
Copy link
Owner

fab-jul commented Aug 8, 2019

Alternatively, can you send out.l3c?

@BUAAHugeGun
Copy link

I sent a email to you. : )

@fab-jul
Copy link
Owner

fab-jul commented Aug 9, 2019

Thanks! I’ll have a look. If you can, running the above command (the one with --write_to_files) would also be really helpful.

@BUAAHugeGun
Copy link

test

@fab-jul
Copy link
Owner

fab-jul commented Aug 14, 2019

So, I just tried, and I get the same blurry output as you. I then went and compared the binary file you gave me to the one I get when I encode. They only match in the part that encodes the smallest bottleneck (which is encoded with a uniform prior). So, for some reason, your network must produce different probability distributions when encoding.

Now, I don't see how --write_to_files worked, because it should raise an assertion. I'm really not sure what's going on here. Are you encoding on GPU? If so, which GPU do you have? If you try with this file here, does it work, i.e., does --write_to_files work and does l3c.py work?

62377157-db349180-b574-11e9-851d-b79e5efc8067

@ChipsSpectre
Copy link
Contributor

ChipsSpectre commented Aug 23, 2019

Hey
I have the same problem, tested it with the .png files from the CIFAR10 dataset like this car.
automobile4
I used this command to get the l3c:
python test.py ../ 0524_0001 ~/images/bar/ --names "L3C" --recursive=auto --write_to_files ~/images/foo/
and this command to decode it again:

python l3c.py ../ 0524_0001 dec ~/Bilder/foo/automobile4.l3c auto.png

yielding these blurs:

auto

When I use the command for encoding,

python l3c.py ../ 0524_0001 enc ~/images/bar/automobile4.png foo.l3c

I get the different blurs.
auto

The code is executed on NVIDIA RTX 2070, with the anaconda environment installed according to the repository, with torch 1.1.0

@fab-jul
Copy link
Owner

fab-jul commented Aug 26, 2019

I‘ll check this out. Since it happens on CIFAR also, it most likely is not a memory issue

@BUAAHugeGun
Copy link

It is strange that when I first used l3c.py, the output was the same as the input, but when I found this problem, I tried the same input as the first one, the output changed to a blurred image.
And the only commit between the two tries was the modification of torchac...

@fab-jul
Copy link
Owner

fab-jul commented Aug 26, 2019

Wait, are you saying that everything worked before that commit? Or are you not 100% sure?

Edit: Are you running both encoding and decoding on the CPU?

@BUAAHugeGun
Copy link

Uh, I just tried .jpg images on GPU before that commit and they were OK.
Round after the commit, I asked you why the output was larger than input when trying .jpg.
Then I edit the code of torchac as your description and run it on .png images and it didn't work well.
Finally I download code again and found it also didn't work well on .jpg images.

@fab-jul
Copy link
Owner

fab-jul commented Sep 16, 2019

So, I finally have some time to dig into this. Good news: I can now finally reproduce it, with the steps provided by @ChipsSpectre.

@fab-jul
Copy link
Owner

fab-jul commented Sep 16, 2019

Update: This has to do with CUDA.

If I compile torchac without CUDA support AND run all commands with CUDA_VISIBLE_DEVICES="", no errors appear.

Currently however, there is some weird behavior in torchac.py, where it always thinks CUDA is available. I'll dig more later this week.

@BUAAHugeGun
Copy link

thx a lot. I guess it's hard to find this problem.

@ChipsSpectre
Copy link
Contributor

ChipsSpectre commented Sep 20, 2019

Thank you for the tip. I will also have a look into the torchac module.
I could reproduce correct encryption and decryption with

CUDA_VISIBLE_DEVICES=""

on my machine, too.

Edit: The Arithmetic coder does not adapt the device before calling the torchac module.
grafik

The data are transferred to the default device (e.g. a GPU) before starting the bitcoding, where the data is only converted to float.
grafik

I assume now that maybe the error can be avoided by transferring the data to cpu if torchac-cpu is available only, similar to the function encode_logistic_mixture in torchac.

@fab-jul
Copy link
Owner

fab-jul commented Sep 21, 2019

@ChipsSpectre Yes I realized that too now. Another problem is that if you compile with GPU support once, it stays in your build dir, and then torchac.py will always use the GPU version. I'll fix both things.

What's really weird to me however is that it works when using test.py. Because there is a line in there that does an assert output == input. So, when using the decoder in test.py, everything works. Somehow however, when using the decoder through l3c.py, it doesn't work anymore...

If you want to dig into that, it would also be much appreciated :)

@ChipsSpectre
Copy link
Contributor

ChipsSpectre commented Sep 21, 2019

fixed.
the restorer class was the problem.
i create a pull request.

@fab-jul
Copy link
Owner

fab-jul commented Sep 23, 2019

Still working on making the backend selection more seamless, so keeping this open.

@fab-jul
Copy link
Owner

fab-jul commented Oct 2, 2019

@BUAAHugeGun Please try again with the latest master commit and let me know how it goes

@fab-jul
Copy link
Owner

fab-jul commented Nov 26, 2019

Closing this due to inactivity.

@fab-jul fab-jul closed this as completed Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants