Brain Haemorrhage Diagnosis - Using Lenet based Deep Learning Model
Brain Haemorrhage Diagnosis - Using Lenet based Deep Learning Model
(*changethepathtothedatasourceinyourpc*)
In[]:=
infected=FileNames["*.png","E:\\COURSES\\Wolfram\\Brain Tumor Images Dataset\\training_set\\hemmorhage_data"];uninfected=FileNames["*.png","E:\\COURSES\\Wolfram\\Brain Tumor Images Dataset\\training_set\\non_hemmorhage_data"];
In[]:=
infectedIMG=File/@infected;uninfectedIMG=File/@uninfected;
In[]:=
Length[infectedIMG]
Out[]=
70
In[]:=
infectedvalues=Table[True,Length[infected]];Length[uninfected]
Out[]=
70
In[]:=
uninfectedvalues=Table[False,Length[uninfected]];
In[]:=
data=RandomSample[AssociationThread[infectedIMG->infectedvalues]];traininglength=Length[data]*.75
Out[]=
52.5
In[]:=
trainingdata=data[[1;;52]];validationdata=data[[53;;]];
In[]:=
dims={135,135}
Out[]=
{135,135}
In[]:=
lenet=NetChain[{ResizeLayer[dims],ConvolutionLayer[20,5],Ramp,(*Takesoutthethenotusefulfeatures*)PoolingLayer[2,2],(*Downsamples*)ConvolutionLayer[50,5],Ramp,(*Takesoutthethenotusefulfeatures*)PoolingLayer[2,2],(*Downsamples*)FlattenLayer[],500,(*Makesfeaturesintofeaturevector"*)Ramp,2,(*Takesoutthethenotusefulfeatures-Trueorfalse*)SoftmaxLayer[]},(*Turnsthevectorintoprobabilities*)"Output"NetDecoder[{"Class",{True,False}}],(*Tensorintotrueorfalse*)"Input"NetEncoder["Image"](*Turnsimageintonumbers*)]
Out[]=
NetChain
In[]:=
results=NetTrain[lenet,Normal[trainingdata],All,ValidationSet->Normal[validationdata],MaxTrainingRounds->10,TargetDevice->"CPU"]
Out[]=
NetTrainResultsObject
In[]:=
augment=ImageAugmentationLayer[{135,135},"Input"NetEncoder[{"Image",{139,139}}],"Output"NetDecoder["Image"]]
Out[]=
ImageAugmentationLayer
In[]:=
dims2={139,139}lenet2=NetChain[{ResizeLayer[dims2],ImageAugmentationLayer[{135,135}],ConvolutionLayer[20,5],Ramp,PoolingLayer[2,2],ConvolutionLayer[50,5],Ramp,PoolingLayer[2,2],FlattenLayer[],500,Ramp,2,SoftmaxLayer[]},"Output"NetDecoder[{"Class",{True,False}}],"Input"NetEncoder["Image"]]
Out[]=
{139,139}
Out[]=
NetChain
In[]:=
results2=NetTrain[lenet2,Normal[trainingdata],All,ValidationSet->Normal[validationdata],MaxTrainingRounds->7]
Out[]=
NetTrainResultsObject
In[]:=
trained=results2["TrainedNet"]
Out[]=
NetChain
In[]:=
Export["augmentnet.wlnet",trained]
Out[]=
augmentnet.wlnet
In[]:=
trained2=results["TrainedNet"]
Out[]=
NetChain
In[]:=
trained=Import["E:\\COURSES\\Wolfram\\Projects\\augmentnet.wlnet"]
Out[]=
NetChain
In[]:=
WLNetImport[E:\\COURSES\\Wolfram\\Projects\\augmentnet.wlnet,Net]
In[]:=
testset=Import/@Keys[validationdata];
In[]:=
visual=ClassifierMeasurements[trained,Normal[RandomSample[AssociationThread[testsetValues[validationdata]]]]]
Out[]=
In[]:=
visual/@{"Accuracy","FScore","ConfusionMatrixPlot","Precision","Recall","Sensitivity","FalsePositiveRate","WorstClassifiedExamples"}//TableForm
