Too many input arguments.

2 ビュー (過去 30 日間)
sun rise
sun rise 2022 年 1 月 2 日
回答済み: Walter Roberson 2022 年 1 月 3 日
clear;clc;close all
net = inceptionv3;
inputSizeNet = net.Layers(1).InputSize;
%Convert the network to a dlnetwork object for feature extraction and remove the last four layers, leaving the "mixed10" layer as the last layer.
lgraph = layerGraph(net);
lgraph = removeLayers(lgraph,["avg_pool" "predictions" "predictions_softmax" "ClassificationLayer_predictions"]);
%View the input layer of the network. The Inception-v3 network uses symmetric-rescale normalization with a minimum value of 0 and a maximum value of 255.
lgraph.Layers(1)
%Custom training does not support this normalization, so you must disable normalization in the network and perform the normalization in the custom training loop instead. Save the minimum and maximum values as doubles in variables named inputMin and inputMax, respectively, and replace the input layer with an image input layer without normalization.
%%inputMin = double(lgraph.Layers(1).Min);
%%inputMax = double(lgraph.Layers(1).Max);
layer = imageInputLayer(inputSizeNet,'Normalization','none','Name','input');
lgraph = replaceLayer(lgraph,'input_1',layer);
%Determine the output size of the network. Use the analyzeNetwork function to see the activation sizes of the last layer. To analyze the network for custom training loop workflows, set the TargetUsage option to 'dlnetwork'.
analyzeNetwork(lgraph,'TargetUsage','dlnetwork')
%Create a variable named outputSizeNet containing the network output size.
outputSizeNet = [8 8 2048];
%Convert the layer graph to a dlnetwork object and view the output layer. The output layer is the "mixed10" layer of the Inception-v3 network.
dlnet = dlnetwork(lgraph);
%Load the Image Dataset of Normal and Malignant WBC
imds = imageDatastore('D:\Project\DB1\train','IncludeSubfolders',true,'LabelSource','foldernames');
labelCount = countEachLabel (imds);
%Partition the data into training and validation sets. Hold out 5% of the observations for testing.
cvp = cvpartition(numel(imds.Files),'HoldOut',0.05);
idxTrain = training(cvp);
idxTest = test(cvp);
annotationsTrain = subset(imds,idxTrain);
annotationsTest = subset(imds,idxTest);
%Create an augmented image datastore containing the images corresponding to the captions. Set the output size to match the input size of the convolutional network. To keep the images synchronized with the captions, specify a table of file names for the datastore by reconstructing the file names using the image ID. To return grayscale images as 3-channel RGB images, set the 'ColorPreprocessing' option to 'gray2rgb'.
tblFilenames = table(cat(1,annotationsTrain.Files));
augimdsTrain = augmentedImageDatastore(inputSizeNet,tblFilenames,'ColorPreprocessing','gray2rgb')
%Specify the options for training. Train for 30 epochs with a mini-batch size of 128 and display the training progress in a plot.
miniBatchSize = 128;
numEpochs = 30;
plots = "training-progress";
executionEnvironment = "auto";
%-----------------------
%Train the model.
iteration = 0;
numObservationsTrain = numel(annotationsTrain);
numIterationsPerEpoch = floor(numObservationsTrain / miniBatchSize);
start = tic;
% Loop over epochs.
for epoch = 1:numEpochs
% Shuffle data.
idxShuffle = randperm(numObservationsTrain);
% Loop over mini-batches.
for i = 1:numIterationsPerEpoch
iteration = iteration + 1;
% Determine mini-batch indices.
idx = (i-1)*miniBatchSize+1:i*miniBatchSize;
idxMiniBatch = idxShuffle(idx);
% Read mini-batch of data.
tbl = readByIndex(augimdsTrain,idxMiniBatch);
X = cat(4,tbl.input{:});
annotations = annotationsTrain(idxMiniBatch);
% For each image, select random caption.
idx = cellfun(@(captionIDs) randsample(captionIDs,1),{annotations.CaptionIDs});
documents = documentsAll(idx);
% Create batch of data.
[dlX, dlT] = createBatch(X,documents,dlnet,inputMin,inputMax,enc,executionEnvironment);
end
end
%%Perform Cross-Validation using Hold-out method with a percentage split of 70% training and 30% testing
%%[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomized');
%Select the Test images and save in Y_test
ans =
ImageInputLayer with properties:
Name: 'input_1'
InputSize: [299 299 3]
Hyperparameters
DataAugmentation: 'none'
Normalization: 'none'
AverageImage: []
Error using analyzeNetwork
Too many input arguments.
Error in cnnv3 (line 22)
analyzeNetwork(lgraph,'TargetUsage','dlnetwork')
  1 件のコメント
Walter Roberson
Walter Roberson 2022 年 1 月 3 日
I suspect that your release of matlab is too early to support that optional parameter.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2022 年 1 月 3 日
Tne 'TargetUsage' option was added to analyzeNetwork in R2020b, which is after your release.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by