Git Product home page Git Product logo

Comments (10)

PascalBACCHUS avatar PascalBACCHUS commented on August 22, 2024 1

Glad to have been of use.

from compressai.

jbegaint avatar jbegaint commented on August 22, 2024

Hi Pascal, right the format it a bit different, the evaluation expects just the state dict whereas the training script also saves training information (loss value, optimizer state, etc..) as you can see from the print. I'll update the evaluation script to accept checkpoints from the training script. In the mean time, it should work if you extract the state_dict key in the checkpoint from the train example.

from compressai.

PascalBACCHUS avatar PascalBACCHUS commented on August 22, 2024

Hi Jean,

Thank you for your reply.
I extracted the state_dict key from the checkpoint and feed it to compressai.utils.eval_model. But after training the net needs to be updated or it raises errors. In the end, I managed to make it work.

However when I downloaded the corresponding pretrained tar file to test compressai.utils.eval_model.
https://compressai.s3.amazonaws.com/models/v1/bmshj2018-factorized-prior-3-5c6f152b.pth.tar

I got some errors:

Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/udd/dbacchus/Codes/CompressAI/compressai/utils/eval_model/__main__.py", line 301, in <module>
    main(sys.argv[1:])
  File "/udd/dbacchus/Codes/CompressAI/compressai/utils/eval_model/__main__.py", line 277, in main
    model = load_func(*opts, run)
  File "/udd/dbacchus/Codes/CompressAI/compressai/utils/eval_model/__main__.py", line 145, in load_checkpoint
    return architectures[arch].from_state_dict(torch.load(checkpoint_path)).eval()
  File "/udd/dbacchus/Codes/CompressAI/compressai/models/priors.py", line 168, in from_state_dict
    net.load_state_dict(state_dict)
  File "/udd/dbacchus/Codes/CompressAI/compressai/models/priors.py", line 105, in load_state_dict
    super().load_state_dict(state_dict)
  File "/udd/dbacchus/env_py3.7/lib/python3.7/site-packages/torch/nn/modules/module.py", line 847, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for FactorizedPrior:
	Missing key(s) in state_dict: "entropy_bottleneck._matrix0", "entropy_bottleneck._bias0", "entropy_bottleneck._factor0", "entropy_bottleneck._matrix1", "entropy_bottleneck._bias1", "entropy_bottleneck._factor1", "entropy_bottleneck._matrix2", "entropy_bottleneck._bias2", "entropy_bottleneck._factor2", "entropy_bottleneck._matrix3", "entropy_bottleneck._bias3", "entropy_bottleneck._factor3", "entropy_bottleneck._matrix4", "entropy_bottleneck._bias4". 
	Unexpected key(s) in state_dict: "entropy_bottleneck._biases.0", "entropy_bottleneck._biases.1", "entropy_bottleneck._biases.2", "entropy_bottleneck._biases.3", "entropy_bottleneck._biases.4", "entropy_bottleneck._factors.0", "entropy_bottleneck._factors.1", "entropy_bottleneck._factors.2", "entropy_bottleneck._factors.3", "entropy_bottleneck._matrices.0", "entropy_bottleneck._matrices.1", "entropy_bottleneck._matrices.2", "entropy_bottleneck._matrices.3", "entropy_bottleneck._matrices.4".

I found differences in both state_dict,, especially in the item's order.

from compressai.

jbegaint avatar jbegaint commented on August 22, 2024

Yes you need to update the model to compute the CDFs based on the trained parameters of the entropy bottleneck(s) (as per the doc here: https://interdigitalinc.github.io/CompressAI/tutorial_train.html#updating-the-model).

Regarding the error from the pretrained model, can you please provide the compressai version you are using?

from compressai.

PascalBACCHUS avatar PascalBACCHUS commented on August 22, 2024

I'm using the latest version v1.1.1.

from compressai.

jbegaint avatar jbegaint commented on August 22, 2024

ok thx, can you provide a short script so I can reproduce the error?

from compressai.

PascalBACCHUS avatar PascalBACCHUS commented on August 22, 2024

OK sure, it's quite simple really.

I just trained a model (bmshj2018-factorized) on my own dataset.
python3 train.py -d $DATASET --epochs 100 -lr 1e-4 --batch-size 16 --cuda --save

Then I downloaded a pretrained tar file as indicated in the documentation.
https://compressai.s3.amazonaws.com/models/v1/bmshj2018-factorized-prior-3-5c6f152b.pth.tar

Finally I tried to run the compressai.utils.eval_model script
python3 -m compressai.utils.eval_model checkpoint $DATASET -a bmshj2018-factorized -p bmshj2018-factorized-prior-3-5c6f152b.pth.tar

from compressai.

jbegaint avatar jbegaint commented on August 22, 2024

Got it thanks!
So we changed the state dict format a few months ago to support multi gpu. Thanks for reporting this, we should convert the models in both checkpoint and pretrained mode.

Side note, you actually don't have to download manually the pretrained weights but can use this command python3 -m compressai.utils.eval_model pretrained ...

from compressai.

zjnlxk avatar zjnlxk commented on August 22, 2024

I also encountered the same error, can you explain how to solve it?

from compressai.

zjnlxk avatar zjnlxk commented on August 22, 2024

@jbegaint @PascalBACCHUS

from compressai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.