DAI-Lab / SteganoGAN

SteganoGAN is a tool for creating steganographic images using adversarial training.
MIT License
304 stars 85 forks source link

i can't encode. #96

Open kompowiec opened 1 week ago

kompowiec commented 1 week ago

Description

steganogan encode -v in.png "Hello world" -o out.png

/home/kompowiec2/myenv/lib/python3.12/site-packages/torch/serialization.py:1113: SourceChangeWarning: source code of class 'torch.nn.modules.container.Sequential' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/kompowiec2/myenv/lib/python3.12/site-packages/torch/serialization.py:1113: SourceChangeWarning: source code of class 'torch.nn.modules.conv.Conv2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/kompowiec2/myenv/lib/python3.12/site-packages/torch/serialization.py:1113: SourceChangeWarning: source code of class 'torch.nn.modules.activation.LeakyReLU' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/kompowiec2/myenv/lib/python3.12/site-packages/torch/serialization.py:1113: SourceChangeWarning: source code of class 'torch.nn.modules.batchnorm.BatchNorm2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/kompowiec2/myenv/lib/python3.12/site-packages/torch/serialization.py:1113: SourceChangeWarning: source code of class 'steganogan.decoders.DenseDecoder' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/kompowiec2/myenv/lib/python3.12/site-packages/torch/serialization.py:1113: SourceChangeWarning: source code of class 'steganogan.critics.BasicCritic' has changed. you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) Traceback (most recent call last): File "/home/kompowiec2/myenv/bin/steganogan", line 8, in sys.exit(main()) ^^^^^^ File "/home/kompowiec2/myenv/lib/python3.12/site-packages/steganogan/cli.py", line 88, in main args.action(args) File "/home/kompowiec2/myenv/lib/python3.12/site-packages/steganogan/cli.py", line 25, in _encode steganogan = _get_steganogan(args) ^^^^^^^^^^^^^^^^^^^^^ File "/home/kompowiec2/myenv/lib/python3.12/site-packages/steganogan/cli.py", line 20, in _get_steganogan return SteganoGAN.load(steganogan_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kompowiec2/myenv/lib/python3.12/site-packages/steganogan/models.py", line 364, in load steganogan = torch.load(path, map_location='cpu', weights_only=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kompowiec2/myenv/lib/python3.12/site-packages/torch/serialization.py", line 1040, in load return _legacy_load(opened_file, map_location, pickle_module, pickle_load_args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kompowiec2/myenv/lib/python3.12/site-packages/torch/serialization.py", line 1272, in _legacy_load result = unpickler.load() ^^^^^^^^^^^^^^^^ File "/home/kompowiec2/myenv/lib/python3.12/site-packages/torch/optim/adam.py", line 66, in setstate super().setstate(state) File "/home/kompowiec2/myenv/lib/python3.12/site-packages/torch/optim/optimizer.py", line 313, in setstate self.defaults.setdefault('differentiable', False) ^^^^^^^^^^^^^ AttributeError: 'Adam' object has no attribute 'defaults'

What I Did

i modify steganogan/models.py:

steganogan = torch.load(path, map_location='cpu', weights_only=False)

ERROR: Could not find a version that satisfies the requirement torch==1.8.1 (from versions: 2.2.0, 2.2.1, 2.2.2, 2.3.0, 2.3.1, 2.4.0, 2.4.1, 2.5.0, 2.5.1)

[notice] A new release of pip is available: 24.2 -> 24.3.1 [notice] To update, run: pip install --upgrade pip ERROR: No matching distribution found for torch==1.8.1

  1. Traceback (most recent call last): File "/home/kompowiec2/myenv/bin/steganogan", line 8, in sys.exit(main()) ^^^^^^ File "/home/kompowiec2/myenv/lib/python3.12/site-packages/steganogan/cli.py", line 88, in main args.action(args) File "/home/kompowiec2/myenv/lib/python3.12/site-packages/steganogan/cli.py", line 25, in _encode steganogan = _get_steganogan(args) ^^^^^^^^^^^^^^^^^^^^^ File "/home/kompowiec2/myenv/lib/python3.12/site-packages/steganogan/cli.py", line 20, in _get_steganogan return SteganoGAN.load(**steganogan_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kompowiec2/myenv/lib/python3.12/site-packages/steganogan/models.py", line 364, in load steganogan = torch.load(path, map_location='cpu', weights_only=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kompowiec2/myenv/lib/python3.12/site-packages/torch/serialization.py", line 1383, in load raise pickle.UnpicklingError(_get_wo_message(str(e))) from None _pickle.UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint. (1) Re-running torch.load with weights_only set to False will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source. (2) Alternatively, to load with weights_only=True please check the recommended steps in the following error message. WeightsUnpickler error: Unsupported global: GLOBAL steganogan.models.SteganoGAN was not an allowed global by default. Please use torch.serialization.add_safe_globals([SteganoGAN]) to allowlist this global if you trust this class/function.

I don't know what else I can do. Model training works for me.

bbtx2024 commented 6 days ago

i ask gpt how to deal with it. gpt told me to use docker and i create a docker with python3.6 and encode successful. now i cant decode

image
kompowiec commented 5 days ago

I also used chatgpt but they just suggested weights_only=False)

and i create a docker with python3.6 and encode successful.

now it's makes sense. I had no idea what version of python it required. As for torch, I'll probably have to manually download it from another source.