In this presentation, you will try learn how to automatically detect COVID-19 in a hand-created X-ray image dataset using Deeplearning4j and talk about And talking about an experiment that I did using the technique of object detection to capture the Covid virus through pictures of infected cells. But it did not produce good results due to the lack of pictures of the affected cells.
Meaning that the two techniques can be applied to technical assistance for health professionals
We will rely on DL4J framework to create the neural network according to the following plan:
1-Build the neural network
2- Train the model the net
3- Save & Loading the model of our neural network
4- Test the neural network against unsigned images
2- Train the model the net
3- Save & Loading the model of our neural network
4- Test the neural network against unsigned images
1-Buildin The neural Network :
At this point we will count on Datavec image pipeline.we are going to use ParentPathLabelGeneraator to apply labels to a collection of images based upon the directory where there located in our case we have tow directories (for positive and negative Diagnosed X-ray images),and ImagePreProcessingScaler to transform the array pixel to a binary values.
2-Train the net :
Adding MultiLayerNetwork,training the model against our training dataset and testing the model withe the test data set
private static Logger log = LoggerFactory.getLogger(MnistImagePipelineExampleAddNeuralNet.class); /** Location to save and extract the training/testing data */private static final String DATA_PATH = FilenameUtils.concat(System.getProperty("java.io.tmpdir"), "YourPATHDIR");// create the main class public static void main(String[] args) throws Exception { // image information // 100* 100 grayscale this is the case of my croped images // grayscale implies single channel int height = 100; int width = 100; int channels = 1; int rngseed = 123; Random randNumGen = new Random(rngseed); int batchSize = 128;/* we have just two outputs positive and negative according to our directories */ int outputNum = 2; int numEpochs = 1; /* This class downloadData() downloads the data stores the data in java's tmpdir 15MB download compressed It will take 158MB of space when uncompressed The data can be downloaded manually here // Define the File Paths File trainData = new File(DATA_PATH + "/covid-19/training"); File testData = new File(DATA_PATH + "/covid-19/testing"); // Define the FileSplit(PATH, ALLOWED FORMATS,random) FileSplit train = new FileSplit(trainData, NativeImageLoader.ALLOWED_FORMATS, randNumGen); FileSplit test = new FileSplit(testData, NativeImageLoader.ALLOWED_FORMATS, randNumGen); // Extract the parent path as the image label ParentPathLabelGenerator labelMaker = new ParentPathLabelGenerator(); ImageRecordReader recordReader = new ImageRecordReader(height, width, channels, labelMaker); // Initialize the record reader // add a listener, to extract the name recordReader.initialize(train); //recordReader.setListeners(new LogRecordListener()); // DataSet Iterator DataSetIterator dataIter = new RecordReaderDataSetIterator(recordReader, batchSize, 1, outputNum); // Scale pixel values to 0-1 DataNormalization scaler = new ImagePreProcessingScaler(0, 1); scaler.fit(dataIter); dataIter.setPreProcessor(scaler); // Build Our Neural Network log.info("BUILD MODEL"); MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() .seed(rngseed) .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT) .updater(new Nesterovs(0.006, 0.9)) .l2(1e-4) .list() .layer(0, new DenseLayer.Builder() .nIn(height * width) .nOut(100) .activation(Activation.RELU) .weightInit(WeightInit.XAVIER) .build()) .layer(1, new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD) .nIn(100) .nOut(outputNum) .activation(Activation.SOFTMAX) .weightInit(WeightInit.XAVIER) .build()) .setInputType(InputType.convolutional(height, width, channels)) .build(); MultiLayerNetwork model = new MultiLayerNetwork(conf); // The Score iteration Listener will log // output to show how well the network is training model.setListeners(new ScoreIterationListener(10)); log.info("TRAIN MODEL"); for (int i = 0; i < numEpochs; i++) { model.fit(dataIter); } log.info("EVALUATE MODEL"); recordReader.reset(); // The model trained on the training dataset split // now that it has trained we evaluate against the // test data of images the network has not seen recordReader.initialize(test); DataSetIterator testIter = new RecordReaderDataSetIterator(recordReader, batchSize, 1, outputNum); scaler.fit(testIter); testIter.setPreProcessor(scaler); /* log the order of the labels for later use In previous versions the label order was consistent, but random In current verions label order is lexicographic preserving the RecordReader Labels order is no longer needed left in for demonstration purposes */ log.info(recordReader.getLabels().toString()); // Create Eval object with 10 possible classes Evaluation eval = new Evaluation(outputNum); // Evaluate the network while (testIter.hasNext()) { DataSet next = testIter.next(); INDArray output = model.output(next.getFeatures()); // Compare the Feature Matrix from the model // with the labels from the RecordReader eval.eval(next.getLabels(), output); } // show the evaluation log.info(eval.stats()); }ََ
And running the test gave me good resultsAs shown in the picture
4-Test the neural network against unsigned images :
in this one load the saved neural net and launch a test On pictures to perform a conformance test and matching ratio.You will find the source code on the following repo.
Commentaires
Enregistrer un commentaire