MambaIR 代码复现

paper:arxiv.org/pdf/2402.15648

GitHub:csguoh/MambaIR: [ECCV2024] MambaIR 和 MambaIRv2!

MambaIR 论文解析:《MambaIR:一种基于状态空间模型的简单图像修复基线方法》学习笔记-CSDN博客 

一、环境配置

1.1 激活conda 环境

Autodl目前遇到的相关问题及其解决方案_autodl启动visdom-CSDN博客

1.2  配置环境

cd ./MambaIR
conda env create -f environment.yaml

1、报错:

Preparing metadata (setup.py): started                                                                                                                                                                                      
  Preparing metadata (setup.py): finished with status 'error'                                                                                                                                                                 
                                                                                                                                                                                                                              
Pip subprocess error:                                                                                                                                                                                                         
  error: subprocess-exited-with-error                                                                                                                                                                                         
                                                                                                                                                                                                                              
  × python setup.py egg_info did not run successfully.                                                                                                                                                                        
  │ exit code: 1                                                                                                                                                                                                              
  ╰─> [6 lines of output]                                                                                                                                                                                                     
      Traceback (most recent call last):                                                                                                                                                                                      
        File "<string>", line 2, in <module>                                                                                                                                                                                  
        File "<pip-setuptools-caller>", line 34, in <module>                                                                                                                                                                  
        File "/tmp/pip-install-6iyr0w5j/causal-conv1d_edb242b70176433eb8df95c01b7c96d9/setup.py", line 8, in <module>                                                                                                         
          from packaging.version import parse, Version                                                                                                                                                                        
      ModuleNotFoundError: No module named 'packaging'                                                                                                                                                                        
      [end of output]                                                                                                                                                                                                         
                                                                                                                                                                                                                              
  note: This error originates from a subprocess, and is likely not a problem with pip.                                                                                                                                        
error: metadata-generation-failed                                                                                                                                                                                             
                                                                                                                                                                                                                              
× Encountered error while generating package metadata.                                                                                                                                                                        
╰─> See above for output.                                                                                                                                                                                                     
                                                                                                                                                                                                                              
note: This is an issue with the package mentioned above, not pip.                                                                                                                                                             
hint: See above for details.                                                                                                                                                                                                  
                                                                                                                                                                                                                              
failed                                                                                                                                                                                                                        
                                                                                                                                                                                                                              
CondaEnvException: Pip failed                                   

解决方案: 

复制下面内容替换 requirements.txt,之后执行

conda activate mambair
pip install -r requirements.txt
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64
absl-py==2.1.0
addict==2.4.0
cachetools==5.3.2
causal-conv1d==1.0.0
certifi==2023.11.17
cffi==1.16.0
charset-normalizer==2.0.4
cmake==3.28.1
contourpy==1.1.1
cryptography==41.0.7
cycler==0.12.1
einops==0.7.0
ffmpeg==1.4
filelock==3.13.1
fonttools==4.47.2
fsspec==2023.12.2
future==0.18.3
giflib==5.2.1
gmp==6.2.1
gmpy2==2.1.2
gnutls==3.6.15
google-auth==2.27.0
google-auth-oauthlib==1.0.0
grpcio==1.60.0
h5py==3.10.0
huggingface-hub==0.20.3
idna==3.4
imageio==2.33.1
importlib-metadata==7.0.1
importlib-resources==6.1.1
jinja2==3.1.2
kiwisolver==1.4.5
lame==3.100
lazy-loader==0.3
lcms2==2.12
lerc==3.0
lit==17.0.6
lmdb==1.4.1
markdown==3.5.2
markupsafe==2.1.3
matplotlib==3.7.4
mkl-service==2.4.0
mkl_fft==1.3.8
mkl_random==1.2.4
mpc==1.1.0
mpfr==4.0.2
mpmath==1.3.0
ncurses==6.4
nettle==3.7.3
networkx==3.1
ninja==1.11.1.1
numpy==1.24.3
oauthlib==3.2.2
opencv-python==4.9.0.80
openh264==2.1.1
openjpeg==2.4.0
openssl==3.0.12
packaging==23.2
pillow==10.0.1
pip==23.3.1
platformdirs==4.1.0
protobuf==4.25.2
pyasn1==0.5.1
pyasn1-modules==0.3.0
pycparser==2.21
pyopenssl==23.2.0
pyparsing==3.1.1
pysocks==1.7.1
python==3.8.18
python-dateutil==2.8.2
pytorch==2.0.1
pytorch-cuda==11.7
pytorch-mutex==1.0
pywavelets==1.4.1
pyyaml==6.0.1
readline==8.2
regex==2023.12.25
requests==2.31.0
requests-oauthlib==1.3.1
rsa==4.9
safetensors==0.4.2
scikit-image==0.21.0
scipy==1.10.1
setuptools==68.2.2
six==1.16.0
sqlite==3.41.2
sympy==1.12
tb-nightly==2.14.0a20230808
tbb==2021.8.0
tensorboard-data-server==0.7.2
tifffile==2023.7.10
timm==0.9.12
tk==8.6.12
tokenizers==0.15.1
tomli==2.0.1
torchaudio==2.0.2
torchtriton==2.0.0
torchvision==0.15.2
tqdm==4.66.1
transformers==4.37.1
typing_extensions==4.9.0
urllib3==1.26.18
werkzeug==3.0.1
wheel==0.41.2
xz==5.4.5
yapf==0.40.2
zipp==3.17.0
zlib==1.2.13
zstd==1.5.5

1.3 mamba_ssm 下载 

运行代码显示缺少 mamba_ssm :

Traceback (most recent call last):
  File "basicsr/test.py", line 17, in <module>
    from basicsr.data import build_dataloader, build_dataset  # 数据加载相关函数
  File "/root/autodl-tmp/MambaIR-main/basicsr/__init__.py", line 1, in <module>
    from .archs import *
  File "/root/autodl-tmp/MambaIR-main/basicsr/archs/__init__.py", line 16, in <module>
    _arch_modules = [importlib.import_module(f'basicsr.archs.{file_name}') for file_name in arch_filenames]
  File "/root/autodl-tmp/MambaIR-main/basicsr/archs/__init__.py", line 16, in <listcomp>
    _arch_modules = [importlib.import_module(f'basicsr.archs.{file_name}') for file_name in arch_filenames]
  File "/root/miniconda3/envs/mambair/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/root/autodl-tmp/MambaIR-main/basicsr/archs/mambair_arch.py", line 11, in <module>
    from mamba_ssm.ops.selective_scan_interface import selective_scan_fn, selective_scan_ref
ModuleNotFoundError: No module named 'mamba_ssm'

使用命令:

pip install mamba_ssm

网络连接问题,显示:

error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [8 lines of output]
      
      
      torch.__version__  = 2.0.1
      
      
      running bdist_wheel
      Guessing wheel URL:  https://github.com/state-spaces/mamba/releases/download/v2.2.2/mamba_ssm-2.2.2+cu118torch2.0cxx11abiFALSE-cp38-cp38-linux_x86_64.whl
      error: <urlopen error [Errno 110] Connection timed out>
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mamba_ssm
  Running setup.py clean for mamba_ssm
Failed to build mamba_ssm
ERROR: Could not build wheels for mamba_ssm, which is required to install pyproject.toml-based projects

 手动点击 Guessing wheel URL 链接下载:

 https://github.com/state-spaces/mamba/releases/download/v2.2.2/mamba_ssm-2.2.2+cu118torch2.0cxx11abiFALSE-cp38-cp38-linux_x86_64.whl

 手动安装

pip install mamba_ssm-2.2.2+cu118torch2.0cxx11abiFALSE-cp38-cp38-linux_x86_64.whl

二、文件

2.1 basicsr 

存放 train 和 test 的代码

2.2 datasets 

用来存放数据集的位置。

2.3 experiments/pretrained_models

存放模型的位置。

三、推理

本次仅使用 MambaIR_guassian15 模型

首先,修改模型对应的 yml 文件,yml 文件路径如下

MambaIR-main/options/test/mambair

修改 .yml 文件内的数据集路径

  test_1:
    task: denoising_color  # 任务类型:彩色图像去噪
    name: CBSD68  # 数据集的名称
    type: PairedImageDataset  # 数据集类型,表示使用成对的图像(低质量和高质量)
    dataroot_gt: /root/autodl-tmp/MambaIR-main/datasets/ColorDN/CBSD68HQ  # 高质量图像的存储路径
    dataroot_lq: /root/autodl-tmp/MambaIR-main/datasets/ColorDN/CBSD68HQ  # 低质量图像的存储路径
    filename_tmpl: '{}'  # 文件名模板,用于加载图像文件
    noise: 15  # 图像的噪声水平,15、25、50等
    io_backend:
      type: disk  # 数据存储方式:从硬盘读取数据

在终端输入命令:

python basicsr/test.py -opt options/test/mambair/test_MambaIR_ColorDN_level15.yml

 测试成功:

2025-02-03 22:29:32,451 INFO: Validation CBSD68
         # psnr: 34.4823        Best: 34.4823 @ test_MambaIR_ColorDN_level15 iter
         # ssim: 0.9362 Best: 0.9362 @ test_MambaIR_ColorDN_level15 iter

2025-02-03 22:29:32,451 INFO: Testing Kodak24...
2025-02-03 22:30:29,313 INFO: Validation Kodak24
         # psnr: 35.4232        Best: 35.4232 @ test_MambaIR_ColorDN_level15 iter
         # ssim: 0.9309 Best: 0.9309 @ test_MambaIR_ColorDN_level15 iter

2025-02-03 22:30:29,317 INFO: Testing McMaster...
2025-02-03 22:31:11,530 INFO: Validation McMaster
         # psnr: 35.6990        Best: 35.6990 @ test_MambaIR_ColorDN_level15 iter
         # ssim: 0.9355 Best: 0.9355 @ test_MambaIR_ColorDN_level15 iter

2025-02-03 22:31:11,534 INFO: Testing Urban100...
2025-02-03 22:44:21,444 INFO: Validation Urban100
         # psnr: 35.3711        Best: 35.3711 @ test_MambaIR_ColorDN_level15 iter
         # ssim: 0.9537 Best: 0.9537 @ test_MambaIR_ColorDN_level15 iter

效果展示:

 

四、训练

运行命令

python basicsr/train.py -opt options/train/mambair/train_MambaIR_ColorDN_level15.yml

开始迭代:

04-03
### Mamba Air IT Technology 查询 Mamba 和 Air 是两个常见的术语,在不同的上下文中可以指代多种技术和产品。以下是关于这两个关键词的一些解释: #### 关于 Mamba 的技术含义 在 IT 领域,“Mamba” 可能指的是以下几种情况之一: 1. **Anaconda Distribution 中的工具** Mamba 是 Anaconda 发布的一个快速替代品,用于管理 Python 软件包和环境[^3]。它是一个命令行工具,旨在加速 Conda 的依赖解析过程并提高性能。 示例安装代码如下所示: ```bash conda install mamba -c conda-forge ``` 2. **网络安全领域中的工具或框架** 在某些情况下,“Mamba” 还可能被用作一种网络扫描器或者渗透测试工具的名字。 #### 关于 Air 的技术含义 “AIR” 或 “air” 在 IT 技术中有多个潜在意义: 1. **Apple 设备生态系统** Apple 使用 AIR 命名其许多无线连接功能的产品线,例如 AirPods、AirDrop 和 AirPlay 等[^4]。 2. **Adobe AIR 平台** Adobe Integrated Runtime (AIR) 是由 Adobe 开发的一种跨平台运行时环境,允许开发者创建桌面应用程序,并支持 HTML、JavaScript、Flash 和 ActionScript 编程语言[^5]。 3. **云计算概念** 在一些云服务提供商的技术文档中,“Air” 也可能代表轻量级的服务模式或者是特定类型的虚拟化解决方案的一部分。 #### 结合两者的情况分析 如果提到的是“Mamba Air”,这可能是某种组合名称,具体取决于实际应用场景。比如某个基于 Mamba 工具链优化后的云端部署方案称为“Mamba Air”。然而目前并没有广泛认可的标准定义来确切描述这样一个复合词组所特指的内容。 ```python import mamba.core.runtime as runtime runtime.init() print("Mamba environment initialized.") ```
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值