实验——基于pytorch的超分和去噪网络联合fine tuning

本博文是本人实现超分和去噪网络联合训练与fine tuning的实验笔记

先基于之前博文《基于pytorch的噪声估计网络》处理的噪声图片,进行bicubic downsample的操作(应该先bicubic再加噪)

进入对应子目录下,运行

$  matlab -nodesktop -nosplash -r matlabfile

python train.py -opt options/train/train_sub_sr.json

首先生成subnetwork板块(在networks.py)

#########################################################################################################################
def define_sub(opt):
    gpu_ids = opt['gpu_ids']
    opt_net = opt['network_sub']
    which_model = opt_net['which_model_sub']

    if which_model == 'noise_estimation':
        subnet = arch.NENET(in_nc=opt_net['in_nc'], out_nc=opt_net['out_nc'], nf=opt_net['nf'], nb=opt_net['nb'],
                                norm_type=opt_net['norm_type'], mode=opt_net['mode'])
    else:
        raise NotImplementedError('subnet model [{:s}] not recognized'.format(which_model))

    if gpu_ids:
        assert torch.cuda.is_available()
        subnet = nn.DataParallel(subnet)
    return subnet
############################################################################################################################

对于setting,也就是.jason文件,如下

{
  "name": "debug_finetune_srresnet_dncnn_DIVIK800" //  please remove "debug_" during training
  , "tb_logger_dir": "sr_c16s06"
  , "use_tb_logger": true
  , "model":"sr_sub"///this is important
  , "scale": 4
  , "crop_scale": 4
  , "gpu_ids": [3,5]
//  , "init_type": "kaiming"
//
  , "finetune_type": "sft" //sft | basic
//  , "init_norm_type": "zero"

  , "datasets": {
    "train": {
      "name": "DIV2K800"
//      , "mode": "LQHQ"
//      , "dataroot_HR": "/media/sdc/jwhe/BasicSR_v2/data/DIV2K/DIV2K800_sub"
//      , "dataroot_HQ": "/media/sdc/jwhe/BasicSR_v2/data/DIV2K/DIV2K800_sub_Gaussian15"
//      , "dataroot_LQ": "/media/sdc/jwhe/BasicSR_v2/data/DIV2K/DIV2K800_sub_Gaussian50"
      , "mode": "LRHR"
      , "dataroot_HR": "/home/guanwp/BasicSR_datasets/DIV2K800_sub"
      , "dataroot_LR": "/home/guanwp/BasicSR_datasets/DIV2K800_sub_bicLRx4_noiseALL"
      , "subset_file": null
      , "use_shuffle": true
      , "n_workers": 8
      , "batch_size": 24 // 16
      , "HR_size": 128 // 128 | 192 | 96
//      , "noise_gt": true
      , "use_flip": true
      , "use_rot": true
    }
//
//    , "val": {
//      "name": "val_CBSD68_Gaussian50",
//      "mode": "LRHR",
//      "dataroot_HR": "/home/jwhe/workspace/BasicSR_v3/data/CBSD68/mod2/CBSD68_mod",
//      "dataroot_LR": "/home/jwhe/workspace/BasicSR_v3/data/CBSD68/mod2/CBSD68_Gaussian50"
      , "noise_gt": true
//    }
//   , "val": {
//      "name": "val_CBSD68_s08_c03",
//      "mode": "LRHR",
//      "dataroot_HR": "/home/jwhe/workspace/BasicSR_v3/data/CBSD68/mod2/CBSD68_mod",
//      "dataroot_LR": "/home/jwhe/workspace/BasicSR_v3/data/CBSD68/mod2/CBSD68_s08_c03"
//      , "noise_gt": true
//    }

//  , "val": {
//      "name": "val_CBSD68_clean",
//      "mode": "LRHR",
//      "dataroot_HR": "/media/sdc/jwhe/BasicSR_v2/data/CBSD68/mod2/CBSD68_mod",
//      "dataroot_LR": "/media/sdc/jwhe/BasicSR_v2/data/CBSD68/mod2/CBSD68_mod"
//    }

//    , "val": {
//      "name": "val_LIVE1_gray_JEPG10",
//      "mode": "LRHR",
//      "dataroot_HR": "/media/hjw/jwhe/BasicSR_v2/data/val/LIVE1_val/LIVE1_gray_mod",
//      "dataroot_LR": "/media/hjw/jwhe/BasicSR_v2/data/val/LIVE1_val/LIVE1_gray_jpg10"
//    }

//      , "val": {
//      "name": "val_LIVE1_JEPG80",
//      "mode": "LRHR",
//      "dataroot_HR": "/media/hjw/jwhe/BasicSR_v2/data/val/LIVE1_val/LIVE1_mod",
//      "dataroot_LR": "/media/hjw/jwhe/BasicSR_v2/data/val/LIVE1_val/LIVE1_jpg80"
//    }

//    , "val_2": {
//      "name": "val_Classic5_gray_JEPG30",
//      "mode": "LRHR",
//      "dataroot_HR": "/media/sdc/jwhe/BasicSR_v2/data/val/Classic5_val/classic5_mod",
//      "dataroot_LR": "/media/sdc/jwhe/BasicSR_v2/data/val/Classic5_val/classic5_jpg30"
//    }

//    , "val": {
//      "name": "val_BSD68_gray_Gaussian50",
//      "mode": "LRHR",
//      "dataroot_HR": "/media/sdc/jwhe/BasicSR_v2/data/BSD68/mod2/BSD68_mod",
//      "dataroot_LR": "/media/sdc/jwhe/BasicSR_v2/data/BSD68/mod2/BSD68_gray_Gaussian50"
//    }

//    , "val": {
//      "name": "val_set5_x4_gray_mod4"
//      , "mode": "LRHR"
//      , "dataroot_HR": "/media/sdc/jwhe/BasicSR_v2/data/val/Set5_val/mod4/Set5_gray_mod4"
//      , "dataroot_LR": "/media/sdc/jwhe/BasicSR_v2/data/val/Set5_val/mod4/Set5_gray_bicx4"
//    }
//
//    , "val": {
//      "name": "val_set5_x45_mod18",
//      "mode": "LRHR",
//      "dataroot_HR": "/media/sdc/jwhe/BasicSR_v2/data/val/Set5_val/mod18/Set5_mod18",
//      "dataroot_LR": "/media/sdc/jwhe/BasicSR_v2/data/val/Set5_val/mod18/Set5_bicx45"
//    }

//    , "val": {
//      "name": "val_set5_x3_mod6"
//      , "mode": "LRHR"
//      , "dataroot_HR": "/media/sdc/jwhe/BasicSR_v2/data/val/Set5_val/mod6/Set5_mod6"
//      , "dataroot_LR": "/media/sdc/jwhe/BasicSR_v2/data/val/Set5_val/mod6/Set5_bicx3"
//    }
//  }
  , "val": {
      "name": "SET5",
      "mode": "LRHR",
      "dataroot_HR": "/home/guanwp/BasicSR_datasets/val_set5/Set5",
      "dataroot_LR": "/home/guanwp/BasicSR_datasets/val_set5/Set5_sub_bicLRx4_noiseALL"
    }
//
//    , "val": {
//      "name": "val_set5_x3_gray_mod6"
//      , "mode": "LRHR"
//      , "dataroot_HR": "/media/sdc/jwhe/BasicSR_v2/data/val/Set5_val/mod6/Set5_gray_mod6"
//      , "dataroot_LR": "/media/sdc/jwhe/BasicSR_v2/data/val/Set5_val/mod6/Set5_gray_bicx3"
//    }
  }

  , "path": {
    "root": "/home/guanwp/BasicSR-master/"
//  , "pretrain_model_G": "../experiments/pretrained_models/sr_c16s06/LR_srx4_c16s06_resnet_denoise_DIV2K/c16s06_basicmodel_704000.pth"
  , "pretrain_model_G": "/home/guanwp/BasicSR-master/experiments2/sr_resnet_x4_baesline/models/latest_G.pth"
//  , "pretrain_model_G": "../experiments/pretrained_models/noise_c16s06/bicx4_nonorm_denoise_resnet_DIV2K/c16s06_basicmodel_992000.pth"
//  , "pretrain_model_G": "../experiments/pretrained_models/sr_c16s06/LR_srx4_c16s06_resnet_denoise_DIV2K/c16s06_basicmodel_704000.pth"
//    , "pretrain_model_G": "../noise_from15to75/experiments/gaussian_from15to75_resnet_denoise_DIV2K/models/986000_G.pth"
//    , "pretrain_model_G": "../experiments/pretrained_models/noise_from15to75/gaussian_from15to75_resnet_denoise_DIV2K/basic_model_986000.pth"
//    , "pretrain_model_sub": "../noise_from15to75/experiments/gaussion_from15to75_subnet_DIV2K/models/596000_G.pth"
  , "pretrain_model_sub": "/home/guanwp/BasicSR-master/experiments/noise_estimation_gt_1e-3/models/203000_G.pth",
    "experiments_root": "/home/guanwp/BasicSR-master/experiments/",
    "models": "/home/guanwp/BasicSR-master/experiments/finetune_srresnet_dncnn_DIVIK800/models",
    "log": "/home/guanwp/BasicSR-master/experiments/finetune_srresnet_dncnn_DIVIK800",
    "val_images": "/home/guanwp/BasicSR-master/experiments/finetune_srresnet_dncnn_DIVIK800/val_images"
    }

  , "network_G": {
    "which_model_G": "sr_resnet" // RRDB_net | sr_resnet
//    , "norm_type": "adaptive_conv_res"
    , "norm_type": null//"sft"
    , "mode": "CNA"
    , "nf": 64
    , "nb": 16
    , "in_nc": 3
    , "out_nc": 3
//    , "gc": 32
    , "group": 1
    , "gate_conv_bias": false
  }

//    , "network_G": {
//    "which_model_G": "denoise_resnet" // RRDB_net | sr_resnet
    , "norm_type": "adaptive_conv_res"
//    , "norm_type": null
//    , "mode": "CNA"
//    , "nf": 64
//    , "nb": 16
//    , "in_nc": 6
//    , "out_nc": 3
    , "gc": 32
//    , "group": 1
//    , "down_scale": 2
//  }

  , "network_sub": {
    "which_model_sub": "noise_estimation" // RRDB_net | sr_resnet | modulate_denoise_resnet |noise_subnet
//    , "norm_type": "adaptive_conv_res"
    , "norm_type": null//"batch"
    , "mode": "CNA"
    , "nf": 64
//    , "nb": 16
    , "in_nc": 3
    , "out_nc": 3
    , "group": 1
  }


  , "train": {
//    "lr_G": 1e-3
    "lr_G": 1e-4
    , "lr_scheme": "MultiStepLR"
//    , "lr_steps": [200000, 400000, 600000, 800000]
    , "lr_steps": [500000]
//    , "lr_steps": [600000]
//    , "lr_steps": [1000000]
//    , "lr_steps": [50000, 100000, 150000, 200000, 250000]
//    , "lr_steps": [100000, 200000, 300000, 400000]
    , "lr_gamma": 0.2
//    , "lr_gamma": 0.5

    , "pixel_criterion_basic": "l1"
    , "pixel_criterion_noise": "l2"
    , "pixel_weight_basic": 1.0
    , "pixel_weight_noise": 1.0
    , "val_freq": 1e3

    , "manual_seed": 0
    , "niter": 1e6
//    , "niter": 6e5
  }

  , "logger": {
    "print_freq": 200
    , "save_checkpoint_freq": 1e3
  }
}

结果如下图所示

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值