diff --git a/src/rawDeepLearningClassifier/dataPlotFX/DLPredictionPane.java b/src/rawDeepLearningClassifier/dataPlotFX/DLPredictionPane.java index c603f08f..19147c81 100644 --- a/src/rawDeepLearningClassifier/dataPlotFX/DLPredictionPane.java +++ b/src/rawDeepLearningClassifier/dataPlotFX/DLPredictionPane.java @@ -101,6 +101,8 @@ public class DLPredictionPane extends PamBorderPane implements TDSettingsPane { if (dlPredictionPlotInfoFX.getDlControl().getDLModel()!=null) { //populate the prediction pane. DLClassName[] classNames = dlPredictionPlotInfoFX.getDlControl().getDLModel().getClassNames(); + +// System.out.println("MAKE MY CLASS NAMES: " + dlPredictionPlotInfoFX.getDlControl().getDLModel().getClassNames()); layoutColourPanes(classNames); } diff --git a/src/rawDeepLearningClassifier/dataPlotFX/DLPredictionPlotInfoFX.java b/src/rawDeepLearningClassifier/dataPlotFX/DLPredictionPlotInfoFX.java index 44fdca6f..36aed7ed 100644 --- a/src/rawDeepLearningClassifier/dataPlotFX/DLPredictionPlotInfoFX.java +++ b/src/rawDeepLearningClassifier/dataPlotFX/DLPredictionPlotInfoFX.java @@ -94,7 +94,7 @@ public class DLPredictionPlotInfoFX extends GenericLinePlotInfo { if (getDlControl().getDLModel()!=null) { DLClassName[] classNames = getDlControl().getDLModel().getClassNames(); -// System.out.println("Class names are: !!! " + (classNames == null ? "null" : classNames.length)); + System.out.println("Class names are: !!! " + (classNames == null ? "null" : classNames.length)); if (classNames!=null) { @@ -105,8 +105,8 @@ public class DLPredictionPlotInfoFX extends GenericLinePlotInfo { dlPredParams.lineInfos[i] = new LineInfo(true, Color.rgb(0, 0, 255%(i*30 + 50))); } } - } + getGraphSettingsPane().setParams(); } } diff --git a/src/rawDeepLearningClassifier/dlClassification/DLClassifyProcess.java b/src/rawDeepLearningClassifier/dlClassification/DLClassifyProcess.java index bb0f8945..03806aa3 100644 --- a/src/rawDeepLearningClassifier/dlClassification/DLClassifyProcess.java +++ b/src/rawDeepLearningClassifier/dlClassification/DLClassifyProcess.java @@ -197,7 +197,7 @@ public class DLClassifyProcess extends PamInstantProcess { if (pamRawData instanceof SegmenterDetectionGroup) { if (classificationBuffer.size()>=1) { - System.out.println("RUN THE MODEL FOR WHISTLES: "); +// System.out.println("RUN THE MODEL FOR WHISTLES: "); runDetectionGroupModel(); classificationBuffer.clear(); } @@ -232,14 +232,15 @@ public class DLClassifyProcess extends PamInstantProcess { /** * Run a model for which the input is a detection group. */ - private void runDetectionGroupModel() { + private synchronized void runDetectionGroupModel() { if (classificationBuffer.size()<=0) return; ArrayList classificationBufferTemp = (ArrayList) classificationBuffer.clone(); ArrayList modelResults = this.dlControl.getDLModel().runModel(classificationBufferTemp); for (int i=0; i) delphinIDParams.dlTransfromParams); } diff --git a/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDWorker.java b/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDWorker.java index c411cce1..a2fcc459 100644 --- a/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDWorker.java +++ b/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDWorker.java @@ -2,6 +2,7 @@ package rawDeepLearningClassifier.dlClassification.delphinID; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import org.jamdev.jdl4pam.transforms.DLTransform; @@ -9,18 +10,23 @@ import org.jamdev.jdl4pam.transforms.DLTransfromParams; import org.jamdev.jdl4pam.transforms.FreqTransform; import org.jamdev.jdl4pam.transforms.DLTransform.DLTransformType; import org.jamdev.jdl4pam.transforms.jsonfile.DLTransformsParser; +import org.jamdev.jdl4pam.utils.DLMatFile; import org.jamdev.jdl4pam.utils.DLUtils; import org.json.JSONArray; import org.json.JSONObject; +import PamUtils.PamArrayUtils; import PamguardMVC.PamDataUnit; import ai.djl.Model; import rawDeepLearningClassifier.DLControl; import rawDeepLearningClassifier.dlClassification.animalSpot.StandardModelParams; import rawDeepLearningClassifier.dlClassification.archiveModel.ArchiveModelWorker; import rawDeepLearningClassifier.dlClassification.delphinID.Whistles2Image.Whistle2ImageParams; -import rawDeepLearningClassifier.segmenter.GroupedRawData; import rawDeepLearningClassifier.segmenter.SegmenterDetectionGroup; +import us.hebi.matlab.mat.format.Mat5; +import us.hebi.matlab.mat.types.MatFile; +import us.hebi.matlab.mat.types.Matrix; +import us.hebi.matlab.mat.types.Struct; /** * @@ -86,11 +92,50 @@ public class DelphinIDWorker extends ArchiveModelWorker { return whistle2ImageParmas; } - } + //something has gone wrong if we get here. return null; } + + + + private Struct imageStruct; + int count = 0; + /** + * Tets by exporting results to a .mat file. + * @param data + * @param aSegment + */ + private void addIMage2MatFile(double[][] data, SegmenterDetectionGroup aSegment) { + long dataStartMillis = 1340212413000L; + + if (imageStruct==null) { + imageStruct = Mat5.newStruct(100,1); + } + Matrix image = DLMatFile.array2Matrix(data); + imageStruct.set("image", count, image); + imageStruct.set("startmillis", count, Mat5.newScalar(aSegment.getSegmentStartMillis())); + imageStruct.set("startseconds", count, Mat5.newScalar((aSegment.getSegmentStartMillis()-dataStartMillis)/1000.)); + + count++; + + System.out.println("SAVED " +count + " TO MAT FILE"); + + if (count==10) { + //create MatFile for saving the image data to. + MatFile matFile = Mat5.newMatFile(); + matFile.addArray("whistle_images", imageStruct); + //the path to the model + String matImageSave = "C:/Users/Jamie Macaulay/MATLAB Drive/MATLAB/PAMGUARD/deep_learning/delphinID/whistleimages_pg.mat"; + try { + Mat5.writeToFile(matFile,matImageSave); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } @Override @@ -110,7 +155,7 @@ public class DelphinIDWorker extends ArchiveModelWorker { double[][] transformedData2; //spectrogram data for (int j=0; j { @Override public float[] runModel(float[][][] transformedDataStack) { - System.out.println("RUN GENERIC MODEL: " + transformedDataStack.length + " " + transformedDataStack[0].length + " " + transformedDataStack[0][0].length); +// System.out.println("RUN GENERIC MODEL: " + transformedDataStack.length + " " + transformedDataStack[0].length + " " + transformedDataStack[0][0].length); // System.out.println("RUN GENERIC MODEL: " + transformedDataStack[0][0][0]); float[] results; if (freqTransform) @@ -48,8 +48,8 @@ public class GenericModelWorker extends DLModelWorker { //System.out.println("RUN GENERIC MODEL WAVE: " + waveStack.length + " " + waveStack[0].length + " " + waveStack[0][0]); results = getModel().runModel(waveStack); } - System.out.println("GENERIC MODEL RESULTS: " + (results== null ? null : results.length)); - PamArrayUtils.printArray(results); +// System.out.println("GENERIC MODEL RESULTS: " + (results== null ? null : results.length)); +// PamArrayUtils.printArray(results); return results; } diff --git a/src/rawDeepLearningClassifier/segmenter/SegmenterDetectionGroup.java b/src/rawDeepLearningClassifier/segmenter/SegmenterDetectionGroup.java index fe218fbf..9636a52b 100644 --- a/src/rawDeepLearningClassifier/segmenter/SegmenterDetectionGroup.java +++ b/src/rawDeepLearningClassifier/segmenter/SegmenterDetectionGroup.java @@ -21,6 +21,8 @@ public class SegmenterDetectionGroup extends GroupDetection { */ private long segMillis; + private double timeS; + /** * Constructor for a group of detections within a detection. Note that some * longer detections (e.g. whistles) may have sections outside the segment. @@ -33,7 +35,7 @@ public class SegmenterDetectionGroup extends GroupDetection { public SegmenterDetectionGroup(long timeMilliseconds, int channelBitmap, long startSample, double duration) { super(timeMilliseconds, channelBitmap, startSample, (long) duration); this.setDurationInMilliseconds(duration); - this.segMillis =timeMilliseconds; + this.segMillis = timeMilliseconds; this.segDuration = duration; } @@ -56,5 +58,13 @@ public class SegmenterDetectionGroup extends GroupDetection { return (long) (segMillis+segDuration); } + public void setStartSecond(double timeS) { + this.timeS = timeS; + } + + public double getStartSecond() { + return timeS; + } + } diff --git a/src/rawDeepLearningClassifier/segmenter/SegmenterProcess.java b/src/rawDeepLearningClassifier/segmenter/SegmenterProcess.java index 3ae032a0..7012ac68 100644 --- a/src/rawDeepLearningClassifier/segmenter/SegmenterProcess.java +++ b/src/rawDeepLearningClassifier/segmenter/SegmenterProcess.java @@ -71,7 +71,11 @@ public class SegmenterProcess extends PamProcess { /** * The current segmenter detection group. */ - private SegmenterDetectionGroup[] segmenterDetectionGroup = null; + private SegmenterDetectionGroup[] segmenterDetectionGroup = null; + + private long segmentStart=-1; + + private long segmenterEnd=-1; public SegmenterProcess(DLControl pamControlledUnit, PamDataBlock parentDataBlock) { @@ -219,9 +223,10 @@ public class SegmenterProcess extends PamProcess { */ public void newData(PamDataUnit pamRawData) { +// System.out.println("New data for segmenter: " + pamRawData); + if (!dlControl.getDLParams().useDataSelector || dlControl.getDataSelector().scoreData(pamRawData)>0) { - //System.out.println("New data for segmenter: " + pamRawData); if (pamRawData instanceof RawDataUnit) { newRawDataUnit(pamRawData); } @@ -243,7 +248,7 @@ public class SegmenterProcess extends PamProcess { * A new detection data unit i.e. this is only if we have detection data which is being grouped into segments. * @param dataUnit - the whistle data unit. */ - private void newWhistleData(PamDataUnit dataUnit) { + private synchronized void newWhistleData(PamDataUnit dataUnit) { ConnectedRegionDataUnit whistle = (ConnectedRegionDataUnit) dataUnit; @@ -256,11 +261,16 @@ public class SegmenterProcess extends PamProcess { int index = -1; for (int i=0; i0) { + this.segmenterGroupDataBlock.addPamData(segmenterDetectionGroup[index]); + } + } + + segmenterDetectionGroup[index] = aSegment; +// System.out.println("NEW SEGMENT START!: " + (segmentStart-firstClockUpdate)/1000. + "s" + " " + segmenterDetectionGroup[index].getSegmentStartMillis()+ " " +segmenterDetectionGroup[index]); + + } + private boolean detectionInSegment(PamDataUnit dataUnit, SegmenterDetectionGroup segmenterDetectionGroup2) { return detectionInSegment(dataUnit, segmenterDetectionGroup2.getSegmentStartMillis(), (long) (segmenterDetectionGroup2.getSegmentStartMillis()+segmenterDetectionGroup2.getSegmentDuration())); @@ -308,11 +348,11 @@ public class SegmenterProcess extends PamProcess { private boolean detectionInSegment(PamDataUnit dataUnit, long segStart, long segEnd) { //TODO - this is going to fail for very small segments. long whistleStart = dataUnit.getTimeMilliseconds(); - long whistleEnd = dataUnit.getDurationInMilliseconds().longValue(); + long whistleEnd = whistleStart + dataUnit.getDurationInMilliseconds().longValue(); if ((whistleStart>=segStart && whistleStart=segStart && whistleEnd transforms = new ArrayList(); + transforms.add(new FreqTransform(DLTransformType.SPECRESIZE, new Number[] {Integer.valueOf(64), Integer.valueOf(48)})); + +// +// //set the spec transform +// ((FreqTransform) transforms.get(0)).setSpecTransfrom(whistles2Image.getSpecTransfrom()); +// +// //process all the transforms. +// DLTransform transform = modelTransforms.get(0); +// for (int i =0; i