mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2024-11-21 22:52:22 +00:00
DL Params to XML
Write DL parameter to XML output (for Tethys). Needed a bit of messing with .equals in some of the objects in the XML writer class. Not really providing the information we want in the XML, so will need to revisit this in the future.
This commit is contained in:
parent
e9bf8dd602
commit
475e7c42cd
@ -583,6 +583,28 @@ public class PamguardXMLWriter implements PamSettings {
|
||||
// }
|
||||
return el;
|
||||
}
|
||||
|
||||
/**
|
||||
* Need to use a modified function here since some of Jamies DL params
|
||||
* classes cast to their own type before the have checked type in the
|
||||
* equals functoins he's written.
|
||||
* @param objectHierarchy
|
||||
* @return
|
||||
*/
|
||||
private boolean hasData(ArrayList<Object> objectHierarchy, Object object) {
|
||||
if (objectHierarchy == null) {
|
||||
return false;
|
||||
}
|
||||
for (Object o : objectHierarchy) {
|
||||
if (object.getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
if (o.equals(object)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Element writeObjectData(Document doc, Element el, Object data, ArrayList<Object> objectHierarchy) {
|
||||
if (data == null) {
|
||||
@ -591,7 +613,7 @@ public class PamguardXMLWriter implements PamSettings {
|
||||
if (objectHierarchy == null) {
|
||||
objectHierarchy = new ArrayList<>();
|
||||
}
|
||||
if (objectHierarchy.contains(data)) {
|
||||
if (hasData(objectHierarchy, data)) {
|
||||
// just write the reference, but nothing else or we'll end up in an infinite loop of objects.
|
||||
Element e = doc.createElement("Object");
|
||||
e.setAttribute("Class", data.getClass().getName());
|
||||
@ -794,6 +816,8 @@ public class PamguardXMLWriter implements PamSettings {
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("Error in PamguardXMLWriter.writeObjectArray: " + e.getMessage());
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -346,6 +346,7 @@ public class DLControl extends PamControlledUnit implements PamSettings {
|
||||
|
||||
this.segmenterProcess.setupSegmenter();
|
||||
this.dlClassifyProcess.setupProcess();
|
||||
this.checkModelParams();
|
||||
|
||||
// this is a bit of a hack. Annotations are added to data units but the
|
||||
// datablock knows nothing about them
|
||||
@ -512,6 +513,34 @@ public class DLControl extends PamControlledUnit implements PamSettings {
|
||||
|
||||
public void setParams(RawDLParams newParams) {
|
||||
this.rawDLParmas = newParams;
|
||||
checkModelParams();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when setParams is called, which should have new model params
|
||||
* after the dialog was closed. Puts these into dlParams so they get serialised
|
||||
* with rest of XML.
|
||||
*/
|
||||
public void checkModelParams() {
|
||||
RawDLParams dlParams = getDLParams();
|
||||
DLClassiferModel model = getDLModel();
|
||||
Serializable modelParams = null;
|
||||
if (model != null) {
|
||||
modelParams = model.getDLModelSettings();
|
||||
}
|
||||
dlParams.setModelParameters(modelParams);
|
||||
|
||||
// see what else we can find in the model in terms of metadata.
|
||||
// if (model == null) {
|
||||
// return;
|
||||
// }
|
||||
// try {
|
||||
// String modelName = model.getName();
|
||||
// System.out.println("Model name: " + modelName);
|
||||
// }
|
||||
// catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,6 +100,8 @@ public class RawDLParams implements Serializable, Cloneable {
|
||||
*/
|
||||
public short classNameIndex = 0;
|
||||
|
||||
private Serializable modelParameters;
|
||||
|
||||
@Override
|
||||
public RawDLParams clone() {
|
||||
RawDLParams newParams = null;
|
||||
@ -118,4 +120,22 @@ public class RawDLParams implements Serializable, Cloneable {
|
||||
return newParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the model parameters. These aren't really needed in here are aren't really
|
||||
* used except when the parameters are serialized to XML for book keeping.
|
||||
* @param modelParameters
|
||||
*/
|
||||
public Serializable getModelParameters() {
|
||||
return modelParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the model parameters. These aren't really needed in here are aren't really
|
||||
* used except when the parameters are serialized to XML for book keeping.
|
||||
* @param modelParameters the modelParameters to set
|
||||
*/
|
||||
public void setModelParameters(Serializable modelParameters) {
|
||||
this.modelParameters = modelParameters;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ public class DLClassifyProcess extends PamInstantProcess {
|
||||
|
||||
//run the deep learning algorithm
|
||||
ArrayList<GroupedRawData> classificationBufferTemp = (ArrayList<GroupedRawData>) classificationBuffer.clone();
|
||||
ArrayList<? extends PredictionResult> modelResults = this.dlControl.getDLModel().runModel(classificationBuffer);
|
||||
ArrayList<? extends PredictionResult> modelResults = this.dlControl.getDLModel().runModel(classificationBufferTemp);
|
||||
|
||||
if (modelResults==null) {
|
||||
return; //there has been a problem
|
||||
|
@ -3,6 +3,7 @@ package rawDeepLearningClassifier.dlClassification;
|
||||
import PamView.GroupedDataSource;
|
||||
import PamView.GroupedSourceParameters;
|
||||
import PamguardMVC.AcousticDataBlock;
|
||||
import rawDeepLearningClassifier.DLControl;
|
||||
import rawDeepLearningClassifier.tethys.DLSpeciesManager;
|
||||
import rawDeepLearningClassifier.tethys.DLTethysDataProvider;
|
||||
import tethys.TethysControl;
|
||||
@ -20,10 +21,12 @@ public class DLDetectionDataBlock extends AcousticDataBlock<DLDetection> impleme
|
||||
private DLClassifyProcess dlClassifyProcess;
|
||||
private DLTethysDataProvider dlTethysDataProvider;
|
||||
private DLSpeciesManager dlSpeciesManager;
|
||||
private DLControl dlControl;
|
||||
|
||||
public DLDetectionDataBlock(String dataName, DLClassifyProcess parentProcess, int channelMap) {
|
||||
super(DLDetection.class, dataName, parentProcess, channelMap);
|
||||
this.dlClassifyProcess = parentProcess;
|
||||
dlControl = dlClassifyProcess.getDLControl();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -34,7 +37,7 @@ public class DLDetectionDataBlock extends AcousticDataBlock<DLDetection> impleme
|
||||
@Override
|
||||
public TethysDataProvider getTethysDataProvider(TethysControl tethysControl) {
|
||||
if (dlTethysDataProvider == null) {
|
||||
dlTethysDataProvider = new DLTethysDataProvider(tethysControl, this);
|
||||
dlTethysDataProvider = new DLTethysDataProvider(tethysControl, dlControl, this);
|
||||
}
|
||||
return dlTethysDataProvider;
|
||||
}
|
||||
|
@ -89,6 +89,14 @@ public class GenericModelParams extends StandardModelParams implements Cloneable
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (o instanceof GenericModelParams == false) {
|
||||
/*
|
||||
* have to add this since the equals function is used in a list comparason
|
||||
* in the XML output and that list contains objects of different types
|
||||
* so need to get out HERE or get a classcastexception at the next line
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
GenericModelParams params = (GenericModelParams) o;
|
||||
|
||||
|
||||
|
@ -1,20 +1,30 @@
|
||||
package rawDeepLearningClassifier.tethys;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import PamguardMVC.PamDataBlock;
|
||||
import PamguardMVC.PamDataUnit;
|
||||
import nilus.Detection;
|
||||
import nilus.Detection.Parameters;
|
||||
import rawDeepLearningClassifier.DLControl;
|
||||
import rawDeepLearningClassifier.RawDLParams;
|
||||
import rawDeepLearningClassifier.dlClassification.DLClassiferModel;
|
||||
import rawDeepLearningClassifier.dlClassification.DLDetection;
|
||||
import tethys.TethysControl;
|
||||
import tethys.output.StreamExportParams;
|
||||
import tethys.output.TethysExportParams;
|
||||
import tethys.pamdata.AutoTethysProvider;
|
||||
import tethys.pamdata.TethysParameterPacker;
|
||||
|
||||
public class DLTethysDataProvider extends AutoTethysProvider {
|
||||
|
||||
public DLTethysDataProvider(TethysControl tethysControl, PamDataBlock pamDataBlock) {
|
||||
private DLControl dlControl;
|
||||
|
||||
public DLTethysDataProvider(TethysControl tethysControl, DLControl dlControl, PamDataBlock pamDataBlock) {
|
||||
super(tethysControl, pamDataBlock);
|
||||
// TODO Auto-generated constructor stub
|
||||
this.dlControl = dlControl;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,4 +45,25 @@ public class DLTethysDataProvider extends AutoTethysProvider {
|
||||
|
||||
return detection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public nilus.AlgorithmType.Parameters getAlgorithmParameters() {
|
||||
|
||||
/**
|
||||
* Add the model parameters to the main dlControl parameters so that they get
|
||||
* correctly serialized to the XML output
|
||||
// */
|
||||
// RawDLParams dlParams = dlControl.getDLParams();
|
||||
// DLClassiferModel model = dlControl.getDLModel();
|
||||
// Serializable modelParams = null;
|
||||
// if (model != null) {
|
||||
// modelParams = model.getDLModelSettings();
|
||||
// }
|
||||
// dlParams.setModelParameters(modelParams);
|
||||
dlControl.checkModelParams();
|
||||
|
||||
nilus.AlgorithmType.Parameters parameters = super.getAlgorithmParameters();
|
||||
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
|
@ -498,5 +498,12 @@ abstract public class AutoTethysProvider implements TethysDataProvider {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tethysControl
|
||||
*/
|
||||
public TethysControl getTethysControl() {
|
||||
return tethysControl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user