2016-12-08 16 views
2

私はウェビナーから得た例を実行しています。 これはコードです:あなたはニューロンの数を3つの新しいレイヤーを置くために、最後の3つの層が削除され、最初のスタートとしてよく知られているAlexNetを使用して、このコードを見ることができるようにMatlab畳み込みニューラルネットワークは学習していません

%% Fine Tuning A Deep Neural Network 
clear; clc;close all; 
imagenet_cnn = load('imagenet-cnn'); 
net = imagenet_cnn.convnet; 
net.Layers 

%% Perform net surgery 
layers = net.Layers(1:end-3); 
layers(end+1) = fullyConnectedLayer(12, 'Name', 'fc8_2') 
layers(end+1) = softmaxLayer('Name','prob_2'); 
layers(end+1) = classificationLayer('Name','classificationLayer_2') 

%% Setup learning rates for fine-tuning 

% fc 8 - bump up learning rate for last layers 
layers(end-2).WeightLearnRateFactor = 100; 
layers(end-2).WeightL2Factor = 1; 
layers(end-2).BiasLearnRateFactor = 20; 
layers(end-2).BiasL2Factor = 0; 

%% Load Image Data 

rootFolder = fullfile('E:\Universidad\Tesis\Matlab', 'TesisDataBase'); 
categories = {'Avion','Banana','Carro','Gato', 'Mango','Perro','Sandia','Tijeras','Silla','Mouse','Calculadora','Arbol'}; 
imds = imageDatastore(fullfile(rootFolder, categories), 'LabelSource', 'foldernames'); 
tbl = countEachLabel(imds); 

%% Equalize number of images of each class in training set 
minSetCount = min(tbl{:,2}); % determine the smallest amount of images in a category 
% Use splitEachLabel method to trim the set. 
imds = splitEachLabel(imds, minSetCount); 

% Notice that each set now has exactly the same number of images. 
countEachLabel(imds) 
[trainingDS, testDS] = splitEachLabel(imds, 0.7,'randomize'); 
% Convert labels to categoricals 
trainingDS.Labels = categorical(trainingDS.Labels); 
trainingDS.ReadFcn = @readFunctionTrain; 

%% Setup test data for validation 
testDS.Labels = categorical(testDS.Labels); 
testDS.ReadFcn = @readFunctionValidation; 

%% Fine-tune the Network 

miniBatchSize = 32; % lower this if your GPU runs out of memory. 
numImages = numel(trainingDS.Files); 
numIterationsPerEpoch = 250; 
maxEpochs = 62; 
lr = 0.01; 
opts = trainingOptions('sgdm', ... 
    'InitialLearnRate', lr,... 
    'LearnRateSchedule', 'none',... 
    'L2Regularization', 0.0005, ... 
    'MaxEpochs', maxEpochs, ... 
    'MiniBatchSize', miniBatchSize); 
net = trainNetwork(trainingDS, layers, opts); 

新しいタスクに必要なものです。あなたがそれらのいずれかを持っている

テストとトレーニングのための読み取りfuncがここに同じです。

function Iout = readFunctionTrain(filename) 
% Resize the flowers images to the size required by the network. 
I = imread(filename); 
% Some images may be grayscale. Replicate the image 3 times to 
% create an RGB image. 
if ismatrix(I) 
    I = cat(3,I,I,I); 
end 
% Resize the image as required for the CNN. 
Iout = imresize(I, [227 227]); 

このコードはウェビナーでうまく動作します、彼らはmatworksドアパススルー車や潜水艦を分類するためにそれを使用します。

問題は、私自身の画像で試してみると、新しいネットが学習していないということです。ImageNETからダウンロードした画像は、1000枚の画像を持つ12種類のデータセットがあります。

ネットは、そのミニバッチ精度を高めることがありません、実際にいくつかの時間が、非常に遅くはありません。

また、私はこのページ Matlab Deep Learning ToolBox

のチュートリアルをやったし、それは私のイメージで良い働きました。だから、私は細かい調整で間違っていることを理解していません。ありがとう。

+0

あなたはデータを正規化していますか? –

+0

はい、入力レイヤーは、リンクで見ているようにそれ自身で行います –

答えて

関連する問題