主要内容

Get Started with Deep Network Designer

This example shows how to use Deep Network Designer to adapt a pretrained GoogLeNet network to classify a new collection of images. This process is called transfer learning and is usually much faster and easier than training a new network, because you can apply learned features to a new task using a smaller number of training images. To prepare a network for transfer learning interactively, use Deep Network Designer.

Extract Data for Training

在里面workspace, unzip the data.

unzip('merchdata.zip');

选择一个预告片的网络

Open Deep Network Designer.

deepNetworkDesigner

Load a pretrained GoogLeNet network by selecting it from the Deep Network Designer Start Page. If you need to download the network, then clickInstallto open the Add-On Explorer.

深网设计师displays a zoomed-out view of the whole network. Explore the network plot. To zoom in with the mouse, useCtrl+scroll wheel.

加载数据集

To load the data into Deep Network Designer, on the数据tab, clickImport Data>导入图像数据。The Import Image Data dialog box opens.

在里面数据sourcelist, select文件夹。点击浏览和select the extracted MerchData folder.

对话框还允许您从应用程序内部分配验证数据。将数据分为70%的培训数据和30%的验证数据。

Specify augmentation operations to perform on the training images. For this example, apply a random reflection in the x-axis, a random rotation from the range [-90,90] degrees, and a random rescaling from the range [1,2].

点击Import将数据导入深层网络设计器。

Using Deep Network Designer, you can visually inspect the distribution of the training and validation data in the数据tab. You can see that, in this example, there are five classes in the data set. You can also view random observations from each class.

深网设计师resizes the images during training to match the network input size. To view the network input size, in the设计师选项卡,单击imageInputLayer。This network has an input size of 224-by-224.

Edit Network for Transfer Learning

要重新训练一个验证的网络以对新图像进行分类,请用适合新数据集的新层替换最后一个可学习的层和最终分类层。在Googlenet中,这些层有名字'loss3-classifier''output', respectively.

在里面设计师tab, drag a newfullyConnectedLayer来自Layer Libraryonto the canvas. SetOutputSizeto the number of classes in the new data, in this example,5

Edit learning rates to learn faster in the new layers than in the transferred layers. SetWeightLearnRateFactorBiasLearnRateFactorto10。删除最后一个完全连接的层,然后连接新图层。

更换输出层。滚动到末端Layer Library和drag a newclassificationLayeronto the canvas. Delete the originaloutput层并连接新图层。

Check Network

单击检查您的网络Analyze。如果深度学习网络分析仪报告零错误,则该网络已准备好培训。

火车Network

To train the network with the default settings, on the火车ingtab, click火车

If you want greater control over the training, click培训选项和choose the settings to train with. The default training options are better suited for large data sets. For small data sets, use smaller values for the mini-batch size and the validation frequency. For more information on selecting training options, see训练

For this example, set初始learternrateto0.0001,ValidationFrequencyto5, 和Maxepochsto8。As there are 55 observations, setMinibatchSizeto11均匀地分配训练数据,并确保在每个时期内使用整个训练集。

To train the network with the specified training options, clickClose和then click火车

深层网络设计师允许您可视化和监视培训进度。然后,您可以编辑培训选项,并在需要时重新训练网络。

出口Results from Training

To export the results from training, on the火车ingtab, select出口>出口培训的网络和结果。深网设计师exports the trained network as the variableTrainednetwork_1和培训信息作为变量traininfostruct_1

You can also generate MATLAB code, which recreates the network and the training options used. On the火车ingtab, select出口>生成培训代码

测试训练的网络

选择一个新图像使用训练有素的网络进行分类。

I = imread("MerchDataTest.jpg");

调整测试图像以匹配网络输入大小。

i = imresize(i,[224 224]);

Classify the test image using the trained network.

[YPred,probs] = classify(trainedNetwork_1,I); imshow(I) label = YPred; title(string(label) +“,”+ num2str(100*max(probs),3) +"%");

更多信息,包括其他pretrained networks, see深网设计师

See Also

相关话题