diff --git a/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDTest.java b/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDTest.java index 722d4cb3..eb8e72d6 100644 --- a/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDTest.java +++ b/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDTest.java @@ -65,7 +65,9 @@ public class DelphinIDTest { String whistleContourPath = "D:/Dropbox/PAMGuard_dev/Deep_Learning/delphinID/testencounter415/whistle_contours.mat"; //the path to the model - String modelPath = "D:/Dropbox/PAMGuard_dev/Deep_Learning/delphinID/testencounter415/whistle_model_2/whistle_4s_415.zip"; +// String modelPath = "D:/Dropbox/PAMGuard_dev/Deep_Learning/delphinID/testencounter415/whistle_model_2/whistle_4s_415.zip"; + String modelPath = "D:/Dropbox/PAMGuard_dev/Deep_Learning/delphinID/testencounter415/whistle_model_3/whistle_4s_415_f5.zip"; + //the path to the model String matImageSave = "C:/Users/Jamie Macaulay/MATLAB Drive/MATLAB/PAMGUARD/deep_learning/delphinID/whistleimages.mat"; diff --git a/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDUtils.java b/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDUtils.java index 0e88bae1..2a359e6d 100644 --- a/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDUtils.java +++ b/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDUtils.java @@ -224,28 +224,34 @@ public class DelphinIDUtils { //segment the whistle detections ArrayList segments = DelphinIDUtils.segmentWhsitleData(whistles, whistles.get(0).getTimeMilliseconds(), segLen, segHop); - + float[][][] images = worker.dataUnits2ModelInput(segments, (float) sampleRate, 0); float[][] image; BufferedImage bfImage; + double density; for (int k=0; k contour = Whistles2Image.whistContours2Points(group); + + //time bin length from the first contour + double[] times = new double[contour.get(0).length-1]; + for (int i=0; i fieldNames = whistlesStruct.getFieldNames(); + File outFolder = new File(imageFolder + File.separator + listOfFiles[i].getName()); + outFolder.mkdir();//make the out folder directory + Struct whistecontours; for (String name: fieldNames) { - System.out.println("Generating images for recording " + name + " from " + listOfFiles[i].getName()); + System.out.println("Generating images for recording " + name + " from " + listOfFiles[i].getName() + " " + lineWidth); if (!name.equals("fftlen") && !name.equals("ffthop") && !name.equals("samplerate")) { whistecontours = whistlesStruct.get(name); + generateImages( whistecontours, (outFolder + File.separator + name) , model, fftLen, fftHop, sampleRate); } } @@ -327,4 +363,32 @@ public class DelphinIDUtils { } } + public static void main(String[] args) { + + // double[] density = new double[] {0.15 - 1.5}; + + //number of whistle bins/number of time bins; either 16 or 21 + //the e contours as csv files. + // String whistlefolder = "/Users/au671271/Library/CloudStorage/Dropbox/PAMGuard_dev/Deep_Learning/delphinID/training/WMD"; +// String whistlefolder = "D:/Dropbox/PAMGuard_dev/Deep_Learning/delphinID/training/WMD_examples/contours"; + String whistlefolder = "D:/Dropbox/PAMGuard_dev/Deep_Learning/delphinID/training/WMD/contours"; + + //the image folder to save to. + // String imageFolder = "/Users/au671271/Library/CloudStorage/Dropbox/PAMGuard_dev/Deep_Learning/delphinID/training/WMD_Images"; +// String imageFolder = "D:/Dropbox/PAMGuard_dev/Deep_Learning/delphinID/training/WMD_examples/images"; + String imageFolder = "C:/Users/Jamie Macaulay/Desktop/Tristan_training_images/contour_images"; + + //the path to the model + // String modelPath = "/Users/au671271/Library/CloudStorage/Dropbox/PAMGuard_dev/Deep_Learning/delphinID/testencounter415/whistle_model_2/whistle_4s_415.zip"; + String modelPath = "D:/Dropbox/PAMGuard_dev/Deep_Learning/delphinID/testencounter415/whistle_model_2/whistle_4s_415.zip"; + + double[] lineWidths = new double[] {6, 7, 10, 15, 20}; + + for (double lineWidth:lineWidths) { + String imageFolderWidth = (imageFolder + "_"+ String.format("%d",(int)lineWidth)); + new File(imageFolderWidth).mkdir(); + generateTrainingData( modelPath, whistlefolder, imageFolderWidth, lineWidth); + } + } + } diff --git a/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDWorker.java b/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDWorker.java index 4a32e7a9..bb3ef58a 100644 --- a/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDWorker.java +++ b/src/rawDeepLearningClassifier/dlClassification/delphinID/DelphinIDWorker.java @@ -42,6 +42,15 @@ public class DelphinIDWorker extends ArchiveModelWorker { */ private Whistle2ImageParams whistleImageParams; + /** + * Get the whislte to image parameters. + * + * @return + */ + public Whistle2ImageParams getWhistleImageParams() { + return whistleImageParams; + } + @Override public void prepModel(StandardModelParams dlParams, DLControl dlControl) { @@ -87,10 +96,12 @@ public class DelphinIDWorker extends ArchiveModelWorker { freqLimits[1] = jsonObjectParams.getFloat("maxfreq"); size[0] = jsonObjectParams.getInt("widthpix"); size[1] = jsonObjectParams.getInt("heightpix"); + double lineWidth = jsonObjectParams.getDouble("linewidthpix"); Whistle2ImageParams whistle2ImageParmas = new Whistle2ImageParams(); whistle2ImageParmas.freqLimits = freqLimits; whistle2ImageParmas.size = size; + whistle2ImageParmas.lineWidth = lineWidth; return whistle2ImageParmas; } diff --git a/src/rawDeepLearningClassifier/dlClassification/delphinID/Whistles2Image.java b/src/rawDeepLearningClassifier/dlClassification/delphinID/Whistles2Image.java index 892043c5..539792da 100644 --- a/src/rawDeepLearningClassifier/dlClassification/delphinID/Whistles2Image.java +++ b/src/rawDeepLearningClassifier/dlClassification/delphinID/Whistles2Image.java @@ -36,7 +36,7 @@ public class Whistles2Image extends FreqTransform { // double[] freqLimits = new double[] {params[0].doubleValue(), params[1].doubleValue()}; // double[] size = new double[] {params[2].doubleValue(), params[3].doubleValue()}; - SpecTransform specTransform = whistleGroupToImage( whistleGroup, params.freqLimits, params.size); + SpecTransform specTransform = whistleGroupToImage( whistleGroup, params.freqLimits, params.size, params.lineWidth); this.setSpecTransfrom(specTransform); this.setFreqlims(params.freqLimits); @@ -50,7 +50,7 @@ public class Whistles2Image extends FreqTransform { * @param freqLimits - the frequency limits * @return the spectrogram transform. */ - private SpecTransform whistleGroupToImage(SegmenterDetectionGroup whistleGroup, double[] freqLimits, double[] size) { + private SpecTransform whistleGroupToImage(SegmenterDetectionGroup whistleGroup, double[] freqLimits, double[] size, double lineWidth) { SpecTransform specTransform = new SpecTransform(); @@ -65,7 +65,7 @@ public class Whistles2Image extends FreqTransform { ArrayList points = whistContours2Points(whistleGroup); //does not work becaue it has to be on the AWT thread. - BufferedImage canvas = makeScatterImage(points, size, new double[]{0, whistleGroup.getSegmentDuration()/1000.}, freqLimits, 10.); + BufferedImage canvas = makeScatterImage(points, size, new double[]{0, whistleGroup.getSegmentDuration()/1000.}, freqLimits, lineWidth); double[][] imaged = new double[(int) size[0]][(int) size[1]]; @@ -90,9 +90,9 @@ public class Whistles2Image extends FreqTransform { /** * Convert a list of whistle contours to a list of time and frequency points. * @param whistleGroup - list of whistle contours within a detection group. - * @return an array with time (milliseconds from start of group) and frequency (Hz) + * @return an array with time (seconds from start of group) and frequency (Hz) */ - private ArrayList whistContours2Points(SegmenterDetectionGroup whistleGroup) { + public static ArrayList whistContours2Points(SegmenterDetectionGroup whistleGroup) { ArrayList contours = new ArrayList(); @@ -212,7 +212,12 @@ public class Whistles2Image extends FreqTransform { */ public double[] freqLimits; - public double[] size; + public double[] size; + + /** + * The line width to draw in pixels + */ + public double lineWidth = 10; } diff --git a/src/rawDeepLearningClassifier/layoutFX/defaultModels/DefaultModelPane.java b/src/rawDeepLearningClassifier/layoutFX/defaultModels/DefaultModelPane.java index 755bd5db..b6b2078d 100644 --- a/src/rawDeepLearningClassifier/layoutFX/defaultModels/DefaultModelPane.java +++ b/src/rawDeepLearningClassifier/layoutFX/defaultModels/DefaultModelPane.java @@ -35,6 +35,9 @@ import rawDeepLearningClassifier.defaultModels.DLModel; */ public class DefaultModelPane extends PamBorderPane{ + private static final double PREF_WIDTH = 200; + + /** * Reference to the deafult model manager that contains the default models. */ @@ -74,7 +77,7 @@ public class DefaultModelPane extends PamBorderPane{ // vBox.setPrefWidth(120); hidingPaneContent= new PamBorderPane(); - hidingPaneContent.setPrefWidth(150); + hidingPaneContent.setPrefWidth(PREF_WIDTH); hidingPane = new HidingPane(Side.RIGHT, hidingPaneContent, vBox, true, 0); PamButton button; @@ -101,12 +104,15 @@ public class DefaultModelPane extends PamBorderPane{ } hidingPane.setStyle("-fx-background-color: -fx-base"); + hidingPane.setPrefWidth(PREF_WIDTH); // this.setStyle("-fx-background-color: -fx-base"); PamStackPane mainHolder = new PamStackPane(); mainHolder.getChildren().addAll(vBox, hidingPane); StackPane.setAlignment(hidingPane, Pos.TOP_RIGHT); + mainHolder.setPrefWidth(PREF_WIDTH); + return mainHolder; } diff --git a/src/rawDeepLearningClassifier/segmenter/SegmenterDetectionGroup.java b/src/rawDeepLearningClassifier/segmenter/SegmenterDetectionGroup.java index 9636a52b..6c152634 100644 --- a/src/rawDeepLearningClassifier/segmenter/SegmenterDetectionGroup.java +++ b/src/rawDeepLearningClassifier/segmenter/SegmenterDetectionGroup.java @@ -50,6 +50,10 @@ public class SegmenterDetectionGroup extends GroupDetection { return segMillis; } + /** + * Get the segment duration in milliseconds. + * @return the segment duration in millis. + */ public double getSegmentDuration() { return segDuration; }