Main Content

深网络设计师的图像到图像回归

此示例显示如何使用深网络设计器构建和培训用于超分辨率的图像到图像回归网络。

Spatial resolution is the number of pixels used to construct a digital image. An image with a high spatial resolution is composed of a greater number of pixels and as a result the image contains greater detail. Super resolution is the process of taking as input a low resolution image and upscaling it into a higher resolution image. When you work with image data, you might reduce the spatial resolution to decrease the size of the data, at the cost of losing information. To recover this lost information, you can train a deep learning network to predict the missing details of an image. In this example, you recover 28-by-28 pixel images from images that were compressed to 7-by-7 pixels.

加载数据

This example uses the digits data set, which consists of 10,000 synthetic grayscale images of handwritten digits. Each image is 28-by-28-by-1 pixels.

Load the data and create an image datastore.

dataFolder = fullfile(toolboxdir('nnet'的)那'nndemos''nndatasets''DigitDataset');imds = imageDatastore(dataFolder,......'IncludeSubfolders',真的,......'LabelSource''foldernames');

使用shuffle在培训之前将数据进行洗牌。

imds = shuffle(imds);

使用spliteachlabel.函数将图像数据存储划分为包含图像以进行培训,验证和测试的图像的三个图像数据存储。

[IMDStrain,IMDSVAL,IMDSTEST] = SpliteachLabel(IMDS,0.7,0.15,0.15,'randomized');

Normalize the data in each image to the range [0,1]. Normalization helps stabilize and speed up network training using gradient descent. If your data is poorly scaled, then the loss can become NaN and the network parameters can diverge during training.

IMDStrain =变换(IMDStrain,@(x)Rescale(x));IMDSVAL =变换(IMDSVAL,@(x)RESCALE(X));IMDSTEST =变换(IMDSTEST,@(x)RESCALE(X));

Generate Training Data

通过生成由上采样的低分辨率图像和相应的高分辨率图像组成的图像组来创建培训数据。

为了训练网络来执行图像到图像回归,需要对由输入组成的对和响应,其中两个图像都是相同的大小。通过将每个图像下采样为7×7像素来生成培训数据,然后将上采样为28×28像素。使用转换和原始图像,网络可以学习如何在两种不同的分辨率之间映射。金宝搏官方网站

使用辅助功能生成输入数据upsampLowRes,它使用imresize产生更低的分辨率图像。

imdsInputTrain =变换(imdsTrain @upsampLowRes);imdsInputVal= transform(imdsVal,@upsampLowRes); imdsInputTest = transform(imdsTest,@upsampLowRes);

使用combine功能将低分辨率和高分辨率图像组合成单个数据存储。输出combine功能是A.ConventDatastore.object.

dstrain =组合(Imdsinputtrain,Imdstrain);dsval =组合(IMDSInputval,IMDSVal);dstest =组合(Imdsinputtest,Indstest);

Create Network Architecture

使用该创建网络架构单层计算机Vision Toolbox™功能。该函数提供适合于语义分割的网络,其可以很容易地适应图像到图像回归。

创建具有输入大小28-28×1像素的网络。

layers = unetLayers([28,28,1],2,'ercoderdepth'那2);

使用深网络设计器编辑图像到图像回归的网络。

DeepNetWorkDesigner(层);

In theDesigner窗格,用来自的回归层替换Softmax和像素分类图层图书馆库

选择最终的卷积层并设置NumFilters财产1

网络现在已准备好进行培训。

进口数据

进口the training and validation data into Deep Network Designer.

In theData选项卡,单击进口数据>进口数据store并选择dsTrainas the training data anddsVal作为验证数据。单击导入两个数据存储进口

深度网络设计器显示组合数据存储中的图像对。左侧上升的低分辨率输入图像,原始高分辨率响应图像右侧。网络了解如何在输入和响应图像之间映射。

火车网络

选择the training options and train the network.

In the训练tab, select训练Options。From theSolver列表,选择adam。SetMaxEpochs10.。Confirm the training options by clicking关闭

点击培训在组合数据存储上的网络Train

由于网络了解如何在两个图像之间映射验证根均方误差(RMSE)减小。

Once training is complete, clickExport将培训的网络导出到工作区。训练有素的网络存储在变量中trainedNetwork_1

Test Network

使用测试数据评估网络的性能。

使用predict那you can test if the network can produce a high resolution image from a low resolution input image that was not included in the training set.

ypred = predict(trainedNetwork_1,dsTest);为了i = 1:8 I(1:2,i)=读(DSTEST);i(3,i)= {ypred(:,:,:,i)};结尾

Compare the input, predicted, and response images.

subplot(1,3,1) imshow(imtile(I(1,:),'gridsize'那[8,1])) title('Input'的)subplot(1,3,2) imshow(imtile(I(3,:),'gridsize'那[8,1])) title('预测')子图(1,3,3)imshow(imtile(i(2,:),'gridsize'那[8,1])) title('回复'的)

该网络成功地从低分辨率输入产生了高分辨率图像。

在此示例中的网络非常简单且高度定制到数字数据集。有关用于为日常图像创建更复杂的图像到图像回归网络的示例,请参阅单幅图像超分辨率使用深度学习

金宝app支持功能

functiondataout = upsamplowres(数据)temp =日期;temp = imresize(temp,[7,7],'method''双线性');dataout = {imresize(temp,[28,28],'method''双线性'的)};结尾

也可以看看

|

Related Topics