hello everyne i'm runing this code for testing and training but receiving errors can any please help me to correct this code i shall be very thank full to you for this kindness.
clc
clear all
close all
image=uigetfile(['*.jpg'],'D:\Diabetic retnopathery\DR code');
copyfile('D:\Diabetic retnopathery\DR code','D:\Diabetic retnopathery\DR code\New Folder');
%inp=input('ENTER IMAGE :');
imgg=imread(image);
aa=imgg;
[m n c]=size(aa);
if c==3
b=rgb2gray(aa);
else
b=aa;
end
im =b;
figure,
imshow(aa)
title('input ')
matlabroot='D:\Diabetic retnopathery\DR code'
DatasetPath = fullfile(matlabroot,'fundusdeeplearning','Dataset1');
Data = imageDatastore(DatasetPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
CountLabel = Data.countEachLabel;
trainData=Data;
%% Define the Network Layers
% Define the convolutional neural network architecture.
layers = [imageInputLayer([336 448 3])
convolution2dLayer(5,20)
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(5,20)
reluLayer
maxPooling2dLayer(2,'Stride',2)
fullyConnectedLayer(2)
softmaxLayer
classificationLayer()];
options = trainingOptions('sgdm','MaxEpochs',15, ...
'InitialLearnRate',0.0001);
convnet = trainNetwork(trainData,layers,options);
%% Classify the Images in the Test Data and Compute Accuracy
% Run the trained network on the test set that was not used to train the
% network and predict the image labels (digits).
img =imgg;
img=imresize(img,[336 448]);
size(img)
outt = classify(convnet,img);
tf1=[]
for ii=1:2
st=int2str(ii)
tf = ismember(outt,st);
tf1=[tf1 tf];
end
out=find(tf1==1);
ss=sprintf('THE CLASS IS : %2f ',round((out)));
if out==1
msgbox('NORMAL')
elseif out==2
msgbox('AB NORMAL')
end

댓글 수: 9

Tommy
Tommy 2020년 4월 18일
What is the error message?
Anas Bilal
Anas Bilal 2020년 4월 18일
Error using trainNetwork (line 165)
Invalid training data. The output size (2) of the last layer does not match the number of classes (1).
Error in fundus_CNN (line 53)
convnet = trainNetwork(trainData,layers,options);
D:\Diabetic retnopathery\DR code\fundusdeeplearning\Dataset1
either has one or more image files but no subfolders that have images in them, or it has no image files in itself directly, and has exactly one sub-folder that has images in them.
What does CountLabel show? I expect it is a scalar when you would want a vector of length 2.
Anas Bilal
Anas Bilal 2020년 4월 18일
can you please modify the code accordingly
KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 4월 18일
@Anas Walter is asking some questions, please read the comments and answer the question, so that we can help you.
Anas Bilal
Anas Bilal 2020년 4월 18일
There are 2 image in subfolder.
Anas Bilal
Anas Bilal 2020년 4월 18일
@Walter Roberson i ayyached the comand window image plea take a look
Walter Roberson
Walter Roberson 2020년 4월 18일
If I am correct about the cause of the problem, then the only way to fix your code would be to put in some tests to detect the situation and give a appropriate message without trying to do the training.
That is, if I am right about the error, then then problem is your data and not the code.
Anas Bilal
Anas Bilal 2020년 4월 18일
ok .i'll try

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

질문:

2020년 4월 18일

댓글:

2020년 4월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by