本文共 2114 字,大约阅读时间需要 7 分钟。
首先,确保你的开发环境已经准备好。以下是需要安装的软件和依赖:
安装conda环境
conda create -n vmambair python=3.9conda activate vmambair
安装PyTorch和相关库
pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu121
克隆并安装项目
cd kernels/selective_scanpip install .
接着进入Deraining
目录,运行以下命令安装依赖:
cd Derainingpip install timm fvcore
创建训练配置文件
根据项目需求,创建Deraining.yml
文件。以下是示例配置内容: # 项目名称或配置名称name: Deraining_Restormer# 模型类型model_type: ImageCleanModel# 缩放比例(通常用于超分辨率任务,这里是1,表示不缩放)scale: 1# 训练时使用的GPU数量,设置为0表示CPU模式num_gpu: 1# 随机种子,用于保证实验的可复现性manual_seed: 100# 数据集类型type: Dataset_PairedImage# 高质量(Ground Truth)图像的路径dataroot_gt: /root/autodl-tmp/VmambaIR-main/Deraining/Dataset/train/B# 低质量(输入)图像的路径dataroot_lq: /root/autodl-tmp/VmambaIR-main/Deraining/Dataset/train/A# 是否开启几何增强(如旋转、翻转等)geometric_augs: true# 文件名模板,用于匹配图像文件名filename_tmpl: '{}'# 输入输出后端类型,这里是磁盘存储io_backend: type: disk# 数据 loader 设置use_shuffle: truenum_worker_per_gpu: 4batch_size_per_gpu: 2# 渐进式训练设置mini_batch_sizes: [8,5,4,2,1,1]iters: [92000,64000,48000,36000,36000,24000]gt_size: 384gt_sizes: [128,160,192,256,320,384]# 训练设置total_iter: 300warmup_iter: -1use_grad_clip: true# 学习率调度器类型scheduler: type: CosineAnnealingRestartCyclicLRperiods: [92000, 208000]restart_weights: [1,1]eta_mins: [0.0003,0.000001]# 数据增强设置mixing_augs: mixup: falsemixup_beta: 1.2use_identity: true# 优化器设置optim_g: type: AdamWlr: !!float 3e-4weight_decay: !!float 1e-4betas: [0.9, 0.999]# 损失函数设置pixel_opt: type: L1Lossloss_weight: 1reduction: mean# 验证设置val: window_size: 8val_freq: !!float 4e3save_img: falsergb2bgr: trueuse_image: truemax_minibatch: 8metrics: psnr: type: calculate_psnrtest_y_channel: true# 日志设置logger: print_freq: 1000save_checkpoint_freq: !!float 4e3use_tb_logger: true# 排队训练设置dist_params: backend: ncclport: 29500
启动训练命令
python basicsr/train.py -opt /root/autodl-tmp/VmambaIR-main/Deraining/Options/Deraining.yml
单次测试
python test.py
批量测试
如果需要进行批量测试,请参考项目文档中的test.sh
脚本,并根据实际需求调整参数。 通过以上步骤,你可以成功配置并运行Deraining项目的训练和测试流程。如果在配置过程中遇到问题,请参考项目文档或社区获取进一步帮助。
转载地址:http://douyz.baihongyu.com/