欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

超分辨率重构之SRCNN整理总结(六)

程序员文章站 2023-12-30 19:04:40
...

tensorflow版本SRCNN的相关基础笔记

tensorflow 使用flags定义命令行参数:
        tf定义了tf.app.flags,用于支持接受命令行传递参数,相当于接受argv。eg:  tf.app.flags.DEFINE_string('str_name', 'def_v_1',"descrip1")#第一个是参数名称,第二个参数是默认值,第三个是参数描述
        在命令行中可以python3 test.py –str_name liu –int_name 10传参数来启动main()函数,在pycharm中可以通过run->edit configurations然后在script parameters中输入–str_name liu –int_name 10来输入参数

比如在项目中可以通过这样的方式控制传入参数:

flags = tf.app.flags
flags.DEFINE_integer("epoch", 15000, "Number of epoch [15000]")
flags.DEFINE_integer("batch_size", 128, "The size of batch images [128]")
flags.DEFINE_integer("image_size", 33, "The size of image to use [33]")
flags.DEFINE_integer("label_size", 21, "The size of label to produce [21]")
flags.DEFINE_float("learning_rate", 1e-4, "The learning rate of gradient descent algorithm [1e-4]")
flags.DEFINE_integer("c_dim", 1, "Dimension of image color. [1]")
flags.DEFINE_integer("scale", 3, "The size of scale factor for preprocessing input image [3]")
flags.DEFINE_integer("stride", 21, "The size of stride to apply input image [21]") 

flags.DEFINE_string("checkpoint_dir", "checkpoint", "Name of checkpoint directory [checkpoint]")
flags.DEFINE_string("sample_dir", "sample", "Name of sample directory [sample]")
# flags.DEFINE_boolean("is_train", True, "True for training, False for testing [True]")   #训练
flags.DEFINE_boolean("is_train", False, "True for training, False for testing [True]")  #测试
FLAGS = flags.FLAGS

PSNR值的计算Python代码

def psnr(target, ref, scale):
    # target:目标图像  ref:参考图像  scale:尺寸大小
    target_data = np.array(target)
    target_data = target_data[scale:-scale, scale:-scale]

    ref_data = np.array(ref)
    ref_data = ref_data[scale:-scale, scale:-scale]

    diff = ref_data - target_data
    diff = diff.flatten('C')
    rmse = math.sqrt(np.mean(diff ** 2.))
    MSE = np.mean(diff ** 2.)
    return 20 * math.log10(1.0 / rmse)

 

上一篇:

下一篇: