This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final Logger log = LoggerFactory.getLogger(SemanticSegmentation.class); | |
private static int height = 96; | |
private static int width = 96; | |
private static int channels = 1; | |
private static int batchSize = 22; | |
private static long seed = 1234; | |
private static Random rng = new Random(seed); | |
private static int epochs = 1; | |
public static final String DATA_PATH= "C:/Users/bismi/Documents/dl4j/brain-tumor-segmentation/src/main/resources"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SemanticSegmentation { | |
private static final Logger log = LoggerFactory.getLogger(SemanticSegmentation.class); | |
private static int height = 256; | |
private static int width = 256; | |
private static int channels = 1; | |
private static int batchSize = 6; | |
private static long seed = 1234; | |
private static Random rng = new Random(seed); | |
private static int epochs = 100; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21:05:24.437 [main] INFO ma.enset.brain_tumor_segmentation.MyPathLabelGenerator - C:/Users/bismi/Documents/dl4j/brain-tumor-segmentation/src/main/resources/testI/rois/1.png | |
21:05:24.557 [main] INFO ma.enset.brain_tumor_segmentation.SemanticSegmentationLoad2 - | |
========================Evaluation Metrics======================== | |
# of classes: 2 | |
Accuracy: 0,9990 | |
Precision: 0,9318 | |
Recall: 1,0000 | |
F1 Score: 0,9647 | |
Precision, recall & F1: reported for positive class (class 1 - "1") only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21:03:21.537 [main] INFO ma.enset.brain_tumor_segmentation.MyPathLabelGenerator - C:/Users/bismi/Documents/dl4j/brain-tumor-segmentation/src/main/resources/testI/rois/1.png | |
21:03:21.540 [main] DEBUG org.nd4j.jita.handler.impl.CudaZeroHandler - Creating bucketID: 2 | |
21:03:21.677 [main] INFO ma.enset.brain_tumor_segmentation.SemanticSegmentationLoad2 - | |
========================Evaluation Metrics======================== | |
# of classes: 2 | |
Accuracy: 0,1186 | |
Precision: 0,0149 | |
Recall: 1,0000 | |
F1 Score: 0,0294 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ma.enset.brain_tumor_segmentation; | |
import org.deeplearning4j.nn.conf.inputs.InputType; | |
import org.deeplearning4j.nn.conf.layers.samediff.SDLayerParams; | |
import org.deeplearning4j.nn.conf.layers.samediff.SameDiffOutputLayer; | |
import org.nd4j.autodiff.samediff.SDVariable; | |
import org.nd4j.autodiff.samediff.SameDiff; | |
import org.nd4j.linalg.api.ndarray.INDArray; | |
import java.util.Map; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ma.enset.brain_tumor_segmentation; | |
import org.deeplearning4j.nn.conf.inputs.InputType; | |
import org.deeplearning4j.nn.conf.layers.samediff.SDLayerParams; | |
import org.deeplearning4j.nn.conf.layers.samediff.SameDiffOutputLayer; | |
import org.nd4j.autodiff.samediff.SDVariable; | |
import org.nd4j.autodiff.samediff.SameDiff; | |
import org.nd4j.linalg.api.ndarray.INDArray; | |
import java.util.Map; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while (Iter.hasNext()) { | |
DataSet next = Iter.next(); | |
INDArray out2d = modelT.outputSingle(next.getFeatures()).permute(0,2,3,1).dup().reshape('c',height*width,1); | |
INDArray labels2d = next.getLabels().permute(0,2,3,1).dup().reshape('c',height*width,1); | |
if(k==0) { | |
e.eval(labels2d, out2d); | |
log.info(e.stats()); | |
} | |
k++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ImageRecordReader recordReader = new ImageRecordReader(height, width, channels, labelMaker); | |
recordReader.initialize(train); | |
Field f = BaseImageRecordReader.class.getDeclaredField("imageLoader"); | |
f.setAccessible(true); | |
f.set(recordReader, new NativeImageLoader(height, width, 1, BaseImageLoader.MultiPageMode.MINIBATCH)); | |
int labelIndex = 1; //You have 2 Writables ("columns") - index 0 is features image NDArrayWritable, index 1 is labels image NDArrayWritable | |
// DataSet Iterator | |
DataSetIterator dataIter = new RecordReaderDataSetIterator(recordReader, batchSize, labelIndex, labelIndex, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyPathLabelGenerator implements PathLabelGenerator{ | |
protected static final Logger log = LoggerFactory.getLogger(MyPathLabelGenerator.class); | |
String labelsDir; | |
private static NativeImageLoader imageLoader = new NativeImageLoader(96, 96, 1); | |
File file; | |
public MyPathLabelGenerator(String path) { | |
labelsDir=path; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Exception in thread "main" java.lang.IllegalStateException: Input and label arrays do not have same shape: [24, 3, 96, 96] vs. [24, 1, 96, 96] | |
at org.nd4j.base.Preconditions.throwStateEx(Preconditions.java:641) | |
at org.nd4j.base.Preconditions.checkState(Preconditions.java:340) | |
at org.deeplearning4j.nn.layers.convolution.CnnLossLayer.backpropGradient(CnnLossLayer.java:80) | |
at org.deeplearning4j.nn.graph.vertex.impl.LayerVertex.doBackward(LayerVertex.java:149) | |
at org.deeplearning4j.nn.graph.ComputationGraph.calcBackpropGradients(ComputationGraph.java:2663) | |
at org.deeplearning4j.nn.graph.ComputationGraph.computeGradientAndScore(ComputationGraph.java:1378) | |
at org.deeplearning4j.nn.graph.ComputationGraph.computeGradientAndScore(ComputationGraph.java:1338) | |
at org.deeplearning4j.optimize.solvers.BaseOptimizer.gradientAndScore(BaseOptimizer.java:160) | |
at org.deeplearning4j.optimize.solvers.StochasticGradientDescent.optimize(StochasticGradientDescent.java:63) |
NewerOlder