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

Using grayscale images with the preparing model #169

Open
clodiamery opened this issue Dec 22, 2024 · 0 comments
Open

Using grayscale images with the preparing model #169

clodiamery opened this issue Dec 22, 2024 · 0 comments

Comments

@clodiamery
Copy link

clodiamery commented Dec 22, 2024

Hello,
I need to use this preparing model "006_CAR_DFWB_s126w7_SwinIR-M_jpeg10.pth" to enhance the image quality, I update on the code in the Collab to be like this:

# BSRGAN
!rm -r results
if not test_patch_wise:
  %cd BSRGAN
  !python main_test_bsrgan.py
  %cd ..
  shutil.move('BSRGAN/testsets/RealSRSet_results_x4', 'results/BSRGAN')

# realESRGAN
if test_patch_wise:
  !python inference_realesrgan.py -n RealESRGAN_x4plus --input BSRGAN/testsets/RealSRSet -s 4 --output results/realESRGAN --tile 800
else:
  !python inference_realesrgan.py -n RealESRGAN_x4plus --input BSRGAN/testsets/RealSRSet -s 4 --output results/realESRGAN

# SwinIR
if test_patch_wise:
 # !python SwinIR/main_test_swinir.py --task real_sr --model_path experiments/pretrained_models/003_realSR_BSRGAN_DFO_s64w8_SwinIR-M_x4_GAN.pth --folder_lq BSRGAN/testsets/RealSRSet --scale 4 --tile 800
 !python SwinIR/main_test_swinir.py --task jpeg_car --jpeg 10 --model_path /content/Real-ESRGAN/experiments/pretrained_models/006_CAR_DFWB_s126w7_SwinIR-M_jpeg10.pth --folder_lq BSRGAN/testsets/RealSRSet --scale 4 --tile 800
else:
 # !python SwinIR/main_test_swinir.py --task real_sr --model_path experiments/pretrained_models/003_realSR_BSRGAN_DFO_s64w8_SwinIR-M_x4_GAN.pth --folder_lq BSRGAN/testsets/RealSRSet --scale 4
 !python SwinIR/main_test_swinir.py --task jpeg_car --jpeg 10 --model_path /content/Real-ESRGAN/experiments/pretrained_models/006_CAR_DFWB_s126w7_SwinIR-M_jpeg10.pth --folder_lq BSRGAN/testsets/RealSRSet --scale 4
shutil.move('results/swinir_jpeg_car_jpeg10', 'results/SwinIR')

# SwinIR-Large
if test_patch_wise:
  !python SwinIR/main_test_swinir.py --task jpeg_car --jpeg 20 --model_path /content/Real-ESRGAN/experiments/pretrained_models/006_CAR_DFWB_s126w7_SwinIR-M_jpeg20.pth --folder_lq BSRGAN/testsets/RealSRSet --scale 4 --large_model --tile 640
else:
  !python SwinIR/main_test_swinir.py --task jpeg_car --jpeg 20 --model_path /content/Real-ESRGAN/experiments/pretrained_models/006_CAR_DFWB_s126w7_SwinIR-M_jpeg20.pth --folder_lq BSRGAN/testsets/RealSRSet --scale 4 --large_model
shutil.move('results/swinir_jpeg_car_jpeg20', 'results/SwinIR_large')

for path in sorted(glob.glob(os.path.join('results/SwinIR_large', '*.png'))):
  os.rename(path, path.replace('SwinIR.png', 'SwinIR_large.png')) # here is a bug in Colab file downloading: no same-name files

But I have this error, any advice please?

/content/Real-ESRGAN/Real-ESRGAN/BSRGAN
LogHandlers setup!
24-12-21 22:50:56.006 :       Model Name : BSRGAN
24-12-21 22:50:56.023 :           GPU ID : 0
[3, 3, 64, 23, 32, 4]
/content/Real-ESRGAN/Real-ESRGAN/BSRGAN/main_test_bsrgan.py:77: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  model.load_state_dict(torch.load(model_path), strict=True)
24-12-21 22:50:56.598 :       Input Path : testsets/RealSRSet
24-12-21 22:50:56.598 :      Output Path : testsets/RealSRSet_results_x4
24-12-21 22:50:56.598 : ---1 --> BSRGAN --> x4--> img_004x2.png
/content/Real-ESRGAN/Real-ESRGAN
Traceback (most recent call last):
  File "/content/Real-ESRGAN/Real-ESRGAN/inference_realesrgan.py", line 5, in <module>
    from basicsr.archs.rrdbnet_arch import RRDBNet
  File "/usr/local/lib/python3.10/dist-packages/basicsr/__init__.py", line 4, in <module>
    from .data import *
  File "/usr/local/lib/python3.10/dist-packages/basicsr/data/__init__.py", line 22, in <module>
    _dataset_modules = [importlib.import_module(f'basicsr.data.{file_name}') for file_name in dataset_filenames]
  File "/usr/local/lib/python3.10/dist-packages/basicsr/data/__init__.py", line 22, in <listcomp>
    _dataset_modules = [importlib.import_module(f'basicsr.data.{file_name}') for file_name in dataset_filenames]
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/local/lib/python3.10/dist-packages/basicsr/data/realesrgan_dataset.py", line 11, in <module>
    from basicsr.data.degradations import circular_lowpass_kernel, random_mixed_kernels
  File "/usr/local/lib/python3.10/dist-packages/basicsr/data/degradations.py", line 8, in <module>
    from torchvision.transforms.functional_tensor import rgb_to_grayscale
ModuleNotFoundError: No module named 'torchvision.transforms.functional_tensor'
/usr/local/lib/python3.10/dist-packages/timm/models/layers/__init__.py:48: FutureWarning: Importing from timm.models.layers is deprecated, please import via timm.layers
  warnings.warn(f"Importing from {__name__} is deprecated, please import via timm.layers", FutureWarning)
loading model from /content/Real-ESRGAN/experiments/pretrained_models/006_CAR_DFWB_s126w7_SwinIR-M_jpeg10.pth
/usr/local/lib/python3.10/dist-packages/torch/functional.py:534: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3595.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
/content/Real-ESRGAN/Real-ESRGAN/SwinIR/main_test_swinir.py:189: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  pretrained_model = torch.load(args.model_path)
Traceback (most recent call last):
  File "/content/Real-ESRGAN/Real-ESRGAN/SwinIR/main_test_swinir.py", line 309, in <module>
    main()
  File "/content/Real-ESRGAN/Real-ESRGAN/SwinIR/main_test_swinir.py", line 60, in main
    for idx, path in enumerate(sorted(glob.glob(os.path.join(folder, '*')))):
  File "/usr/lib/python3.10/posixpath.py", line 76, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType
/usr/local/lib/python3.10/dist-packages/timm/models/layers/__init__.py:48: FutureWarning: Importing from timm.models.layers is deprecated, please import via timm.layers
  warnings.warn(f"Importing from {__name__} is deprecated, please import via timm.layers", FutureWarning)
loading model from /content/Real-ESRGAN/experiments/pretrained_models/006_CAR_DFWB_s126w7_SwinIR-M_jpeg20.pth
/usr/local/lib/python3.10/dist-packages/torch/functional.py:534: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3595.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
/content/Real-ESRGAN/Real-ESRGAN/SwinIR/main_test_swinir.py:189: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  pretrained_model = torch.load(args.model_path)
Traceback (most recent call last):
  File "/content/Real-ESRGAN/Real-ESRGAN/SwinIR/main_test_swinir.py", line 309, in <module>
    main()
  File "/content/Real-ESRGAN/Real-ESRGAN/SwinIR/main_test_swinir.py", line 60, in main
    for idx, path in enumerate(sorted(glob.glob(os.path.join(folder, '*')))):
  File "/usr/lib/python3.10/posixpath.py", line 76, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType
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

1 participant