Implement zip model for deep learning classifier.

Implement zip models which allow packaging of deep learning models with metadata\
Fix TDdsiplayFX spinner bug
Bug fixes for deep learning module after testing
Implement a validator to warn if users have selected all or no classes for binary classifcation.
This commit is contained in:
Jamie Mac 2024-03-01 15:23:16 +00:00
parent 98e7d55034
commit 45bf890a62
25 changed files with 248 additions and 202 deletions

Binary file not shown.

17
pom.xml
View File

@ -240,23 +240,6 @@
<url>file://${project.basedir}/repo</url> <url>file://${project.basedir}/repo</url>
</repository> </repository>
<!-- Repo for Jamie's code -->
<!-- IMPORTANT: SOMEHOW THIS REPO INTERFERES WITH THE
JAVAFX DEPENDENCIES. Don't understand how, but it
does. If Maven is not downloading the JavaFX dependencies
and is instead throwing errors, try commenting out this
repository. Let Maven download the JavaFX files, and
then uncomment this repo again.
Same thing seems to be occurring if I try to update the postgresql library. -->
<!-- <repository> -->
<!-- <snapshots> -->
<!-- <enabled>false</enabled> -->
<!-- </snapshots> -->
<!-- <id>central</id> -->
<!-- <name>a0u0ltozdsehx-artifactory-primary-0-releases</name> -->
<!-- <url>https://jmachund.jfrog.io/artifactory/jpam2</url> -->
<!-- </repository> -->
<!-- Repo for netCDF --> <!-- Repo for netCDF -->
<repository> <repository>
<snapshots> <snapshots>

View File

@ -115,12 +115,12 @@ public class TDControlFX extends TDControl implements UserDisplayNodeFX {
System.out.println("TDControldFX: parent datablock null"); System.out.println("TDControldFX: parent datablock null");
return dataBlocks; return dataBlocks;
} }
for (int i=0; i<tdDisplayController.getUserDisplayProcess().getNumMuiltiplexDataBlocks(); i++){ for (int i=0; i<tdDisplayController.getUserDisplayProcess().getNumMuiltiplexDataBlocks(); i++){
dataBlock=this.tdDisplayController.getUserDisplayProcess().getMuiltiplexDataBlock(i); dataBlock=this.tdDisplayController.getUserDisplayProcess().getMuiltiplexDataBlock(i);
if (TDDataProviderRegisterFX.getInstance().findDataProvider(dataBlock)!=null){ if (TDDataProviderRegisterFX.getInstance().findDataProvider(dataBlock)!=null){
dataBlocks.add(dataBlock); dataBlocks.add(dataBlock);
} }
// System.out.println("TDControldFX: parent data block "+dataBlock.getDataName());
} }
return dataBlocks; return dataBlocks;
} }

View File

@ -517,7 +517,7 @@ public class ClickPlotInfoFX extends TDDataInfoFX {
if (pamDataUnit.getSuperDetectionsCount()==0) return null; if (pamDataUnit.getSuperDetectionsCount()==0) return null;
ListIterator<PamDataUnit> iterator = this.getPamDataBlock().getListIterator(PamDataBlock.ITERATOR_END); ListIterator<PamDataUnit> iterator = this.getDataBlock().getListIterator(PamDataBlock.ITERATOR_END);
PamDataUnit testDataUnit; PamDataUnit testDataUnit;
while (iterator.hasPrevious()) { while (iterator.hasPrevious()) {

View File

@ -731,13 +731,6 @@ public abstract class TDDataInfoFX {
return false; return false;
} }
/**
* @return the pamDataBlock
*/
protected PamDataBlock getPamDataBlock() {
return pamDataBlock;
}
/** /**
* @return the tdDataProvider * @return the tdDataProvider
*/ */

View File

@ -80,6 +80,7 @@ public class TDDataProviderRegisterFX {
*/ */
synchronized public TDDataProviderFX findDataProvider(PamDataBlock pamDataBlock) { synchronized public TDDataProviderFX findDataProvider(PamDataBlock pamDataBlock) {
for (TDDataProviderFX aProvider:dataProviders) { for (TDDataProviderFX aProvider:dataProviders) {
// System.out.println("Data providers: " + aProvider.getName() + " | " + aProvider.getDataBlock() + " | " +pamDataBlock);
if (aProvider.getDataBlock()==pamDataBlock) { if (aProvider.getDataBlock()==pamDataBlock) {
return aProvider; return aProvider;
} }

View File

@ -294,7 +294,7 @@ public class GenericDataPlotInfo extends TDDataInfoFX {
* do some which may be associated with other annotations ? * do some which may be associated with other annotations ?
*/ */
protected void updateAvailability() { protected void updateAvailability() {
LocalisationInfo locInfo = getPamDataBlock().getLocalisationContents(); LocalisationInfo locInfo = getDataBlock().getLocalisationContents();
bearingScaleInfo.setAvailable(locInfo.hasLocContent(LocContents.HAS_BEARING)); bearingScaleInfo.setAvailable(locInfo.hasLocContent(LocContents.HAS_BEARING));
slantScaleInfo.setAvailable(locInfo.hasLocContent(LocContents.HAS_BEARING)); slantScaleInfo.setAvailable(locInfo.hasLocContent(LocContents.HAS_BEARING));
} }

View File

@ -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, * A Data Info which plots 1D line data i.e. usually used to plot continuous 1D
* Ishmael data, click trigger data. * data e.g. deep learning predictions, Ishmael data, click trigger data.
*
* @author Jamie Macaulay * @author Jamie Macaulay
* *
*/ */
@ -94,7 +95,7 @@ public abstract class GenericLinePlotInfo extends TDDataInfoFX {
} }
//use the center of the window for plotting //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); double tC=tdProjector.getTimePix(timeMillis-scrollStart);

View File

@ -144,10 +144,16 @@ public class TDAcousticScroller extends AcousticScrollerFX implements PamSetting
createTimeSpinner(); createTimeSpinner();
this.settingsPane.setParams(scrollerColourParams); this.settingsPane.setParams(scrollerColourParams);
updateDataGramColours(scrollerColourParams); updateDataGramColours(scrollerColourParams);
} }
private void setSpinnerValue(long millis) {
spinnerCall = true;
spinner.getValueFactory().setValue(millis);
spinnerCall = false;
}
boolean 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 //add a listener so that the spinner changes of the visible amount chnages
super.getScrollBarPane().visibleAmountProperty().addListener((obsVal, oldVal, newVal)->{ super.getScrollBarPane().visibleAmountProperty().addListener((obsVal, oldVal, newVal)->{
spinnerCall = true; setSpinnerValue(newVal.longValue());
spinner.getValueFactory().setValue(newVal.longValue());
spinnerCall = false;
}); });
//add a listener so the visible amount changes of the spinner changes value. //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 @Override
public String getUnitName() { public String getUnitName() {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View File

@ -12,6 +12,7 @@ import javafx.scene.shape.Shape;
/** /**
* Line which connects a plug or socket to a ConnectionRectangle or other ConnectionLine. * Line which connects a plug or socket to a ConnectionRectangle or other ConnectionLine.
*
* @author Jamie Macaulay * @author Jamie Macaulay
* *
*/ */

View File

@ -275,7 +275,7 @@ public class DLControl extends PamControlledUnit implements PamSettings {
TDDataProviderRegisterFX.getInstance() TDDataProviderRegisterFX.getInstance()
.registerDataInfo(new DLDetectionPlotProvider(this, dlClassifyProcess.getDLDetectionDatablock())); .registerDataInfo(new DLDetectionPlotProvider(this, dlClassifyProcess.getDLDetectionDatablock()));
TDDataProviderRegisterFX.getInstance() TDDataProviderRegisterFX.getInstance()
.registerDataInfo(new DLPredictionProvider(this, dlClassifyProcess.getDLDetectionDatablock())); .registerDataInfo(new DLPredictionProvider(this, dlClassifyProcess.getDLPredictionDataBlock()));
// register the DD display // register the DD display
DDPlotRegister.getInstance() DDPlotRegister.getInstance()

View File

@ -94,7 +94,7 @@ public class DLPredictionPlotInfoFX extends GenericLinePlotInfo {
if (getDlControl().getDLModel()!=null) { if (getDlControl().getDLModel()!=null) {
DLClassName[] classNames = getDlControl().getDLModel().getClassNames(); 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) { if (classNames!=null) {
@ -357,8 +357,8 @@ public class DLPredictionPlotInfoFX extends GenericLinePlotInfo {
updateClassNames(); updateClassNames();
break; break;
} }
} }
} }

View File

@ -5,6 +5,7 @@ import dataPlotsFX.data.TDDataProviderFX;
import dataPlotsFX.layout.TDGraphFX; import dataPlotsFX.layout.TDGraphFX;
import rawDeepLearningClassifier.DLControl; import rawDeepLearningClassifier.DLControl;
import rawDeepLearningClassifier.dlClassification.DLDetectionDataBlock; import rawDeepLearningClassifier.dlClassification.DLDetectionDataBlock;
import rawDeepLearningClassifier.dlClassification.DLModelDataBlock;
/** /**
* The DL detection plot provider. * The DL detection plot provider.
@ -22,10 +23,10 @@ public class DLPredictionProvider extends TDDataProviderFX {
/** /**
* The DL detection plot provider. * The DL detection plot provider.
* @param dlControl - reference to DL control. * @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) { public DLPredictionProvider(DLControl dlControl, DLModelDataBlock dlModelDataBlock) {
super(dlDetectionDataBlock); super(dlModelDataBlock);
this.dlControl = dlControl; this.dlControl = dlControl;
} }

View File

@ -2,12 +2,16 @@ package rawDeepLearningClassifier.dlClassification.animalSpot;
import java.io.File; import java.io.File;
import org.controlsfx.control.CheckComboBox; import org.controlsfx.control.CheckComboBox;
import org.controlsfx.control.IndexedCheckModel;
import org.controlsfx.control.PopOver; import org.controlsfx.control.PopOver;
import org.controlsfx.control.ToggleSwitch; import org.controlsfx.control.ToggleSwitch;
import PamController.SettingsPane; import PamController.SettingsPane;
import PamUtils.PamArrayUtils; import PamUtils.PamArrayUtils;
import PamView.dialog.warn.WarnOnce; 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.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Node; import javafx.scene.Node;
@ -25,6 +29,7 @@ import pamViewFX.fxNodes.PamGridPane;
import pamViewFX.fxNodes.PamHBox; import pamViewFX.fxNodes.PamHBox;
import pamViewFX.fxNodes.PamSpinner; import pamViewFX.fxNodes.PamSpinner;
import pamViewFX.fxNodes.PamVBox; import pamViewFX.fxNodes.PamVBox;
import pamViewFX.validator.PamValidator;
import rawDeepLearningClassifier.dlClassification.DLClassiferModel; import rawDeepLearningClassifier.dlClassification.DLClassiferModel;
/** /**
@ -101,6 +106,8 @@ public abstract class StandardModelPane extends SettingsPane<StandardModelParams
* Model indicator. * Model indicator.
*/ */
private ProgressIndicator modelLoadIndicator; private ProgressIndicator modelLoadIndicator;
PamValidator validator;
@ -191,9 +198,35 @@ public abstract class StandardModelPane extends SettingsPane<StandardModelParams
gridPane.add(new Label(""), 2, 0); gridPane.add(new Label(""), 2, 0);
speciesIDBox = new CheckComboBox<String>(); speciesIDBox = new CheckComboBox<String>();
gridPane.add(speciesIDBox, 3, 0); gridPane.add(speciesIDBox, 3, 0);
speciesIDBox.setMaxWidth(100); //speciesIDBox.setMaxWidth(100);
speciesIDBox.setPrefWidth(100); // speciesIDBox.setPrefWidth(100);
speciesIDBox.prefHeightProperty().bind(detectionSpinner.heightProperty()); speciesIDBox.prefHeightProperty().bind(detectionSpinner.heightProperty());
validator = new PamValidator();
final SimpleIntegerProperty checkItemsCount = new SimpleIntegerProperty();
speciesIDBox.getCheckModel().getCheckedItems().addListener((Change<? extends String> 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 = new PamVBox();
vBoxHolder.setSpacing(5); vBoxHolder.setSpacing(5);

View File

@ -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. *classes.
* @return a new parameters class object. * @return a new parameters class object.
*/ */

View File

@ -14,15 +14,18 @@ import org.jamdev.jdl4pam.ArchiveModel;
import org.jamdev.jdl4pam.genericmodel.GenericModelParams; import org.jamdev.jdl4pam.genericmodel.GenericModelParams;
import org.jamdev.jdl4pam.transforms.DLTransform; import org.jamdev.jdl4pam.transforms.DLTransform;
import org.jamdev.jdl4pam.transforms.DLTransformsFactory; 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.DLTransformParser2;
import org.jamdev.jdl4pam.transforms.jsonfile.DLTransformsParser; import org.jamdev.jdl4pam.transforms.jsonfile.DLTransformsParser;
import org.json.JSONObject; import org.json.JSONObject;
import PamUtils.PamArrayUtils;
import PamView.dialog.warn.WarnOnce; import PamView.dialog.warn.WarnOnce;
import ai.djl.MalformedModelException; import ai.djl.MalformedModelException;
import rawDeepLearningClassifier.DLControl; import rawDeepLearningClassifier.DLControl;
import rawDeepLearningClassifier.dlClassification.animalSpot.StandardModelParams; import rawDeepLearningClassifier.dlClassification.animalSpot.StandardModelParams;
import rawDeepLearningClassifier.dlClassification.genericModel.DLModelWorker; import rawDeepLearningClassifier.dlClassification.genericModel.DLModelWorker;
import rawDeepLearningClassifier.dlClassification.genericModel.GenericModelWorker;
import rawDeepLearningClassifier.dlClassification.genericModel.GenericPrediction; import rawDeepLearningClassifier.dlClassification.genericModel.GenericPrediction;
/** /**
@ -33,7 +36,7 @@ import rawDeepLearningClassifier.dlClassification.genericModel.GenericPrediction
* @author Jamie Macaulay * @author Jamie Macaulay
* *
*/ */
public class ArchiveModelWorker extends DLModelWorker<GenericPrediction> { public class ArchiveModelWorker extends GenericModelWorker {
/** /**
@ -57,6 +60,7 @@ public class ArchiveModelWorker extends DLModelWorker<GenericPrediction> {
/** /**
* Prepare the model * Prepare the model
*/ */
@Override
public void prepModel(StandardModelParams dlParams, DLControl dlControl) { public void prepModel(StandardModelParams dlParams, DLControl dlControl) {
//ClassLoader origCL = Thread.currentThread().getContextClassLoader(); //ClassLoader origCL = Thread.currentThread().getContextClassLoader();
try { try {
@ -96,10 +100,11 @@ public class ArchiveModelWorker extends DLModelWorker<GenericPrediction> {
//read the JSON string from the the file. //read the JSON string from the the file.
String jsonString = DLTransformsParser.readJSONString(new File(dlModel.getAudioReprFile())); String jsonString = DLTransformsParser.readJSONString(new File(dlModel.getAudioReprFile()));
//convert the JSON string to a parameters object. //convert the JSON string to a parameters object.
GenericModelParams modelParams = makeModelParams( jsonString); GenericModelParams modelParams = makeModelParams( jsonString);
//important to add this for Ketos models because the JSON string does not necessarily contain and output shape. //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()); //System.out.println("----Default output shape: " + ketosParams.defaultOutputShape + " " + ketosModel.getOutShape());
if (modelParams.defaultOutputShape==null) { if (modelParams.defaultOutputShape==null) {
@ -108,6 +113,7 @@ public class ArchiveModelWorker extends DLModelWorker<GenericPrediction> {
//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. //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)) { 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); 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); dlModel.setInputShape(modelParams.defaultInputShape);
} }
@ -131,26 +137,35 @@ public class ArchiveModelWorker extends DLModelWorker<GenericPrediction> {
//only load new transforms if defaults are selected //only load new transforms if defaults are selected
if (getModelTransforms()==null || dlParams.dlTransfroms==null || dlParams.useDefaultTransfroms) { 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. //only set the transforms if they are null - otherwise handled elsewhere.
setModelTransforms(transforms); setModelTransforms(transforms);
dlParams.useDefaultTransfroms = true; dlParams.useDefaultTransfroms = true;
dlParams.dlTransfroms=transforms;
} }
else { else {
//System.out.println("SET CURRENT TRANSFORMS: " + ketosDLParams.dlTransfroms + " " + ketosDLParams.useDefaultTransfroms);
//use the old transforms. //use the old transforms.
setModelTransforms(dlParams.dlTransfroms); 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. //ketosDLParams.dlTransfroms = transforms; //this is done after prep model in the settings pane.
dlParams.defaultSegmentLen = modelParams.segLen*1000.; //the segment length in microseconds. dlParams.defaultSegmentLen = modelParams.segLen; //the segment length in microseconds.
//ketosParams.classNames = new String[] {"Noise", "Right Whale"}; // FIXME;
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.... //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) { if (dlParams.binaryClassification==null || dlParams.binaryClassification.length!=dlParams.numClasses) {
dlParams.binaryClassification = new boolean[dlParams.numClasses]; dlParams.binaryClassification = new boolean[dlParams.numClasses];
for (int i=0; i<dlParams.binaryClassification.length; i++) { for (int i=0; i<dlParams.binaryClassification.length; i++) {
@ -165,19 +180,6 @@ public class ArchiveModelWorker extends DLModelWorker<GenericPrediction> {
//set the number of class names from the default output shape //set the number of class names from the default output shape
dlParams.numClasses = (int) modelParams.defaultOutputShape.get(1); dlParams.numClasses = (int) modelParams.defaultOutputShape.get(1);
} }
// if (dlParams.classNames!=null) {
// for (int i = 0; i<dlParams.classNames.length; i++) {
// System.out.println("Class name " + i + " " + dlParams.classNames[i]);
// }
// }
// ketosDLParams.classNames = dlControl.getClassNameManager().makeClassNames(ketosParams.classNames);
// if (ketosParams.classNames!=null) {
// for (int i = 0; i<ketosDLParams.classNames.length; i++) {
// System.out.println("Class name " + i + " " + ketosDLParams.classNames[i].className + " ID " + ketosDLParams.classNames[i].ID );
// }
// }
} }
catch (Exception e) { catch (Exception e) {
dlModel=null; dlModel=null;
@ -195,13 +197,6 @@ public class ArchiveModelWorker extends DLModelWorker<GenericPrediction> {
* @throws IOException * @throws IOException
*/ */
public ArchiveModel loadModel(String currentPath2) throws MalformedModelException, 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)); return new SimpleArchiveModel(new File(currentPath2));
} }
@ -225,11 +220,11 @@ public class ArchiveModelWorker extends DLModelWorker<GenericPrediction> {
@Override // @Override
public float[] runModel(float[][][] transformedDataStack) { // public float[] runModel(float[][][] transformedDataStack) {
System.out.println("Model input: " + transformedDataStack.length + " " + transformedDataStack[0].length + " " + transformedDataStack[0][0].length); // System.out.println("Model input: " + transformedDataStack.length + " " + transformedDataStack[0].length + " " + transformedDataStack[0][0].length);
return dlModel.runModel(transformedDataStack); // return dlModel.runModel(transformedDataStack);
} // }
@Override @Override
@ -252,6 +247,7 @@ public class ArchiveModelWorker extends DLModelWorker<GenericPrediction> {
* Get the currently loaded mode. * Get the currently loaded mode.
* @return - the currently loaded mode. * @return - the currently loaded mode.
*/ */
@Override
public ArchiveModel getModel() { public ArchiveModel getModel() {
return dlModel; return dlModel;
} }

View File

@ -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 zipUri - uri to the zip file
* @param filePattern - the file pattern to match - the file must contain this string. * @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 * @return null if no file found and the file pqth if the file is founf

View File

@ -28,7 +28,7 @@ public class SimpleArchiveModel extends ArchiveModel {
@Override @Override
public String getAudioReprRelPath(String zipFolder) { public String getAudioReprRelPath(String zipFolder) {
try { try {
System.out.println("SETTINGS PATH: " + getRelFilePath(zipFolder, ".pdtf")); //System.out.println("SETTINGS PATH: " + getRelFilePath(zipFolder, ".pdtf"));
return getRelFilePath(zipFolder, ".pdtf"); return getRelFilePath(zipFolder, ".pdtf");
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
@ -43,7 +43,7 @@ public class SimpleArchiveModel extends ArchiveModel {
String model = null; String model = null;
model = getRelFilePath(zipFolder, ".pb"); model = getRelFilePath(zipFolder, ".pb");
if (model==null) model = getRelFilePath(zipFolder, ".py"); if (model==null) model = getRelFilePath(zipFolder, ".py");
System.out.println("MODEL PATH: " +model); //System.out.println("MODEL PATH: " +model);
return model; return model;
} catch (IOException e) { } catch (IOException e) {
@ -64,14 +64,16 @@ public class SimpleArchiveModel extends ArchiveModel {
try (Stream<Path> walk = Files.walk(Paths.get(zipFolder))) { try (Stream<Path> walk = Files.walk(Paths.get(zipFolder))) {
List<String> result = walk List<String> result = walk
.filter(p -> !Files.isDirectory(p)) // not a directory .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 .filter(f -> f.endsWith(fileEnd)) // check end with
.collect(Collectors.toList()); // collect all matched to a List .collect(Collectors.toList()); // collect all matched to a List
if (result.size()>0) { if (result.size()>0) {
String firstFile = result.get(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; return relative;
} }

View File

@ -184,7 +184,6 @@ public class GenericAdvPane extends SettingsPane<GenericModelParams> {
defualtShapeSwitch = new PamToggleSwitch("Use model default shape"); defualtShapeSwitch = new PamToggleSwitch("Use model default shape");
defualtShapeSwitch.selectedProperty().addListener((obsval, oldval, newval)->{ defualtShapeSwitch.selectedProperty().addListener((obsval, oldval, newval)->{
System.out.println("Hello: deafult shape: " + newval);
PamArrayUtils.printArray( currentInput.defaultShape); PamArrayUtils.printArray( currentInput.defaultShape);
if (newval) { if (newval) {

View File

@ -121,13 +121,12 @@ public class GenericDLClassifier extends StandardClassifierModel {
genericModelParams.dlTransfromParams=dlTransformParams; genericModelParams.dlTransfromParams=dlTransformParams;
if (genericModelParams.dlTransfromParams!=null) { // if (genericModelParams.dlTransfromParams!=null) {
System.out.println("Generic settings have been saved. : " + genericModelParams.dlTransfromParams.size()); // System.out.println("Generic settings have been saved. : " + genericModelParams.dlTransfromParams.size());
} // }
else { // else {
System.out.println("Generic settings have been saved. : " + null); // System.out.println("Generic settings have been saved. : " + null);
// }
}
return genericModelParams; return genericModelParams;
} }
@ -211,6 +210,8 @@ public class GenericDLClassifier extends StandardClassifierModel {
*/ */
public static boolean isBinaryResult(GenericPrediction modelResult, StandardModelParams genericModelParams) { public static boolean isBinaryResult(GenericPrediction modelResult, StandardModelParams genericModelParams) {
for (int i=0; i<modelResult.getPrediction().length; i++) { for (int i=0; i<modelResult.getPrediction().length; i++) {
//System.out.println("Binary Classification: " + genericModelParams.binaryClassification.length);
if (modelResult.getPrediction()[i]>genericModelParams.threshold && genericModelParams.binaryClassification[i]) { if (modelResult.getPrediction()[i]>genericModelParams.threshold && genericModelParams.binaryClassification[i]) {
// System.out.println("SoundSpotClassifier: prediciton: " + i + " passed threshold with val: " + modelResult.getPrediction()[i]); // System.out.println("SoundSpotClassifier: prediciton: " + i + " passed threshold with val: " + modelResult.getPrediction()[i]);
return true; return true;

View File

@ -33,19 +33,21 @@ public class GenericModelWorker extends DLModelWorker<GenericPrediction> {
@Override @Override
public float[] runModel(float[][][] transformedDataStack) { 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]); // System.out.println("RUN GENERIC MODEL: " + transformedDataStack[0][0][0]);
float[] results; float[] results;
if (freqTransform) if (freqTransform)
results = genericModel.runModel(transformedDataStack); results = getModel().runModel(transformedDataStack);
else { else {
//run a model if it is waveform info. //run a model if it is waveform info.
float[][] waveStack = new float[transformedDataStack.length][]; float[][] waveStack = new float[transformedDataStack.length][];
for (int i=0; i<waveStack.length; i++) { for (int i=0; i<waveStack.length; i++) {
waveStack[i] = transformedDataStack[i][0]; waveStack[i] = transformedDataStack[i][0];
} }
results = genericModel.runModel(waveStack);
//System.out.println("RUN GENERIC MODEL WAVE: " + transformedDataStack.length + " " + transformedDataStack[0].length);
results = getModel().runModel(waveStack);
} }
System.out.println("GENERIC MODEL RESULTS: " + results== null ? null : results.length); //System.out.println("GENERIC MODEL RESULTS: " + results== null ? null : results.length);
return results; return results;
} }
@ -97,13 +99,7 @@ public class GenericModelWorker extends DLModelWorker<GenericPrediction> {
setModelTransforms(genericParams.dlTransfroms); setModelTransforms(genericParams.dlTransfroms);
//is this a waveform or a spectrogram model? //is this a waveform or a spectrogram model?
DLTransform transform = genericParams.dlTransfroms.get(genericParams.dlTransfroms.size()-1); setWaveFreqModel(genericParams);
if (transform instanceof FreqTransform) {
freqTransform = true;
}
else {
freqTransform = false;
}
//use softmax or not? //use softmax or not?
String extension = FilenameUtils.getExtension(genericParams.modelPath); String extension = FilenameUtils.getExtension(genericParams.modelPath);
@ -131,6 +127,18 @@ public class GenericModelWorker extends DLModelWorker<GenericPrediction> {
//Thread.currentThread().setContextClassLoader(origCL); //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. * Convert a long[] array to a Long[] array.
* @param inArr - the input long[] array. * @param inArr - the input long[] array.

View File

@ -32,6 +32,8 @@ public class KetosWorker2 extends ArchiveModelWorker {
public GenericModelParams makeModelParams(String jsonString) { public GenericModelParams makeModelParams(String jsonString) {
//ketos parameters are non standard and need a bit of extra work to get right. //ketos parameters are non standard and need a bit of extra work to get right.
//This also deal with legacy paramters. //This also deal with legacy paramters.
return new KetosParams(jsonString); KetosParams params = new KetosParams(jsonString);
// System.out.println(params);
return params;
} }
} }

View File

@ -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. //we are loading model from a file - anything can happen so put in a try catch.
DLStatus status = currentClassifierModel.setModel(file); DLStatus status = currentClassifierModel.setModel(file);
if (status.isError()) { if (status.isError()) {
System.err.println("Model load failed: " + currentClassifierModel.getModelStatus()); System.err.println("Model load failed: " + currentClassifierModel.getModelStatus());
currentClassifierModel=null; currentClassifierModel=null;
@ -437,7 +438,7 @@ public class DLModelSelectPane extends PamBorderPane {
pathLabel.setText("No classifier model loaded: Select model"); 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")); 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.setGraphic(createErrorIcon(currentClassifierModel.getModelStatus()));
pathLabel.setText(currentClassifierModel.getModelStatus().getName()); pathLabel.setText(currentClassifierModel.getModelStatus().getName());
pathLabel.setTooltip(new Tooltip(currentClassifierModel.getModelStatus().getDescription())); pathLabel.setTooltip(new Tooltip(currentClassifierModel.getModelStatus().getDescription()));

View File

@ -20,8 +20,10 @@ import javafx.scene.control.Label;
import javafx.scene.control.Spinner; import javafx.scene.control.Spinner;
import javafx.scene.control.Tooltip; import javafx.scene.control.Tooltip;
import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import pamViewFX.PamGuiManagerFX; import pamViewFX.PamGuiManagerFX;
import pamViewFX.fxGlyphs.PamGlyphDude; import pamViewFX.fxGlyphs.PamGlyphDude;
import pamViewFX.fxNodes.PamBorderPane; import pamViewFX.fxNodes.PamBorderPane;
@ -48,7 +50,7 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
public static double MAX_WIDTH = 270; public static double MAX_WIDTH = 270;
/** /**
* The source for the FFT data source. * The source for the FFT data source.
*/ */
@ -64,10 +66,10 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
*/ */
private PamBorderPane mainPane; private PamBorderPane mainPane;
// /** // /**
// * Combo box which allows users to select model. // * Combo box which allows users to select model.
// */ // */
// private ComboBox<String> dlModelBox; // private ComboBox<String> dlModelBox;
/** /**
* The window length spinner for the segmenter process * The window length spinner for the segmenter process
@ -112,9 +114,9 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
private Label infoLabel; private Label infoLabel;
private DLModelSelectPane modelSelectPane; private DLModelSelectPane modelSelectPane;
public DLSettingsPane(DLControl dlControl){ public DLSettingsPane(DLControl dlControl){
super(null); super(null);
this.dlControl=dlControl; this.dlControl=dlControl;
@ -126,19 +128,19 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
// stage.sizeToScene(); // stage.sizeToScene();
// }); // });
// this.setTop(newButton); // this.setTop(newButton);
mainPane=new PamBorderPane(); mainPane=new PamBorderPane();
mainPane.setCenter(createDLPane()); mainPane.setCenter(createDLPane());
mainPane.setPadding(new Insets(5,5,5,5)); mainPane.setPadding(new Insets(5,5,5,5));
if (!PamGUIManager.isFX()){ if (!PamGUIManager.isFX()){
mainPane.setMinHeight(430); mainPane.setMinHeight(430);
mainPane.setMaxWidth(MAX_WIDTH); mainPane.setMaxWidth(MAX_WIDTH);
mainPane.setPrefWidth(MAX_WIDTH); mainPane.setPrefWidth(MAX_WIDTH);
} }
//this.getAdvPane().setMaxWidth(MAX_WIDTH); //this.getAdvPane().setMaxWidth(MAX_WIDTH);
//mainPane.getStylesheets().add(PamStylesManagerFX.getPamStylesManagerFX().getCurStyle().getDialogCSS()); //mainPane.getStylesheets().add(PamStylesManagerFX.getPamStylesManagerFX().getCurStyle().getDialogCSS());
@ -162,14 +164,14 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
vBox.getChildren().add(sourcePane); vBox.getChildren().add(sourcePane);
sourcePane.prefWidthProperty().bind(vBox.widthProperty()); sourcePane.prefWidthProperty().bind(vBox.widthProperty());
sourcePane.setMaxWidth(Double.MAX_VALUE); sourcePane.setMaxWidth(Double.MAX_VALUE);
sourcePane.getDataBlockBox().setOnAction((action)->{ sourcePane.getDataBlockBox().setOnAction((action)->{
//need to create a data selector if one exists. //need to create a data selector if one exists.
this.dlControl.createDataSelector(getSelectedParentDataBlock()); this.dlControl.createDataSelector(getSelectedParentDataBlock());
//enable the controls to show a data selector or not. //enable the controls to show a data selector or not.
enableControls(); enableControls();
}); });
//create the detection //create the detection
vBox.getChildren().add(createDataSelectorPane()); vBox.getChildren().add(createDataSelectorPane());
@ -193,14 +195,14 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
hopLength.valueProperty().addListener((obsVal, oldVal, newVal)->{ hopLength.valueProperty().addListener((obsVal, oldVal, newVal)->{
setSegInfoLabel(); setSegInfoLabel();
}); });
reMergeSeg = new PamSpinner<Integer>(0, Integer.MAX_VALUE, 1, 1); reMergeSeg = new PamSpinner<Integer>(0, Integer.MAX_VALUE, 1, 1);
reMergeSeg.getStyleClass().add(Spinner.STYLE_CLASS_SPLIT_ARROWS_HORIZONTAL); reMergeSeg.getStyleClass().add(Spinner.STYLE_CLASS_SPLIT_ARROWS_HORIZONTAL);
reMergeSeg.setEditable(true); reMergeSeg.setEditable(true);
//button to set default hop size //button to set default hop size
Button defaultButton = new Button(); 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.setGraphic(PamGlyphDude.createPamIcon("mdi2r-refresh", PamGuiManagerFX.iconSize-3));
defaultButton.setTooltip(new Tooltip("Set default hop size")); defaultButton.setTooltip(new Tooltip("Set default hop size"));
defaultButton.setOnAction((action)->{ defaultButton.setOnAction((action)->{
@ -208,6 +210,14 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
}); });
PamGridPane segmenterGridPane = new PamGridPane(); 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(new Label("Window length"), 0, 0);
segmenterGridPane.add(windowLength, 1, 0); segmenterGridPane.add(windowLength, 1, 0);
segmenterGridPane.add(new Label("samples"), 2, 0); segmenterGridPane.add(new Label("samples"), 2, 0);
@ -222,40 +232,40 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
segmenterGridPane.add(new Label("segments"), 2, 2); segmenterGridPane.add(new Label("segments"), 2, 2);
vBox.getChildren().add(segmenterGridPane); vBox.getChildren().add(segmenterGridPane);
vBox.getChildren().add(infoLabel = new Label()); vBox.getChildren().add(infoLabel = new Label());
Label label2 = new Label("Deep Learning Model"); Label label2 = new Label("Deep Learning Model");
label2.setPadding(new Insets(5,0,0,0)); label2.setPadding(new Insets(5,0,0,0));
PamGuiManagerFX.titleFont2style(label2); PamGuiManagerFX.titleFont2style(label2);
vBox.getChildren().add(label2); vBox.getChildren().add(label2);
/** /**
* Pane which allows users to select a model type. * Pane which allows users to select a model type.
*/ */
modelSelectPane = new DLModelSelectPane(this); modelSelectPane = new DLModelSelectPane(this);
// //add the possible deep learning models. // //add the possible deep learning models.
// dlModelBox= new ComboBox<String>(); // dlModelBox= new ComboBox<String>();
// for (int i=0; i<dlControl.getDLModels().size(); i++) { // for (int i=0; i<dlControl.getDLModels().size(); i++) {
// dlModelBox.getItems().add(dlControl.getDLModels().get(i).getName()); // dlModelBox.getItems().add(dlControl.getDLModels().get(i).getName());
// } // }
// dlModelBox.prefWidthProperty().bind(vBox.widthProperty()); // dlModelBox.prefWidthProperty().bind(vBox.widthProperty());
// //
// dlModelBox.setOnAction((action)->{ // dlModelBox.setOnAction((action)->{
// setClassifierPane(); // setClassifierPane();
// if (mainPane!=null) { // if (mainPane!=null) {
// if (mainPane.getScene().getWindow() instanceof Stage) { // if (mainPane.getScene().getWindow() instanceof Stage) {
// Stage stage = (Stage) mainPane.getScene().getWindow(); // Stage stage = (Stage) mainPane.getScene().getWindow();
// stage.sizeToScene(); // stage.sizeToScene();
// } // }
// } // }
// //this.dlControl.getAnnotationType().getSymbolModifier(symbolChooser). // //this.dlControl.getAnnotationType().getSymbolModifier(symbolChooser).
// }); // });
// //
// vBox.getChildren().add(dlModelBox); // vBox.getChildren().add(dlModelBox);
classifierPane = new PamBorderPane(); classifierPane = new PamBorderPane();
@ -265,7 +275,7 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
return vBox; return vBox;
} }
/** /**
* Create the data selector. * Create the data selector.
* @return the data selector. * @return the data selector.
@ -274,13 +284,13 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
dataSelectorPane = new PamHBox(); dataSelectorPane = new PamHBox();
dataSelectorPane.setSpacing(5); dataSelectorPane.setSpacing(5);
dataSelectorPane.setAlignment(Pos.CENTER_LEFT); dataSelectorPane.setAlignment(Pos.CENTER_LEFT);
dataSelectorCheckBox = new PamToggleSwitch("Detection Selector"); dataSelectorCheckBox = new PamToggleSwitch("Detection Selector");
dataSelectorCheckBox.selectedProperty().addListener((obsval, oldval, newval)->{ dataSelectorCheckBox.selectedProperty().addListener((obsval, oldval, newval)->{
enableControls(); enableControls();
}); });
dataSelectorButton = new PamButton(); 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.setGraphic(PamGlyphDude.createPamIcon("mdi2c-cog", PamGuiManagerFX.iconSize));
dataSelectorButton.setOnAction((action)->{ dataSelectorButton.setOnAction((action)->{
showAdvPane(); showAdvPane();
@ -288,7 +298,7 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
dataSelectorPane.getChildren().addAll(dataSelectorCheckBox, dataSelectorButton); dataSelectorPane.getChildren().addAll(dataSelectorCheckBox, dataSelectorButton);
return dataSelectorPane; return dataSelectorPane;
} }
/** /**
* Set extra information in the info label. * Set extra information in the info label.
*/ */
@ -306,7 +316,7 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
} }
infoLabel.setText(text); infoLabel.setText(text);
} }
/** /**
* Creates pane allowing the user to change fine scale things such as error limits. * Creates pane allowing the user to change fine scale things such as error limits.
* @return the pop over pane. * @return the pop over pane.
@ -327,7 +337,7 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
popOver.show(dataSelectorButton); popOver.show(dataSelectorButton);
} }
/** /**
* Enable the controls. * Enable the controls.
*/ */
@ -338,10 +348,10 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
//^bit messy but cannot think of a better way to do it. //^bit messy but cannot think of a better way to do it.
this.dataSelectorPane.setVisible(false); this.dataSelectorPane.setVisible(false);
} }
dataSelectorButton.setDisable(!dataSelectorCheckBox.isSelected()); dataSelectorButton.setDisable(!dataSelectorCheckBox.isSelected());
} }
/** /**
@ -368,9 +378,9 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
protected void setClassifierPane() { protected void setClassifierPane() {
//set the classifier Pane.class //set the classifier Pane.class
if (modelSelectPane.currentClassifierModel!=null && modelSelectPane.currentClassifierModel.getModelUI()!=null) { if (modelSelectPane.currentClassifierModel!=null && modelSelectPane.currentClassifierModel.getModelUI()!=null) {
classifierPane.setCenter(modelSelectPane.currentClassifierModel.getModelUI().getSettingsPane().getContentNode()); classifierPane.setCenter(modelSelectPane.currentClassifierModel.getModelUI().getSettingsPane().getContentNode());
if (modelSelectPane.currentClassifierModel!=null) { if (modelSelectPane.currentClassifierModel!=null) {
modelSelectPane.currentClassifierModel.getModelUI().setParams(); modelSelectPane.currentClassifierModel.getModelUI().setParams();
} }
@ -400,8 +410,8 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
} }
sourcePane.getParams(currParams.groupedSourceParams); sourcePane.getParams(currParams.groupedSourceParams);
// currParams.modelSelection = dlModelBox.getSelectionModel().getSelectedIndex(); // currParams.modelSelection = dlModelBox.getSelectionModel().getSelectedIndex();
if (windowLength.getValue() == 0 || hopLength.getValue()==0){ if (windowLength.getValue() == 0 || hopLength.getValue()==0){
Platform.runLater(()->{ Platform.runLater(()->{
@ -413,8 +423,8 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
currParams.rawSampleSize = windowLength.getValue(); currParams.rawSampleSize = windowLength.getValue();
currParams.sampleHop = hopLength.getValue(); currParams.sampleHop = hopLength.getValue();
currParams.maxMergeHops = reMergeSeg.getValue(); currParams.maxMergeHops = reMergeSeg.getValue();
if (modelSelectPane.currentClassifierModel == null) { if (modelSelectPane.currentClassifierModel == null) {
currParams.modelSelection = -1; currParams.modelSelection = -1;
} }
@ -423,28 +433,28 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
} }
// //update any changes // //update any changes
// if (this.dlControl.getDLModels().get(dlModelBox.getSelectionModel().getSelectedIndex()).getModelUI()!=null){ // if (this.dlControl.getDLModels().get(dlModelBox.getSelectionModel().getSelectedIndex()).getModelUI()!=null){
// this.dlControl.getDLModels().get(dlModelBox.getSelectionModel().getSelectedIndex()).getModelUI().getParams(); // this.dlControl.getDLModels().get(dlModelBox.getSelectionModel().getSelectedIndex()).getModelUI().getParams();
// //
// //display any warnings from the settings. // //display any warnings from the settings.
// ArrayList<PamWarning> warnings = this.dlControl.getDLModels().get(dlModelBox.getSelectionModel().getSelectedIndex()).checkSettingsOK(); // ArrayList<PamWarning> warnings = this.dlControl.getDLModels().get(dlModelBox.getSelectionModel().getSelectedIndex()).checkSettingsOK();
// showWarnings(warnings); // showWarnings(warnings);
// //
// for (int i=0; i<warnings.size(); i++) { // for (int i=0; i<warnings.size(); i++) {
// if (warnings.get(i).getWarnignLevel()>1) { // if (warnings.get(i).getWarnignLevel()>1) {
// //Serious error. Do not close dialog. // //Serious error. Do not close dialog.
// return null; // return null;
// } // }
// } // }
// } // }
currParams.useDataSelector = dataSelectorCheckBox.isSelected(); currParams.useDataSelector = dataSelectorCheckBox.isSelected();
if (dlControl.getDataSelector()!=null) { if (dlControl.getDataSelector()!=null) {
dlControl.getDataSelector().getDialogPaneFX().getParams(true); dlControl.getDataSelector().getDialogPaneFX().getParams(true);
} }
//need to make sure we call get params for the current model when the oK button is pressed. //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!=null) {
if (this.modelSelectPane.currentClassifierModel.getModelUI()!=null) { if (this.modelSelectPane.currentClassifierModel.getModelUI()!=null) {
@ -453,16 +463,16 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
} }
currParams.modelURI = this.modelSelectPane.currentSelectedFile; currParams.modelURI = this.modelSelectPane.currentSelectedFile;
return currParams; return currParams;
} }
public static PamWarning statusToWarnings(DLStatus dlStatus) { public static PamWarning statusToWarnings(DLStatus dlStatus) {
PamWarning pamWarning = new PamWarning(dlStatus.getName(), dlStatus.getDescription(), dlStatus.isError() ? 2 : 1); PamWarning pamWarning = new PamWarning(dlStatus.getName(), dlStatus.getDescription(), dlStatus.isError() ? 2 : 1);
return pamWarning; return pamWarning;
} }
/** /**
* Show a warning dialog for the status * Show a warning dialog for the status
* @param the status to show * @param the status to show
@ -472,7 +482,7 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
dlWarnings.add(statusToWarnings(dlWarning)); dlWarnings.add(statusToWarnings(dlWarning));
showWarning(dlWarnings); showWarning(dlWarnings);
} }
/** /**
* Show a warning dialog. * Show a warning dialog.
* @param the warning to show. * @param the warning to show.
@ -489,12 +499,12 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
* @param dlWarnings - list of warnings - the most important will be shown. * @param dlWarnings - list of warnings - the most important will be shown.
*/ */
public void showWarning(ArrayList<PamWarning> dlWarnings) { public void showWarning(ArrayList<PamWarning> dlWarnings) {
if (dlWarnings==null || dlWarnings.size()<1) return; if (dlWarnings==null || dlWarnings.size()<1) return;
String warnings =""; String warnings ="";
boolean error = false; boolean error = false;
for (int i=0; i<dlWarnings.size(); i++) { for (int i=0; i<dlWarnings.size(); i++) {
warnings += dlWarnings.get(i).getWarningMessage() + "\n\n"; warnings += dlWarnings.get(i).getWarningMessage() + "\n\n";
@ -502,14 +512,14 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
error=true; error=true;
} }
} }
final String warningsF = warnings; final String warningsF = warnings;
final boolean errorF = error; final boolean errorF = error;
Platform.runLater(()->{ Platform.runLater(()->{
WarnOnce.showWarningFX(null, "Deep Learning Settings Warning", warningsF , errorF ? AlertType.ERROR : AlertType.WARNING); 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. //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<RawDLParams>{
sourcePane.setParams(currParams.groupedSourceParams); sourcePane.setParams(currParams.groupedSourceParams);
sourcePane.sourceChanged(); sourcePane.sourceChanged();
dlControl.createDataSelector(sourcePane.getSource()); dlControl.createDataSelector(sourcePane.getSource());
//set the classifier model. //set the classifier model.
if (currParams.modelURI !=null) { if (currParams.modelURI !=null) {
modelSelectPane.currentClassifierModel = dlControl.getDLModel(); modelSelectPane.currentClassifierModel = dlControl.getDLModel();
} }
// dlModelBox.getSelectionModel().select(currParams.modelSelection); // dlModelBox.getSelectionModel().select(currParams.modelSelection);
windowLength.getValueFactory().setValue(currParams.rawSampleSize); windowLength.getValueFactory().setValue(currParams.rawSampleSize);
hopLength.getValueFactory().setValue(currParams.sampleHop); hopLength.getValueFactory().setValue(currParams.sampleHop);
reMergeSeg.getValueFactory().setValue(currParams.maxMergeHops); reMergeSeg.getValueFactory().setValue(currParams.maxMergeHops);
dataSelectorCheckBox.setSelected(currParams.useDataSelector); dataSelectorCheckBox.setSelected(currParams.useDataSelector);
setClassifierPane(); setClassifierPane();
enableControls(); enableControls();
setSegInfoLabel(); 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.loadNewModel(currParams.modelURI);
//this.modelSelectPane.updatePathLabel(); //this.modelSelectPane.updatePathLabel();
this.setClassifierPane(); this.setClassifierPane();
//For some reason, in the FX GUI, this causes a root used in multiple scenes exceptions...not sure why. //For some reason, in the FX GUI, this causes a root used in multiple scenes exceptions...not sure why.
Platform.runLater(()->{ Platform.runLater(()->{
sourcePane.getChannelValidator().validate(); sourcePane.getChannelValidator().validate();
@ -598,23 +608,23 @@ public class DLSettingsPane extends SettingsPane<RawDLParams>{
*/ */
public void setSegmentLength(Double defaultSegmentLen) { public void setSegmentLength(Double defaultSegmentLen) {
if (defaultSegmentLen==null) return; if (defaultSegmentLen==null) return;
double sR = getDLControl().getSettingsPane().getSelectedParentDataBlock().getSampleRate(); double sR = getDLControl().getSettingsPane().getSelectedParentDataBlock().getSampleRate();
System.out.println("Set the segment length: " + defaultSegmentLen + " sR " + sR); System.out.println("Set the segment length: " + defaultSegmentLen + " sR " + sR);
//automatically set the default segment length. //automatically set the default segment length.
getDLControl().getSettingsPane().getSegmentLenSpinner().getValueFactory().setValue((int) (sR*defaultSegmentLen/1000.)); getDLControl().getSettingsPane().getSegmentLenSpinner().getValueFactory().setValue((int) (sR*defaultSegmentLen/1000.));
} }
/** /**
* Convenience class to set the hop length in samples from milliseconds * Convenience class to set the hop length in samples from milliseconds
* @param defaultSegmentLen - the segment length in milliseconds. * @param defaultSegmentLen - the segment length in milliseconds.
*/ */
public void setHopLength(Double hopLength) { public void setHopLength(Double hopLength) {
if (hopLength==null) return; if (hopLength==null) return;
double sR = getDLControl().getSettingsPane().getSelectedParentDataBlock().getSampleRate(); double sR = getDLControl().getSettingsPane().getSelectedParentDataBlock().getSampleRate();
//automatically set the default segment length. //automatically set the default segment length.
getDLControl().getSettingsPane().getHopLenSpinner().getValueFactory().setValue((int) (sR*hopLength/1000.)); getDLControl().getSettingsPane().getHopLenSpinner().getValueFactory().setValue((int) (sR*hopLength/1000.));

View File

@ -31,6 +31,8 @@ public class DLDataUnitDatagram implements DatagramProvider {
public int addDatagramData(PamDataUnit dataUnit, float[] dataGramLine) { public int addDatagramData(PamDataUnit dataUnit, float[] dataGramLine) {
DLDataUnit dlDataUnit = (DLDataUnit) dataUnit; DLDataUnit dlDataUnit = (DLDataUnit) dataUnit;
if (dataGramLine==null || dataGramLine.length==0) return 0;
if (dlDataUnit.getPredicitionResult().getPrediction()!=null) { if (dlDataUnit.getPredicitionResult().getPrediction()!=null) {
for (int i=0; i<dlDataUnit.getPredicitionResult().getPrediction().length; i++) { for (int i=0; i<dlDataUnit.getPredicitionResult().getPrediction().length; i++) {
dataGramLine[i] += (float) dlDataUnit.getPredicitionResult().getPrediction()[i]; dataGramLine[i] += (float) dlDataUnit.getPredicitionResult().getPrediction()[i];