diff --git a/nullPamguardSettings_20171106_185953.psfx b/nullPamguardSettings_20171106_185953.psfx new file mode 100644 index 00000000..b2e2bed1 Binary files /dev/null and b/nullPamguardSettings_20171106_185953.psfx differ diff --git a/pom.xml b/pom.xml index a26861ce..4c649303 100644 --- a/pom.xml +++ b/pom.xml @@ -240,23 +240,6 @@ file://${project.basedir}/repo - - - - - - - - - - - diff --git a/src/dataPlotsFX/TDControlFX.java b/src/dataPlotsFX/TDControlFX.java index 089edd93..2bfd1e83 100644 --- a/src/dataPlotsFX/TDControlFX.java +++ b/src/dataPlotsFX/TDControlFX.java @@ -115,12 +115,12 @@ public class TDControlFX extends TDControl implements UserDisplayNodeFX { System.out.println("TDControldFX: parent datablock null"); return dataBlocks; } + for (int i=0; i iterator = this.getPamDataBlock().getListIterator(PamDataBlock.ITERATOR_END); + ListIterator iterator = this.getDataBlock().getListIterator(PamDataBlock.ITERATOR_END); PamDataUnit testDataUnit; while (iterator.hasPrevious()) { diff --git a/src/dataPlotsFX/data/TDDataInfoFX.java b/src/dataPlotsFX/data/TDDataInfoFX.java index b6f50cef..45185e3f 100644 --- a/src/dataPlotsFX/data/TDDataInfoFX.java +++ b/src/dataPlotsFX/data/TDDataInfoFX.java @@ -731,13 +731,6 @@ public abstract class TDDataInfoFX { return false; } - /** - * @return the pamDataBlock - */ - protected PamDataBlock getPamDataBlock() { - return pamDataBlock; - } - /** * @return the tdDataProvider */ diff --git a/src/dataPlotsFX/data/TDDataProviderRegisterFX.java b/src/dataPlotsFX/data/TDDataProviderRegisterFX.java index da0a3beb..8901845e 100644 --- a/src/dataPlotsFX/data/TDDataProviderRegisterFX.java +++ b/src/dataPlotsFX/data/TDDataProviderRegisterFX.java @@ -80,6 +80,7 @@ public class TDDataProviderRegisterFX { */ synchronized public TDDataProviderFX findDataProvider(PamDataBlock pamDataBlock) { for (TDDataProviderFX aProvider:dataProviders) { +// System.out.println("Data providers: " + aProvider.getName() + " | " + aProvider.getDataBlock() + " | " +pamDataBlock); if (aProvider.getDataBlock()==pamDataBlock) { return aProvider; } diff --git a/src/dataPlotsFX/data/generic/GenericDataPlotInfo.java b/src/dataPlotsFX/data/generic/GenericDataPlotInfo.java index 990e0e97..eddf4d7b 100644 --- a/src/dataPlotsFX/data/generic/GenericDataPlotInfo.java +++ b/src/dataPlotsFX/data/generic/GenericDataPlotInfo.java @@ -294,7 +294,7 @@ public class GenericDataPlotInfo extends TDDataInfoFX { * do some which may be associated with other annotations ? */ protected void updateAvailability() { - LocalisationInfo locInfo = getPamDataBlock().getLocalisationContents(); + LocalisationInfo locInfo = getDataBlock().getLocalisationContents(); bearingScaleInfo.setAvailable(locInfo.hasLocContent(LocContents.HAS_BEARING)); slantScaleInfo.setAvailable(locInfo.hasLocContent(LocContents.HAS_BEARING)); } diff --git a/src/dataPlotsFX/data/generic/GenericLinePlotInfo.java b/src/dataPlotsFX/data/generic/GenericLinePlotInfo.java index affeb7b8..97a06ed9 100644 --- a/src/dataPlotsFX/data/generic/GenericLinePlotInfo.java +++ b/src/dataPlotsFX/data/generic/GenericLinePlotInfo.java @@ -23,8 +23,9 @@ import rawDeepLearningClassifier.dataPlotFX.LineInfo; /** - * A Data Info which plots 1D line data i.e. usually used to plot continuous 1D data e.g. deep learning predictions, - * Ishmael data, click trigger data. + * A Data Info which plots 1D line data i.e. usually used to plot continuous 1D + * data e.g. deep learning predictions, Ishmael data, click trigger data. + * * @author Jamie Macaulay * */ @@ -94,7 +95,7 @@ public abstract class GenericLinePlotInfo extends TDDataInfoFX { } //use the center of the window for plotting - double timeMillis = pamDataUnit.getTimeMilliseconds(); + double timeMillis = pamDataUnit.getTimeMilliseconds()+pamDataUnit.getDurationInMilliseconds()/2; double tC=tdProjector.getTimePix(timeMillis-scrollStart); diff --git a/src/dataPlotsFX/scroller/TDAcousticScroller.java b/src/dataPlotsFX/scroller/TDAcousticScroller.java index 784d3bec..304bd76e 100644 --- a/src/dataPlotsFX/scroller/TDAcousticScroller.java +++ b/src/dataPlotsFX/scroller/TDAcousticScroller.java @@ -144,10 +144,16 @@ public class TDAcousticScroller extends AcousticScrollerFX implements PamSetting createTimeSpinner(); this.settingsPane.setParams(scrollerColourParams); - + updateDataGramColours(scrollerColourParams); } + + private void setSpinnerValue(long millis) { + spinnerCall = true; + spinner.getValueFactory().setValue(millis); + spinnerCall = false; + } boolean spinnerCall = false; @@ -177,9 +183,7 @@ public class TDAcousticScroller extends AcousticScrollerFX implements PamSetting //add a listener so that the spinner changes of the visible amount chnages super.getScrollBarPane().visibleAmountProperty().addListener((obsVal, oldVal, newVal)->{ - spinnerCall = true; - spinner.getValueFactory().setValue(newVal.longValue()); - spinnerCall = false; + setSpinnerValue(newVal.longValue()); }); //add a listener so the visible amount changes of the spinner changes value. @@ -213,6 +217,13 @@ public class TDAcousticScroller extends AcousticScrollerFX implements PamSetting } }); } + + + @Override + public void setVisibleMillis(long visibleAmount) { + super.setVisibleMillis(visibleAmount); + setSpinnerValue(visibleAmount); + } @@ -624,6 +635,7 @@ public class TDAcousticScroller extends AcousticScrollerFX implements PamSetting } + @Override public String getUnitName() { // TODO Auto-generated method stub diff --git a/src/pamViewFX/fxNodes/connectionPane/ConnectionLine.java b/src/pamViewFX/fxNodes/connectionPane/ConnectionLine.java index 9a143cdd..d4219198 100644 --- a/src/pamViewFX/fxNodes/connectionPane/ConnectionLine.java +++ b/src/pamViewFX/fxNodes/connectionPane/ConnectionLine.java @@ -12,6 +12,7 @@ import javafx.scene.shape.Shape; /** * Line which connects a plug or socket to a ConnectionRectangle or other ConnectionLine. + * * @author Jamie Macaulay * */ diff --git a/src/rawDeepLearningClassifier/DLControl.java b/src/rawDeepLearningClassifier/DLControl.java index 06663a8a..f4d21a8b 100644 --- a/src/rawDeepLearningClassifier/DLControl.java +++ b/src/rawDeepLearningClassifier/DLControl.java @@ -275,7 +275,7 @@ public class DLControl extends PamControlledUnit implements PamSettings { TDDataProviderRegisterFX.getInstance() .registerDataInfo(new DLDetectionPlotProvider(this, dlClassifyProcess.getDLDetectionDatablock())); TDDataProviderRegisterFX.getInstance() - .registerDataInfo(new DLPredictionProvider(this, dlClassifyProcess.getDLDetectionDatablock())); + .registerDataInfo(new DLPredictionProvider(this, dlClassifyProcess.getDLPredictionDataBlock())); // register the DD display DDPlotRegister.getInstance() diff --git a/src/rawDeepLearningClassifier/dataPlotFX/DLPredictionPlotInfoFX.java b/src/rawDeepLearningClassifier/dataPlotFX/DLPredictionPlotInfoFX.java index fe3f3efa..e4e31b42 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) { @@ -357,8 +357,8 @@ public class DLPredictionPlotInfoFX extends GenericLinePlotInfo { updateClassNames(); break; } - - + } + } diff --git a/src/rawDeepLearningClassifier/dataPlotFX/DLPredictionProvider.java b/src/rawDeepLearningClassifier/dataPlotFX/DLPredictionProvider.java index 7194bfc2..a75cae0b 100644 --- a/src/rawDeepLearningClassifier/dataPlotFX/DLPredictionProvider.java +++ b/src/rawDeepLearningClassifier/dataPlotFX/DLPredictionProvider.java @@ -5,6 +5,7 @@ import dataPlotsFX.data.TDDataProviderFX; import dataPlotsFX.layout.TDGraphFX; import rawDeepLearningClassifier.DLControl; import rawDeepLearningClassifier.dlClassification.DLDetectionDataBlock; +import rawDeepLearningClassifier.dlClassification.DLModelDataBlock; /** * The DL detection plot provider. @@ -22,10 +23,10 @@ public class DLPredictionProvider extends TDDataProviderFX { /** * The DL detection plot provider. * @param dlControl - reference to DL control. - * @param dlDetectionDataBlock - the dl detection data block. + * @param dlModelDataBlock - the dl detection data block. */ - public DLPredictionProvider(DLControl dlControl, DLDetectionDataBlock dlDetectionDataBlock) { - super(dlDetectionDataBlock); + public DLPredictionProvider(DLControl dlControl, DLModelDataBlock dlModelDataBlock) { + super(dlModelDataBlock); this.dlControl = dlControl; } diff --git a/src/rawDeepLearningClassifier/dlClassification/animalSpot/StandardModelPane.java b/src/rawDeepLearningClassifier/dlClassification/animalSpot/StandardModelPane.java index ae51ea25..ca40321c 100644 --- a/src/rawDeepLearningClassifier/dlClassification/animalSpot/StandardModelPane.java +++ b/src/rawDeepLearningClassifier/dlClassification/animalSpot/StandardModelPane.java @@ -2,12 +2,16 @@ package rawDeepLearningClassifier.dlClassification.animalSpot; import java.io.File; import org.controlsfx.control.CheckComboBox; +import org.controlsfx.control.IndexedCheckModel; import org.controlsfx.control.PopOver; import org.controlsfx.control.ToggleSwitch; import PamController.SettingsPane; import PamUtils.PamArrayUtils; import PamView.dialog.warn.WarnOnce; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.value.ObservableValue; +import javafx.collections.ListChangeListener.Change; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Node; @@ -25,6 +29,7 @@ import pamViewFX.fxNodes.PamGridPane; import pamViewFX.fxNodes.PamHBox; import pamViewFX.fxNodes.PamSpinner; import pamViewFX.fxNodes.PamVBox; +import pamViewFX.validator.PamValidator; import rawDeepLearningClassifier.dlClassification.DLClassiferModel; /** @@ -101,6 +106,8 @@ public abstract class StandardModelPane extends SettingsPane(); gridPane.add(speciesIDBox, 3, 0); - speciesIDBox.setMaxWidth(100); - speciesIDBox.setPrefWidth(100); + //speciesIDBox.setMaxWidth(100); +// speciesIDBox.setPrefWidth(100); speciesIDBox.prefHeightProperty().bind(detectionSpinner.heightProperty()); + + validator = new PamValidator(); + + final SimpleIntegerProperty checkItemsCount = new SimpleIntegerProperty(); + + speciesIDBox.getCheckModel().getCheckedItems().addListener((Change c)->{ + checkItemsCount.set(speciesIDBox.getCheckModel().getCheckedItems().size()); + }); + + + validator.createCheck() + .dependsOn("species_box",checkItemsCount) + .withMethod(c -> { + int nChecked = c.get("species_box"); + + if (nChecked==speciesIDBox.getItems().size()) { + c.warn("All output class are checked. If one of these classes is noise then PAMGuard will continually detect all sound data..."); + } + + if (nChecked==0) { + c.warn("No output classes are checked for binary classification. PAMGuard will save all prediction values but no detections will be generated"); + } + }) + .decorates(speciesIDBox) + .immediate(); + ; vBoxHolder = new PamVBox(); vBoxHolder.setSpacing(5); diff --git a/src/rawDeepLearningClassifier/dlClassification/archiveModel/ArchiveModelClassifier.java b/src/rawDeepLearningClassifier/dlClassification/archiveModel/ArchiveModelClassifier.java index f8a395e6..0c3f2938 100644 --- a/src/rawDeepLearningClassifier/dlClassification/archiveModel/ArchiveModelClassifier.java +++ b/src/rawDeepLearningClassifier/dlClassification/archiveModel/ArchiveModelClassifier.java @@ -167,7 +167,7 @@ public abstract class ArchiveModelClassifier extends StandardClassifierModel { } /** - * Create the parameters class for the model. This can be overridden for bespoke parameters. + *Create the parameters class for the model. This can be overridden for bespoke parameters. *classes. * @return a new parameters class object. */ diff --git a/src/rawDeepLearningClassifier/dlClassification/archiveModel/ArchiveModelWorker.java b/src/rawDeepLearningClassifier/dlClassification/archiveModel/ArchiveModelWorker.java index e694c9e9..ac045382 100644 --- a/src/rawDeepLearningClassifier/dlClassification/archiveModel/ArchiveModelWorker.java +++ b/src/rawDeepLearningClassifier/dlClassification/archiveModel/ArchiveModelWorker.java @@ -14,15 +14,18 @@ import org.jamdev.jdl4pam.ArchiveModel; import org.jamdev.jdl4pam.genericmodel.GenericModelParams; import org.jamdev.jdl4pam.transforms.DLTransform; import org.jamdev.jdl4pam.transforms.DLTransformsFactory; +import org.jamdev.jdl4pam.transforms.FreqTransform; import org.jamdev.jdl4pam.transforms.jsonfile.DLTransformParser2; import org.jamdev.jdl4pam.transforms.jsonfile.DLTransformsParser; import org.json.JSONObject; +import PamUtils.PamArrayUtils; import PamView.dialog.warn.WarnOnce; import ai.djl.MalformedModelException; import rawDeepLearningClassifier.DLControl; import rawDeepLearningClassifier.dlClassification.animalSpot.StandardModelParams; import rawDeepLearningClassifier.dlClassification.genericModel.DLModelWorker; +import rawDeepLearningClassifier.dlClassification.genericModel.GenericModelWorker; import rawDeepLearningClassifier.dlClassification.genericModel.GenericPrediction; /** @@ -33,7 +36,7 @@ import rawDeepLearningClassifier.dlClassification.genericModel.GenericPrediction * @author Jamie Macaulay * */ -public class ArchiveModelWorker extends DLModelWorker { +public class ArchiveModelWorker extends GenericModelWorker { /** @@ -57,6 +60,7 @@ public class ArchiveModelWorker extends DLModelWorker { /** * Prepare the model */ + @Override public void prepModel(StandardModelParams dlParams, DLControl dlControl) { //ClassLoader origCL = Thread.currentThread().getContextClassLoader(); try { @@ -96,10 +100,11 @@ public class ArchiveModelWorker extends DLModelWorker { //read the JSON string from the the file. String jsonString = DLTransformsParser.readJSONString(new File(dlModel.getAudioReprFile())); + //convert the JSON string to a parameters object. GenericModelParams modelParams = makeModelParams( jsonString); - + //important to add this for Ketos models because the JSON string does not necessarily contain and output shape. //System.out.println("----Default output shape: " + ketosParams.defaultOutputShape + " " + ketosModel.getOutShape()); if (modelParams.defaultOutputShape==null) { @@ -108,6 +113,7 @@ public class ArchiveModelWorker extends DLModelWorker { //HACK there seems to be some sort of bug in ketos where the params input shape is correct but the model input shape is wrong. if (dlModel.getInputShape()==null || !dlModel.getInputShape().equals(modelParams.defaultInputShape)) { + System.out.println("Model input shape: " + modelParams.defaultInputShape); WarnOnce.showWarning("Model shape", "The model shape does not match the model metadata. \n Metadata shape will be used used.", WarnOnce.OK_OPTION); dlModel.setInputShape(modelParams.defaultInputShape); } @@ -131,26 +137,35 @@ public class ArchiveModelWorker extends DLModelWorker { //only load new transforms if defaults are selected if (getModelTransforms()==null || dlParams.dlTransfroms==null || dlParams.useDefaultTransfroms) { - System.out.println(" " + transforms); - //System.out.println("SET MODEL TRANSFORMS: " + ketosDLParams.dlTransfroms + " " + ketosDLParams.useDefaultTransfroms); - //only set the transforms if they are null - otherwise handled elsewhere. setModelTransforms(transforms); dlParams.useDefaultTransfroms = true; + dlParams.dlTransfroms=transforms; } else { - //System.out.println("SET CURRENT TRANSFORMS: " + ketosDLParams.dlTransfroms + " " + ketosDLParams.useDefaultTransfroms); //use the old transforms. setModelTransforms(dlParams.dlTransfroms); } + + //set whether a wave or spectrogram model + //this is important for setting the input stack into the model. + setWaveFreqModel(dlParams); + +// //enable softmax? - TODO +// this.setEnableSoftMax(true); //ketosDLParams.dlTransfroms = transforms; //this is done after prep model in the settings pane. - dlParams.defaultSegmentLen = modelParams.segLen*1000.; //the segment length in microseconds. - //ketosParams.classNames = new String[] {"Noise", "Right Whale"}; // FIXME; - + dlParams.defaultSegmentLen = modelParams.segLen; //the segment length in microseconds. + + if (modelParams.classNames!=null) { + dlParams.numClasses = modelParams.classNames.length; + } + else { + dlParams.numClasses = (int) modelParams.defaultOutputShape.get(1); + } //ok 0 the other values are not user selectable but this is. If we relaod the same model we probably want to keep it.... - //So this is a little bt of a hack but will probably be OK in most cases. + //So this is a little bit of a hack but will probably be OK in most cases. if (dlParams.binaryClassification==null || dlParams.binaryClassification.length!=dlParams.numClasses) { dlParams.binaryClassification = new boolean[dlParams.numClasses]; for (int i=0; i { //set the number of class names from the default output shape dlParams.numClasses = (int) modelParams.defaultOutputShape.get(1); } - - // if (dlParams.classNames!=null) { - // for (int i = 0; i { * @throws IOException */ public ArchiveModel loadModel(String currentPath2) throws MalformedModelException, IOException { - //note the the model should have been check for compatibility beforehand - File file = new File(currentPath2); - - String model = getZipFilePath(file, ".py"); - if (model==null) model = getZipFilePath(file, ".pb"); - String settings = getZipFilePath(file, ".pdtf"); - return new SimpleArchiveModel(new File(currentPath2)); } @@ -225,11 +220,11 @@ public class ArchiveModelWorker extends DLModelWorker { - @Override - public float[] runModel(float[][][] transformedDataStack) { - System.out.println("Model input: " + transformedDataStack.length + " " + transformedDataStack[0].length + " " + transformedDataStack[0][0].length); - return dlModel.runModel(transformedDataStack); - } +// @Override +// public float[] runModel(float[][][] transformedDataStack) { +// System.out.println("Model input: " + transformedDataStack.length + " " + transformedDataStack[0].length + " " + transformedDataStack[0][0].length); +// return dlModel.runModel(transformedDataStack); +// } @Override @@ -252,6 +247,7 @@ public class ArchiveModelWorker extends DLModelWorker { * Get the currently loaded mode. * @return - the currently loaded mode. */ + @Override public ArchiveModel getModel() { return dlModel; } diff --git a/src/rawDeepLearningClassifier/dlClassification/archiveModel/PamZipModelClassifier.java b/src/rawDeepLearningClassifier/dlClassification/archiveModel/PamZipModelClassifier.java index 5537fb0b..023a5949 100644 --- a/src/rawDeepLearningClassifier/dlClassification/archiveModel/PamZipModelClassifier.java +++ b/src/rawDeepLearningClassifier/dlClassification/archiveModel/PamZipModelClassifier.java @@ -65,7 +65,7 @@ public class PamZipModelClassifier extends ArchiveModelClassifier { } /** - * Find the first file within a zip folder that matches a pattern. + * Find the first file within a zip folder that matches a pattern. This peaks into the zip file instead of decompressing it. * @param zipUri - uri to the zip file * @param filePattern - the file pattern to match - the file must contain this string. * @return null if no file found and the file pqth if the file is founf diff --git a/src/rawDeepLearningClassifier/dlClassification/archiveModel/SimpleArchiveModel.java b/src/rawDeepLearningClassifier/dlClassification/archiveModel/SimpleArchiveModel.java index db7afaaf..1819c6b0 100644 --- a/src/rawDeepLearningClassifier/dlClassification/archiveModel/SimpleArchiveModel.java +++ b/src/rawDeepLearningClassifier/dlClassification/archiveModel/SimpleArchiveModel.java @@ -28,7 +28,7 @@ public class SimpleArchiveModel extends ArchiveModel { @Override public String getAudioReprRelPath(String zipFolder) { try { - System.out.println("SETTINGS PATH: " + getRelFilePath(zipFolder, ".pdtf")); + //System.out.println("SETTINGS PATH: " + getRelFilePath(zipFolder, ".pdtf")); return getRelFilePath(zipFolder, ".pdtf"); } catch (IOException e) { // TODO Auto-generated catch block @@ -43,7 +43,7 @@ public class SimpleArchiveModel extends ArchiveModel { String model = null; model = getRelFilePath(zipFolder, ".pb"); if (model==null) model = getRelFilePath(zipFolder, ".py"); - System.out.println("MODEL PATH: " +model); + //System.out.println("MODEL PATH: " +model); return model; } catch (IOException e) { @@ -64,14 +64,16 @@ public class SimpleArchiveModel extends ArchiveModel { try (Stream walk = Files.walk(Paths.get(zipFolder))) { List result = walk .filter(p -> !Files.isDirectory(p)) // not a directory - .map(p -> p.toString().toLowerCase()) // convert path to string + .map(p -> p.toString()) // convert path to string .filter(f -> f.endsWith(fileEnd)) // check end with .collect(Collectors.toList()); // collect all matched to a List if (result.size()>0) { String firstFile = result.get(0); - String relative = new File(zipFolder).toURI().relativize(new File(firstFile).toURI()).getPath(); + //System.out.println("First file: " +firstFile); + + String relative = firstFile.replace(zipFolder, ""); return relative; } diff --git a/src/rawDeepLearningClassifier/dlClassification/genericModel/GenericAdvPane.java b/src/rawDeepLearningClassifier/dlClassification/genericModel/GenericAdvPane.java index 875910ea..3d695502 100644 --- a/src/rawDeepLearningClassifier/dlClassification/genericModel/GenericAdvPane.java +++ b/src/rawDeepLearningClassifier/dlClassification/genericModel/GenericAdvPane.java @@ -184,7 +184,6 @@ public class GenericAdvPane extends SettingsPane { defualtShapeSwitch = new PamToggleSwitch("Use model default shape"); defualtShapeSwitch.selectedProperty().addListener((obsval, oldval, newval)->{ - System.out.println("Hello: deafult shape: " + newval); PamArrayUtils.printArray( currentInput.defaultShape); if (newval) { diff --git a/src/rawDeepLearningClassifier/dlClassification/genericModel/GenericDLClassifier.java b/src/rawDeepLearningClassifier/dlClassification/genericModel/GenericDLClassifier.java index 04ded702..418134a0 100644 --- a/src/rawDeepLearningClassifier/dlClassification/genericModel/GenericDLClassifier.java +++ b/src/rawDeepLearningClassifier/dlClassification/genericModel/GenericDLClassifier.java @@ -121,13 +121,12 @@ public class GenericDLClassifier extends StandardClassifierModel { genericModelParams.dlTransfromParams=dlTransformParams; - if (genericModelParams.dlTransfromParams!=null) { - System.out.println("Generic settings have been saved. : " + genericModelParams.dlTransfromParams.size()); - } - else { - System.out.println("Generic settings have been saved. : " + null); - - } +// if (genericModelParams.dlTransfromParams!=null) { +// System.out.println("Generic settings have been saved. : " + genericModelParams.dlTransfromParams.size()); +// } +// else { +// System.out.println("Generic settings have been saved. : " + null); +// } return genericModelParams; } @@ -211,6 +210,8 @@ public class GenericDLClassifier extends StandardClassifierModel { */ public static boolean isBinaryResult(GenericPrediction modelResult, StandardModelParams genericModelParams) { for (int i=0; igenericModelParams.threshold && genericModelParams.binaryClassification[i]) { // System.out.println("SoundSpotClassifier: prediciton: " + i + " passed threshold with val: " + modelResult.getPrediction()[i]); return true; diff --git a/src/rawDeepLearningClassifier/dlClassification/genericModel/GenericModelWorker.java b/src/rawDeepLearningClassifier/dlClassification/genericModel/GenericModelWorker.java index 3979be84..9a2caae9 100644 --- a/src/rawDeepLearningClassifier/dlClassification/genericModel/GenericModelWorker.java +++ b/src/rawDeepLearningClassifier/dlClassification/genericModel/GenericModelWorker.java @@ -33,19 +33,21 @@ public class GenericModelWorker extends DLModelWorker { @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[0][0][0]); +// System.out.println("RUN GENERIC MODEL: " + transformedDataStack[0][0][0]); float[] results; if (freqTransform) - results = genericModel.runModel(transformedDataStack); + results = getModel().runModel(transformedDataStack); else { //run a model if it is waveform info. float[][] waveStack = new float[transformedDataStack.length][]; for (int i=0; i { setModelTransforms(genericParams.dlTransfroms); //is this a waveform or a spectrogram model? - DLTransform transform = genericParams.dlTransfroms.get(genericParams.dlTransfroms.size()-1); - if (transform instanceof FreqTransform) { - freqTransform = true; - } - else { - freqTransform = false; - } + setWaveFreqModel(genericParams); //use softmax or not? String extension = FilenameUtils.getExtension(genericParams.modelPath); @@ -131,6 +127,18 @@ public class GenericModelWorker extends DLModelWorker { //Thread.currentThread().setContextClassLoader(origCL); } + + protected void setWaveFreqModel(StandardModelParams genericParams) { + //is this a waveform or a spectrogram model? + DLTransform transform = genericParams.dlTransfroms.get(genericParams.dlTransfroms.size()-1); + if (transform instanceof FreqTransform) { + freqTransform = true; + } + else { + freqTransform = false; + } + } + /** * Convert a long[] array to a Long[] array. * @param inArr - the input long[] array. diff --git a/src/rawDeepLearningClassifier/dlClassification/ketos/KetosWorker2.java b/src/rawDeepLearningClassifier/dlClassification/ketos/KetosWorker2.java index 89165d29..a77c1abd 100644 --- a/src/rawDeepLearningClassifier/dlClassification/ketos/KetosWorker2.java +++ b/src/rawDeepLearningClassifier/dlClassification/ketos/KetosWorker2.java @@ -32,6 +32,8 @@ public class KetosWorker2 extends ArchiveModelWorker { public GenericModelParams makeModelParams(String jsonString) { //ketos parameters are non standard and need a bit of extra work to get right. //This also deal with legacy paramters. - return new KetosParams(jsonString); + KetosParams params = new KetosParams(jsonString); +// System.out.println(params); + return params; } } diff --git a/src/rawDeepLearningClassifier/layoutFX/DLModelSelectPane.java b/src/rawDeepLearningClassifier/layoutFX/DLModelSelectPane.java index 2d6a8e22..7f3d8565 100644 --- a/src/rawDeepLearningClassifier/layoutFX/DLModelSelectPane.java +++ b/src/rawDeepLearningClassifier/layoutFX/DLModelSelectPane.java @@ -377,6 +377,7 @@ public class DLModelSelectPane extends PamBorderPane { //we are loading model from a file - anything can happen so put in a try catch. DLStatus status = currentClassifierModel.setModel(file); + if (status.isError()) { System.err.println("Model load failed: " + currentClassifierModel.getModelStatus()); currentClassifierModel=null; @@ -437,7 +438,7 @@ public class DLModelSelectPane extends PamBorderPane { pathLabel.setText("No classifier model loaded: Select model"); pathLabel.setTooltip(new Tooltip("Use the browse button/ URI botton to select a model or select a default model")); } - if (currentClassifierModel.getModelStatus().isError()) { + else if (currentClassifierModel.getModelStatus().isError()) { pathLabel.setGraphic(createErrorIcon(currentClassifierModel.getModelStatus())); pathLabel.setText(currentClassifierModel.getModelStatus().getName()); pathLabel.setTooltip(new Tooltip(currentClassifierModel.getModelStatus().getDescription())); diff --git a/src/rawDeepLearningClassifier/layoutFX/DLSettingsPane.java b/src/rawDeepLearningClassifier/layoutFX/DLSettingsPane.java index ba4cfa80..b07fe4fc 100644 --- a/src/rawDeepLearningClassifier/layoutFX/DLSettingsPane.java +++ b/src/rawDeepLearningClassifier/layoutFX/DLSettingsPane.java @@ -20,8 +20,10 @@ import javafx.scene.control.Label; import javafx.scene.control.Spinner; import javafx.scene.control.Tooltip; import javafx.scene.control.Alert.AlertType; +import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; +import javafx.scene.layout.Priority; import pamViewFX.PamGuiManagerFX; import pamViewFX.fxGlyphs.PamGlyphDude; import pamViewFX.fxNodes.PamBorderPane; @@ -48,7 +50,7 @@ public class DLSettingsPane extends SettingsPane{ public static double MAX_WIDTH = 270; - + /** * The source for the FFT data source. */ @@ -64,10 +66,10 @@ public class DLSettingsPane extends SettingsPane{ */ private PamBorderPane mainPane; -// /** -// * Combo box which allows users to select model. -// */ -// private ComboBox dlModelBox; + // /** + // * Combo box which allows users to select model. + // */ + // private ComboBox dlModelBox; /** * The window length spinner for the segmenter process @@ -112,9 +114,9 @@ public class DLSettingsPane extends SettingsPane{ private Label infoLabel; private DLModelSelectPane modelSelectPane; - - + + public DLSettingsPane(DLControl dlControl){ super(null); this.dlControl=dlControl; @@ -126,19 +128,19 @@ public class DLSettingsPane extends SettingsPane{ // stage.sizeToScene(); // }); // this.setTop(newButton); - - + + mainPane=new PamBorderPane(); mainPane.setCenter(createDLPane()); mainPane.setPadding(new Insets(5,5,5,5)); - + if (!PamGUIManager.isFX()){ mainPane.setMinHeight(430); mainPane.setMaxWidth(MAX_WIDTH); mainPane.setPrefWidth(MAX_WIDTH); } //this.getAdvPane().setMaxWidth(MAX_WIDTH); - + //mainPane.getStylesheets().add(PamStylesManagerFX.getPamStylesManagerFX().getCurStyle().getDialogCSS()); @@ -162,14 +164,14 @@ public class DLSettingsPane extends SettingsPane{ vBox.getChildren().add(sourcePane); sourcePane.prefWidthProperty().bind(vBox.widthProperty()); sourcePane.setMaxWidth(Double.MAX_VALUE); - + sourcePane.getDataBlockBox().setOnAction((action)->{ //need to create a data selector if one exists. this.dlControl.createDataSelector(getSelectedParentDataBlock()); //enable the controls to show a data selector or not. enableControls(); }); - + //create the detection vBox.getChildren().add(createDataSelectorPane()); @@ -193,14 +195,14 @@ public class DLSettingsPane extends SettingsPane{ hopLength.valueProperty().addListener((obsVal, oldVal, newVal)->{ setSegInfoLabel(); }); - + reMergeSeg = new PamSpinner(0, Integer.MAX_VALUE, 1, 1); reMergeSeg.getStyleClass().add(Spinner.STYLE_CLASS_SPLIT_ARROWS_HORIZONTAL); reMergeSeg.setEditable(true); //button to set default hop size Button defaultButton = new Button(); -// defaultButton.setGraphic(PamGlyphDude.createPamGlyph(MaterialDesignIcon.REFRESH, PamGuiManagerFX.iconSize-3)); + // defaultButton.setGraphic(PamGlyphDude.createPamGlyph(MaterialDesignIcon.REFRESH, PamGuiManagerFX.iconSize-3)); defaultButton.setGraphic(PamGlyphDude.createPamIcon("mdi2r-refresh", PamGuiManagerFX.iconSize-3)); defaultButton.setTooltip(new Tooltip("Set default hop size")); defaultButton.setOnAction((action)->{ @@ -208,6 +210,14 @@ public class DLSettingsPane extends SettingsPane{ }); PamGridPane segmenterGridPane = new PamGridPane(); + segmenterGridPane.setHgap(5); + + ColumnConstraints col1 = new ColumnConstraints(); + col1.setHgrow( Priority.SOMETIMES ); + ColumnConstraints col2 = new ColumnConstraints(); + col2.setHgrow( Priority.ALWAYS ); + segmenterGridPane.getColumnConstraints().addAll(col1, col2 ); + segmenterGridPane.add(new Label("Window length"), 0, 0); segmenterGridPane.add(windowLength, 1, 0); segmenterGridPane.add(new Label("samples"), 2, 0); @@ -222,40 +232,40 @@ public class DLSettingsPane extends SettingsPane{ segmenterGridPane.add(new Label("segments"), 2, 2); vBox.getChildren().add(segmenterGridPane); - + vBox.getChildren().add(infoLabel = new Label()); Label label2 = new Label("Deep Learning Model"); label2.setPadding(new Insets(5,0,0,0)); PamGuiManagerFX.titleFont2style(label2); - + vBox.getChildren().add(label2); - + /** * Pane which allows users to select a model type. */ - modelSelectPane = new DLModelSelectPane(this); + modelSelectPane = new DLModelSelectPane(this); -// //add the possible deep learning models. -// dlModelBox= new ComboBox(); -// for (int i=0; i{ -// setClassifierPane(); -// if (mainPane!=null) { -// if (mainPane.getScene().getWindow() instanceof Stage) { -// Stage stage = (Stage) mainPane.getScene().getWindow(); -// stage.sizeToScene(); -// } -// } -// //this.dlControl.getAnnotationType().getSymbolModifier(symbolChooser). -// }); -// -// vBox.getChildren().add(dlModelBox); + // //add the possible deep learning models. + // dlModelBox= new ComboBox(); + // for (int i=0; i{ + // setClassifierPane(); + // if (mainPane!=null) { + // if (mainPane.getScene().getWindow() instanceof Stage) { + // Stage stage = (Stage) mainPane.getScene().getWindow(); + // stage.sizeToScene(); + // } + // } + // //this.dlControl.getAnnotationType().getSymbolModifier(symbolChooser). + // }); + // + // vBox.getChildren().add(dlModelBox); classifierPane = new PamBorderPane(); @@ -265,7 +275,7 @@ public class DLSettingsPane extends SettingsPane{ return vBox; } - + /** * Create the data selector. * @return the data selector. @@ -274,13 +284,13 @@ public class DLSettingsPane extends SettingsPane{ dataSelectorPane = new PamHBox(); dataSelectorPane.setSpacing(5); dataSelectorPane.setAlignment(Pos.CENTER_LEFT); - + dataSelectorCheckBox = new PamToggleSwitch("Detection Selector"); dataSelectorCheckBox.selectedProperty().addListener((obsval, oldval, newval)->{ enableControls(); }); dataSelectorButton = new PamButton(); -// dataSelectorButton.setGraphic(PamGlyphDude.createPamGlyph(MaterialIcon.SETTINGS, PamGuiManagerFX.iconSize)); + // dataSelectorButton.setGraphic(PamGlyphDude.createPamGlyph(MaterialIcon.SETTINGS, PamGuiManagerFX.iconSize)); dataSelectorButton.setGraphic(PamGlyphDude.createPamIcon("mdi2c-cog", PamGuiManagerFX.iconSize)); dataSelectorButton.setOnAction((action)->{ showAdvPane(); @@ -288,7 +298,7 @@ public class DLSettingsPane extends SettingsPane{ dataSelectorPane.getChildren().addAll(dataSelectorCheckBox, dataSelectorButton); return dataSelectorPane; } - + /** * Set extra information in the info label. */ @@ -306,7 +316,7 @@ public class DLSettingsPane extends SettingsPane{ } infoLabel.setText(text); } - + /** * Creates pane allowing the user to change fine scale things such as error limits. * @return the pop over pane. @@ -327,7 +337,7 @@ public class DLSettingsPane extends SettingsPane{ popOver.show(dataSelectorButton); } - + /** * Enable the controls. */ @@ -338,10 +348,10 @@ public class DLSettingsPane extends SettingsPane{ //^bit messy but cannot think of a better way to do it. this.dataSelectorPane.setVisible(false); } - + dataSelectorButton.setDisable(!dataSelectorCheckBox.isSelected()); } - + /** @@ -368,9 +378,9 @@ public class DLSettingsPane extends SettingsPane{ protected void setClassifierPane() { //set the classifier Pane.class if (modelSelectPane.currentClassifierModel!=null && modelSelectPane.currentClassifierModel.getModelUI()!=null) { - + classifierPane.setCenter(modelSelectPane.currentClassifierModel.getModelUI().getSettingsPane().getContentNode()); - + if (modelSelectPane.currentClassifierModel!=null) { modelSelectPane.currentClassifierModel.getModelUI().setParams(); } @@ -400,8 +410,8 @@ public class DLSettingsPane extends SettingsPane{ } sourcePane.getParams(currParams.groupedSourceParams); - -// currParams.modelSelection = dlModelBox.getSelectionModel().getSelectedIndex(); + + // currParams.modelSelection = dlModelBox.getSelectionModel().getSelectedIndex(); if (windowLength.getValue() == 0 || hopLength.getValue()==0){ Platform.runLater(()->{ @@ -413,8 +423,8 @@ public class DLSettingsPane extends SettingsPane{ currParams.rawSampleSize = windowLength.getValue(); currParams.sampleHop = hopLength.getValue(); currParams.maxMergeHops = reMergeSeg.getValue(); - - + + if (modelSelectPane.currentClassifierModel == null) { currParams.modelSelection = -1; } @@ -423,28 +433,28 @@ public class DLSettingsPane extends SettingsPane{ } -// //update any changes -// if (this.dlControl.getDLModels().get(dlModelBox.getSelectionModel().getSelectedIndex()).getModelUI()!=null){ -// this.dlControl.getDLModels().get(dlModelBox.getSelectionModel().getSelectedIndex()).getModelUI().getParams(); -// -// //display any warnings from the settings. -// ArrayList warnings = this.dlControl.getDLModels().get(dlModelBox.getSelectionModel().getSelectedIndex()).checkSettingsOK(); -// showWarnings(warnings); -// -// for (int i=0; i1) { -// //Serious error. Do not close dialog. -// return null; -// } -// } -// } - + // //update any changes + // if (this.dlControl.getDLModels().get(dlModelBox.getSelectionModel().getSelectedIndex()).getModelUI()!=null){ + // this.dlControl.getDLModels().get(dlModelBox.getSelectionModel().getSelectedIndex()).getModelUI().getParams(); + // + // //display any warnings from the settings. + // ArrayList warnings = this.dlControl.getDLModels().get(dlModelBox.getSelectionModel().getSelectedIndex()).checkSettingsOK(); + // showWarnings(warnings); + // + // for (int i=0; i1) { + // //Serious error. Do not close dialog. + // return null; + // } + // } + // } + currParams.useDataSelector = dataSelectorCheckBox.isSelected(); if (dlControl.getDataSelector()!=null) { dlControl.getDataSelector().getDialogPaneFX().getParams(true); } - - + + //need to make sure we call get params for the current model when the oK button is pressed. if (this.modelSelectPane.currentClassifierModel!=null) { if (this.modelSelectPane.currentClassifierModel.getModelUI()!=null) { @@ -453,16 +463,16 @@ public class DLSettingsPane extends SettingsPane{ } currParams.modelURI = this.modelSelectPane.currentSelectedFile; - + return currParams; } - - + + public static PamWarning statusToWarnings(DLStatus dlStatus) { PamWarning pamWarning = new PamWarning(dlStatus.getName(), dlStatus.getDescription(), dlStatus.isError() ? 2 : 1); return pamWarning; } - + /** * Show a warning dialog for the status * @param the status to show @@ -472,7 +482,7 @@ public class DLSettingsPane extends SettingsPane{ dlWarnings.add(statusToWarnings(dlWarning)); showWarning(dlWarnings); } - + /** * Show a warning dialog. * @param the warning to show. @@ -489,12 +499,12 @@ public class DLSettingsPane extends SettingsPane{ * @param dlWarnings - list of warnings - the most important will be shown. */ public void showWarning(ArrayList dlWarnings) { - + if (dlWarnings==null || dlWarnings.size()<1) return; - + String warnings =""; - - + + boolean error = false; for (int i=0; i{ error=true; } } - + final String warningsF = warnings; final boolean errorF = error; Platform.runLater(()->{ WarnOnce.showWarningFX(null, "Deep Learning Settings Warning", warningsF , errorF ? AlertType.ERROR : AlertType.WARNING); -// WarnOnce.showWarning( "Deep Learning Settings Warning", warningsF , WarnOnce.WARNING_MESSAGE); + // WarnOnce.showWarning( "Deep Learning Settings Warning", warningsF , WarnOnce.WARNING_MESSAGE); }); - + //user presses OK - these warnings are just a message - they do not prevent running the module. } @@ -518,35 +528,35 @@ public class DLSettingsPane extends SettingsPane{ sourcePane.setParams(currParams.groupedSourceParams); sourcePane.sourceChanged(); - - + + dlControl.createDataSelector(sourcePane.getSource()); - + //set the classifier model. if (currParams.modelURI !=null) { modelSelectPane.currentClassifierModel = dlControl.getDLModel(); } -// dlModelBox.getSelectionModel().select(currParams.modelSelection); + // dlModelBox.getSelectionModel().select(currParams.modelSelection); windowLength.getValueFactory().setValue(currParams.rawSampleSize); hopLength.getValueFactory().setValue(currParams.sampleHop); reMergeSeg.getValueFactory().setValue(currParams.maxMergeHops); - + dataSelectorCheckBox.setSelected(currParams.useDataSelector); setClassifierPane(); - + enableControls(); - + setSegInfoLabel(); - -// //set up the model and the custom pane if necessary. + + // //set up the model and the custom pane if necessary. this.modelSelectPane.loadNewModel(currParams.modelURI); //this.modelSelectPane.updatePathLabel(); this.setClassifierPane(); - + //For some reason, in the FX GUI, this causes a root used in multiple scenes exceptions...not sure why. Platform.runLater(()->{ sourcePane.getChannelValidator().validate(); @@ -598,23 +608,23 @@ public class DLSettingsPane extends SettingsPane{ */ public void setSegmentLength(Double defaultSegmentLen) { if (defaultSegmentLen==null) return; - - + + double sR = getDLControl().getSettingsPane().getSelectedParentDataBlock().getSampleRate(); - + System.out.println("Set the segment length: " + defaultSegmentLen + " sR " + sR); //automatically set the default segment length. getDLControl().getSettingsPane().getSegmentLenSpinner().getValueFactory().setValue((int) (sR*defaultSegmentLen/1000.)); } - + /** * Convenience class to set the hop length in samples from milliseconds * @param defaultSegmentLen - the segment length in milliseconds. */ public void setHopLength(Double hopLength) { if (hopLength==null) return; - + double sR = getDLControl().getSettingsPane().getSelectedParentDataBlock().getSampleRate(); //automatically set the default segment length. getDLControl().getSettingsPane().getHopLenSpinner().getValueFactory().setValue((int) (sR*hopLength/1000.)); diff --git a/src/rawDeepLearningClassifier/logging/DLDataUnitDatagram.java b/src/rawDeepLearningClassifier/logging/DLDataUnitDatagram.java index 8a17a2cd..702bccc3 100644 --- a/src/rawDeepLearningClassifier/logging/DLDataUnitDatagram.java +++ b/src/rawDeepLearningClassifier/logging/DLDataUnitDatagram.java @@ -31,6 +31,8 @@ public class DLDataUnitDatagram implements DatagramProvider { public int addDatagramData(PamDataUnit dataUnit, float[] dataGramLine) { DLDataUnit dlDataUnit = (DLDataUnit) dataUnit; + if (dataGramLine==null || dataGramLine.length==0) return 0; + if (dlDataUnit.getPredicitionResult().getPrediction()!=null) { for (int i=0; i