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',,,,“折叠式”);

使用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 = transform(imdstrain,@(x)recale(x));imdsval = transform(imdsval,@(x)recale(x));imdstest = transform(imdstest,@(x)recale(x));

Generate Training Data

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

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

使用助手函数生成输入数据upsampLowRes,使用imresize产生较低的分辨率图像。

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

使用combine功能将低分辨率图像和高分辨率图像组合到单个数据存储中。输出combine功能是组合的datastoreobject.

dstrain = combine(imdsinputtrain,imdstrain);dsval = combine(imdsinputval,imdsval);dstest = combine(imdsinputTest,imdstest);

Create Network Architecture

使用未扎layerers来自计算机视觉工具箱™的功能。此功能提供了一个适合语义分割的网络,可以轻松适应图像到图像回归。

创建一个具有输入大小28乘28 x-1像素的网络。

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

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

DeepNetworkDesigner(层);

In theDesigner窗格,用从图层库

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

该网络现在可以培训了。

导入数据

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

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

Deep Network Designer在合并的数据存储中显示图像对。高尺度的低分辨率输入图像在左侧,原始的高分辨率响应图像在右侧。网络学习如何在输入和响应图像之间映射。

火车网络

选择the training options and train the network.

In theTrainingtab, selectTraining Options。From theSolver列表,选择adam。SetMaxEpochs10。Confirm the training options by clicking

通过单击在合并的数据存储上训练网络Train

当网络学习如何在两个图像之间映射验证根平方误差(RMSE)减小。

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

Test Network

评估网络的性能sing the test data.

使用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,:),“格栅”,,,,[8,1])) title('Input')subplot(1,3,2) imshow(imtile(I(3,:),“格栅”,,,,[8,1])) title('预测')子图(1,3,3)imshow(imtile(i(2,:),,“格栅”,,,,[8,1])) title('回复'

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

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

金宝app支持功能

functiondataout = upsamplowres(datain)temp = datain;temp = imresize(temp,[7,7],,'method',,,,“双线”);dataout = {imresize(temp,[28,28],,'method',,,,“双线”)};结尾

也可以看看

|

Related Topics