-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
%% ³õʼ»¯ | ||
|
||
clc; | ||
clear; | ||
addpath('./src') | ||
|
||
%% ÔØÈë²âÊÔͼÏñ | ||
|
||
im = imread('./img/100080.jpg'); | ||
im = im(201:340, 101:240, 1); | ||
[H, W, ~] = size(im); | ||
input = reshape(im, 1, 1, H, W); | ||
|
||
%% run | ||
|
||
tic | ||
upscale_factor = 5; | ||
model_name = ['./model/model_upscale_', num2str(upscale_factor),'.mat']; | ||
im_sr = SR_model(input, model_name); | ||
size(im_sr) | ||
toc | ||
%% ÏÔʾ | ||
|
||
figure | ||
[~,~,h_sr, w_sr] = size(im_sr); | ||
imshow(reshape(im_sr, h_sr, w_sr), []) | ||
figure | ||
[~,~,h, w] = size(input); | ||
imshow(reshape(input, h, w), []) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
function [ outputs ] = PixelShuffle( inputs, upscale_factor ) | ||
% PixelShuffle : | ||
% | ||
% input : N, upscale_factor ** 2, H, W | ||
% output : N, 1, H*upscale_factor, W*upscale_factor | ||
|
||
[N, ~, H, W] = size(inputs); | ||
H_out = H*upscale_factor; | ||
W_out = W*upscale_factor; | ||
outputs = zeros([N, 1, H_out, W_out]); | ||
for i = 1:N | ||
for h = 1: H_out | ||
for w = 1:W_out | ||
height_idx = floor(h / upscale_factor+0.5); | ||
weight_idx = floor(w / upscale_factor+0.5); | ||
channel_idx = (upscale_factor * mod(h-1, upscale_factor)) + mod(w-1, upscale_factor)+1; | ||
outputs(i, 1, h, w) = inputs(i, channel_idx, height_idx, weight_idx); | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
function [ image_sr ] = SR_model( image, model_name) | ||
%{ | ||
一、函数概述 | ||
SR_model, 该函数以单波段图像作为输入,使用卷积神经网络做超分辨处理,输 | ||
出超分辨后的图像。不同的超分辨因子对应不同的预训练模型,超分辨因子可指定 | ||
2-10中的任意整数,指定超分辨因子时,手动指定不同的权重即可。权重命名具有一 | ||
定规律,如 model_upscale_7.mat,表示超分辨因子为7时对应的模型。 | ||
该函数使用高效的子像素卷积层进行图像超分辨[1], 在GPU加速条件下能够实现 | ||
720P视频实时超分辨,相比于之前的深度学习模型,推理速度得到了极大提高。 | ||
二、参数说明: | ||
image :4维数组,(N, 1, H, W),N 为图像数量 | ||
model : 预训练的权值 | ||
image_sr :4维数组,超分辨后的图像序列, | ||
尺寸为:(N, 1, H * upscale_factor, W * upscale_factor) | ||
其中 N 为图像数量 | ||
三、参考文献: | ||
[1] Shi W, Caballero J, Huszar F, et al. Real-Time Single Image and | ||
Video Super-Resolution Using an Efficient Sub-Pixel Convolutional | ||
Neural Network[J]. 2016:1874-1883. | ||
%} | ||
|
||
load(model_name) | ||
out1 = conv_func(image, conv1_w); | ||
out1 = relu(out1 + conv1_b); | ||
|
||
out2 = conv_func(out1, conv2_w); | ||
out2 = relu(out2 + conv2_b); | ||
|
||
out3 = conv_func(out2, conv3_w); | ||
out3 = relu(out3 + conv3_b); | ||
|
||
out4 = conv_func(out3, conv4_w); | ||
out4 = out4 + conv4_b; | ||
|
||
image_sr = PixelShuffle( out4, 2 ); | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function [ outputs ] = conv_func( inputs, kernels ) | ||
% conv_func : 深度学习中的卷积层前向运算 | ||
% with stride = 1 and padding = 'same' | ||
% | ||
% input : N, C_in, H, W | ||
% kernel : C_out, C_in, kernel_h, kernel_w | ||
% output : N, C_out, H, W | ||
inputs = double(inputs); | ||
kernels = double(kernels); | ||
[N, ~, H, W] = size(inputs); | ||
[C_out, C_in, kernel_h, kernel_w] = size(kernels); | ||
|
||
outputs = zeros(N, C_out, H, W); | ||
tmp = zeros(C_in, H, W); | ||
|
||
for i = 1:N | ||
for j = 1:C_out | ||
for k = 1:C_in | ||
input = reshape(inputs(i, k, :, :), H, W); | ||
kernel = reshape(kernels(j, k, :, :), kernel_h, kernel_w); | ||
tmp(k, :, :) = filter2(kernel, input, 'same'); % tmp (H, W) | ||
outputs(i, j, :, :) = sum(tmp, 1); | ||
end | ||
end | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function [ output ] = relu( input ) | ||
% Éñ¾ÍøÂçÖеÄReLU¼¤»îº¯Êý | ||
% ReLU(x) = max(x, 0) | ||
input (input < 0) = 0; | ||
output = input; | ||
|
||
end | ||
|