该部分的实现参考了pytorch官方repo中的SR例程,训练程序包含于./train
文件夹。该项目
基于高效子像素卷积层[1]进行空间分辨率提升操作,训练速度极快。
简单粗暴,异常直接
from __future__ import print_function
import torch
import numpy as np
import scipy.io as sio
for i in [2, 3, 4, 5, 6, 7, 8, 9, 10]:
model_name = 'model_upscale_{}_epoch_101.pth'.format(i)
model = torch.load(model_name)
print(model._modules)
weight = dict()
weight['conv1_w'] = model._modules['conv1']._parameters['weight'].data.cpu().numpy()
weight['conv2_w'] = model._modules['conv2']._parameters['weight'].data.cpu().numpy()
weight['conv3_w'] = model._modules['conv3']._parameters['weight'].data.cpu().numpy()
weight['conv4_w'] = model._modules['conv4']._parameters['weight'].data.cpu().numpy()
weight['conv1_b'] = model._modules['conv1']._parameters['bias'].data.cpu().numpy()
weight['conv2_b'] = model._modules['conv2']._parameters['bias'].data.cpu().numpy()
weight['conv3_b'] = model._modules['conv3']._parameters['bias'].data.cpu().numpy()
weight['conv4_b'] = model._modules['conv4']._parameters['bias'].data.cpu().numpy()
sio.savemat('model_upscale_{}.mat'.format(i), mdict=weight)
模型权值已保存为matlab权值,直接在matlab中运行demo.m
文件即可验证