我有一個90×50的矩陣來保存我的列車數據。每行都保存從數字輸入圖像中提取的特徵(已讀取90個圖像 - 每個數字顯示10個圖像)。前10行是從數字1
的10幅圖像中提取,第二個10行從10個圖像數字2
萃取,等等,因此size(dataset,1) = 90
Matlab神經網絡錯誤:輸入1大小不匹配net.inputs {1} .size
神經網絡的我的代碼部分如下所示:
T=zeros(1,90);
for i=1:90
T(i)=ceil(i/10);
end
setdemorandstream(491218382);
net=fitnet(20);
[net,tr]=train(net,datasetNormalized',T);
datasetNormalized是我的數據集在[0 1]間隔內進行了歸一化處理。 T是網絡的目標。 我現在想要做的是獲得一個數字的新圖像,將其轉化爲1×50的矢量(在這種情況下是m_normalized),並在我的訓練網絡的幫助下猜測它的數字是多少。我用下面的代碼,但它確實產生錯誤:
[a,b]=max(sim(net,m_normalized));
disp(b);
msgbox(['digit is: ' num2str(b)],'Digit recognized','help');
錯誤消息的內容是這樣的:
Error using network/sim (line 130)
Input 1 size does not match net.inputs{1}.size.
Error in Neural (line 92)
[a,b]=max(sim(net,m_normalized));
你有什麼想法,我怎麼可以從顯示我的腳本輸出輸入圖像的位數是多少? 順便說一句,完整的腳本代碼是在這裏作進一步參考:
的用於訓練使用的訓練後,模擬網絡神經網絡的輸入輸入clc
clear
close all
numOfPhotos = 90;
imgRows = 100;
imgCols = 50;
X = zeros(numOfPhotos, (imgRows * imgCols)/100);
%% Resize Images
% myresize(imgRows,imgCols);
% read train images
datasetIndex = 0;
for i = 1:numOfPhotos/10
for j = 1:numOfPhotos/9
datasetIndex = datasetIndex+1;
im = imread(['resized_train_numbers\' num2str(i) ' (' num2str(j) ').jpg']);
im = im2bw(im, graythresh(im));
c = 1;
for g = 1:imgRows/10
for e = 1:imgCols/10
s = sum(sum(im((g*10-9 : g*10),(e*10-9 : e*10))));
X(datasetIndex, c) = s;
c = c+1;
end
end
end
end
datasetNormalized = zeros(numOfPhotos, imgRows*imgCols/100);
%% Normalize dataset contents
minDataset = min(min(X));
maxDataset = max(max(X));
for i = 1:numOfPhotos
for j = 1:imgRows*imgCols/100
datasetNormalized(i, j) = (X(i, j) - minDataset)/(maxDataset - minDataset);
end
end
%%Neural network part
T = zeros(1, 90);
for i = 1:90
T(i) = ceil(i/10);
end
setdemorandstream(491218382);
net = fitnet(20);
[net, tr]=train(net, datasetNormalized', T);
% Read input image for recognition
newImg = imread('plate_1\1.jpg');
newImg = imresize(newImg, [imgRows imgCols]);
newImg = im2bw(newImg, graythresh(newImg));
scrsz = get(0, 'ScreenSize');
figure('Position', [1 1 scrsz(3)/3 scrsz(4)/2]),
imshow(newImg);
m = zeros(1, imgRows*imgCols/100);
c = 1;
for g = 1:imgRows/10
for e = 1:imgCols/10
s = sum(sum(newImg((g*10-9 : g*10), (e*10-9 : e*10))));
m(c) = s;
c = c+1;
end
end
%Normalize m contents
m_normalized = zeros(1, imgRows*imgCols/100);
for i = 1:imgRows*imgCols/100
m_normalized(i) = (m(i)-min(m))/(max(m)-min(m));
end
[a,b] = max(sim(net, m_normalized));
disp(b);
msgbox(['digit is: ' num2str(b)], 'Digit recognized', 'help');
爲什麼不檢查'Input 1 size'和'net.inputs {1} .size'是否一樣? – Mehraban
也許我不知道他們是什麼節正好在我的代碼:這是MATLAB說:'>> net.inputs {1} ANS = 神經網絡的輸入 名:「輸入」 feedbackOutput: [] processFcns:{ 'fixunknowns',removeconstantrows, mapminmax} processParams:{2個PARAMS 1×3單元陣列} processSettings:{3只設置1×3單元陣列} processedRange:[50X2雙] processedSize:50 範圍:[50x2雙] 大小:50 userdata :(你的自定義信息)'是否matl ab意思是「輸入1」的「網絡」? – JasonStack
我想你應該檢查'm_normalized'大小和'net.input {1}'大小 – Mehraban