mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2025-04-27 18:48:38 +00:00
Thomas click deep learning unit test
This commit is contained in:
parent
d18137223a
commit
1fedbe6acd
@ -6,7 +6,7 @@
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/ojdk-21.0.1">
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-21-openjdk-amd64">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
@ -1,6 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/help/utilities/tethys/docs/connection.html=UTF-8
|
||||
encoding//src/rawDeepLearningClassifer/segmenter/SegmenterProcess.java=UTF-8
|
||||
encoding//src/test=UTF-8
|
||||
encoding//src/test/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
encoding/src=UTF-8
|
||||
|
@ -11,9 +11,9 @@ org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes=
|
||||
org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes=
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=17
|
||||
org.eclipse.jdt.core.compiler.compliance=21
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
@ -23,4 +23,4 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=17
|
||||
org.eclipse.jdt.core.compiler.source=21
|
||||
|
BIN
build/deb/PAMGuardIcon2.png
Normal file
BIN
build/deb/PAMGuardIcon2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 99 KiB |
13
build/deb/control
Normal file
13
build/deb/control
Normal file
@ -0,0 +1,13 @@
|
||||
Package: PAMGuard
|
||||
Version: 2.0.1
|
||||
Section: java
|
||||
Priority: optional
|
||||
Architecture: all
|
||||
Maintainer: Jamie Macaulay <jdjm@st-andrews.ac.uk>
|
||||
Description: A complex Java application with additional dependencies.
|
||||
Icon: pamguard_icon.png
|
||||
Depends: openjdk-21-jre
|
||||
postinst script:
|
||||
#!/bin/bash
|
||||
# Set JVM options for the application
|
||||
export JAVA_OPTS="-Xmx2g -Xms512m"
|
8
build/deb/pamguard.desktop
Executable file
8
build/deb/pamguard.desktop
Executable file
@ -0,0 +1,8 @@
|
||||
[Desktop Entry]
|
||||
Name=PAMGuard
|
||||
Comment=Application for passive acoustic monitoring v1
|
||||
Exec=java -jar /usr/share/pamguard/Pamguard.jar -c
|
||||
Icon=/usr/share/pamguard/PAMGuardIcon2.png
|
||||
Terminal=true
|
||||
Type=Application
|
||||
Categories=Application;
|
8
build/deb/set-java-propery.sh
Normal file
8
build/deb/set-java-propery.sh
Normal file
@ -0,0 +1,8 @@
|
||||
[Desktop Entry]
|
||||
Name=PAMGuard
|
||||
Comment=Application for passive acoustic monitoring
|
||||
Exec=java -jar /usr/share/pamguard/Pamguard-2.02.14a.jar -c
|
||||
Icon=/path/to/your/icon.png
|
||||
Terminal=true
|
||||
Type=Application
|
||||
Categories=Application;
|
122
pom.xml
122
pom.xml
@ -311,11 +311,82 @@
|
||||
</execution>
|
||||
-->
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugin>
|
||||
|
||||
<!--Creates a deb file for Linux-->
|
||||
<plugin>
|
||||
<artifactId>jdeb</artifactId>
|
||||
<groupId>org.vafer</groupId>
|
||||
<version>1.11</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jdeb</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<controlDir>${basedir}/build/deb</controlDir>
|
||||
<dataSet>
|
||||
<data>
|
||||
<!--TODO-really hte jar file should be named properly but thos would mean we would
|
||||
have to change the anme in the desktop file too. For now create a link to the jar file
|
||||
with correct version number-->
|
||||
<src>${project.build.directory}/Pamguard.jar</src>
|
||||
<type>file</type>
|
||||
<mapper>
|
||||
<type>perm</type>
|
||||
<prefix>/usr/share/pamguard</prefix>
|
||||
</mapper>
|
||||
</data>
|
||||
<data>
|
||||
<src>${basedir}/liblinux</src>
|
||||
<type>directory</type>
|
||||
<includes>*.txt</includes>
|
||||
<includes>*.so</includes>
|
||||
<mapper>
|
||||
<type>perm</type>
|
||||
<prefix>/usr/share/pamguard/liblinux</prefix>
|
||||
</mapper>
|
||||
</data>
|
||||
<data>
|
||||
<src>${basedir}/build/deb/PAMGuardIcon2.png</src>
|
||||
<type>file</type>
|
||||
<mapper>
|
||||
<type>perm</type>
|
||||
<prefix>/usr/share/pamguard</prefix>
|
||||
</mapper>
|
||||
</data>
|
||||
<data>
|
||||
<src>${basedir}/build/deb/pamguard.desktop</src>
|
||||
<type>file</type>
|
||||
<mapper>
|
||||
<type>perm</type>
|
||||
<prefix>/usr/share/applications</prefix>
|
||||
</mapper>
|
||||
</data>
|
||||
<data>
|
||||
<type>link</type>
|
||||
<linkName>/usr/share/pamguard/PAMGuard</linkName>
|
||||
<linkTarget>/usr/share/pamguard/${project.build.finalName}.jar</linkTarget>
|
||||
<symlink>true</symlink>
|
||||
</data>
|
||||
<!--<data>
|
||||
<src>${project.basedir}/build/deb/set-java-property.sh</src>
|
||||
<type>file</type>
|
||||
<mapper>
|
||||
<type>perm</type>
|
||||
<prefix>/usr/bin</prefix>
|
||||
<filemode>755</filemode>
|
||||
</mapper>
|
||||
</data>-->
|
||||
</dataSet>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
|
||||
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
|
||||
@ -359,6 +430,51 @@
|
||||
|
||||
</profiles>
|
||||
|
||||
<!-- Plugin which creates a .dmg file for MacOS.
|
||||
<plugin>
|
||||
<groupId>de.perdian.maven.plugins</groupId>
|
||||
<artifactId>macosappbundler-maven-plugin</artifactId>
|
||||
<version>1.21.1</version>
|
||||
<configuration>
|
||||
<plist>
|
||||
<JVMMainClassName>pamguard.Pamguard</JVMMainClassName>
|
||||
<CFBundleIconFile>src/Resources/PamguardIcon2.icns</CFBundleIconFile>
|
||||
<CFBundleDisplayName>PAMGuard</CFBundleDisplayName>
|
||||
<CFBundleDevelopmentRegion>English</CFBundleDevelopmentRegion>
|
||||
<CFBundleURLTypes>
|
||||
<string>msa</string>
|
||||
</CFBundleURLTypes>
|
||||
<JVMVersion>21+</JVMVersion>
|
||||
<JVMArguments>
|
||||
<string>-c</string>
|
||||
</JVMArguments>
|
||||
</plist>
|
||||
<dmg>
|
||||
<generate>true</generate>
|
||||
<additionalResources>
|
||||
<additionalResource>
|
||||
<directory>src/target/bundle/</directory>
|
||||
</additionalResource>
|
||||
</additionalResources>
|
||||
</dmg>
|
||||
<jdk>
|
||||
<include>false</include>
|
||||
<location>/Library/Java/JavaVirtualMachines/amazon-corretto-21.jdk</location>
|
||||
</jdk>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>bundle</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>-->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<reporting>
|
||||
@ -1065,7 +1181,7 @@
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.pamguard</groupId>
|
||||
<artifactId>x3</artifactId>
|
||||
<artifactId>X3</artifactId>
|
||||
<version>2.2.8</version>
|
||||
</dependency>
|
||||
|
||||
|
@ -82,6 +82,7 @@ public abstract class DLModelWorker<T> {
|
||||
DLTransform transform = modelTransforms.get(0);
|
||||
for (int i =0; i<modelTransforms.size(); i++) {
|
||||
transform = modelTransforms.get(i).transformData(transform);
|
||||
|
||||
// //TEMP
|
||||
// if (transform instanceof FreqTransform) {
|
||||
// transformedData = ((FreqTransform) transform).getSpecTransfrom().getTransformedData();
|
||||
|
@ -49,7 +49,7 @@ public class GenericModelWorker extends DLModelWorker<StandardPrediction> {
|
||||
waveStack[i] = transformedDataStack[i][0];
|
||||
}
|
||||
|
||||
System.out.println("RUN GENERIC MODEL WAVE: " + waveStack.length + " " + waveStack[0].length + " " + waveStack[0][0] + " " + PamArrayUtils.max( waveStack[0]));
|
||||
// System.out.println("RUN GENERIC MODEL WAVE: " + waveStack.length + " " + waveStack[0].length + " " + waveStack[0][0] + " " + PamArrayUtils.max( waveStack[0]));
|
||||
// PamArrayUtils.printArray(waveStack[0]);
|
||||
results = getModel().runModel(waveStack);
|
||||
}
|
||||
|
@ -1,12 +1,18 @@
|
||||
package test.rawDeepLearningClassifier;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.jamdev.jdl4pam.transforms.DLTransform;
|
||||
import org.jamdev.jdl4pam.transforms.DLTransformsFactory;
|
||||
import org.jamdev.jdl4pam.transforms.DLTransfromParams;
|
||||
import org.jamdev.jdl4pam.transforms.SimpleTransformParams;
|
||||
import org.jamdev.jdl4pam.transforms.WaveTransform;
|
||||
import org.jamdev.jdl4pam.utils.DLMatFile;
|
||||
import org.jamdev.jpamutils.wavFiles.AudioData;
|
||||
import org.jamdev.jdl4pam.transforms.DLTransform.DLTransformType;
|
||||
@ -19,6 +25,7 @@ import rawDeepLearningClassifier.dlClassification.genericModel.StandardPredictio
|
||||
import rawDeepLearningClassifier.segmenter.GroupedRawData;
|
||||
import us.hebi.matlab.mat.format.Mat5;
|
||||
import us.hebi.matlab.mat.format.Mat5File;
|
||||
import us.hebi.matlab.mat.types.MatFile;
|
||||
import us.hebi.matlab.mat.types.Matrix;
|
||||
import us.hebi.matlab.mat.types.Struct;
|
||||
|
||||
@ -30,9 +37,10 @@ public class ClickDLTest {
|
||||
|
||||
/**
|
||||
* Test just one click
|
||||
* @throws
|
||||
*/
|
||||
@Test
|
||||
public void aclickDLTest() {
|
||||
public void aclickDLTest() {
|
||||
|
||||
System.out.println("CLickDLTest: Single click test");
|
||||
|
||||
@ -40,15 +48,22 @@ public class ClickDLTest {
|
||||
//relative paths to the resource folders.
|
||||
System.out.println("*****Click classification Deep Learning C*****");
|
||||
|
||||
// //relative paths to the resource folders.
|
||||
// String relModelPath = "/Users/jdjm/Library/CloudStorage/Dropbox/PAMGuard_dev/Deep_Learning/click_classifier_Thomas/model_v2/model_pb/saved_model.pb";
|
||||
// String clicksPath = "/Users/jdjm/Library/CloudStorage/Dropbox/PAMGuard_dev/Deep_Learning/click_classifier_Thomas/model_v2/example_2000021.mat";
|
||||
|
||||
//relative paths to the resource folders.
|
||||
String relModelPath = "/Users/jdjm/Library/CloudStorage/Dropbox/PAMGuard_dev/Deep_Learning/click_classifier_Thomas/model_v2/model_pb/saved_model.pb";
|
||||
String clicksPath = "/Users/jdjm/Library/CloudStorage/Dropbox/PAMGuard_dev/Deep_Learning/click_classifier_Thomas/model_v2/example_2000021.mat";
|
||||
|
||||
String relModelPath = "/home/jamiemac/Dropbox/PAMGuard_dev/Deep_Learning/click_classifier_Thomas/model_v2/model_pb/saved_model.pb";
|
||||
String clicksPath = "/home/jamiemac/Dropbox/PAMGuard_dev/Deep_Learning/click_classifier_Thomas/model_v2/example_2000021.mat";
|
||||
//load the click up
|
||||
|
||||
// String matout = "/home/jamiemac/MATLAB-Drive/MATLAB/PAMGUARD/deep_learning/generic_classifier/example_2000021_transforms.mat";
|
||||
String matout=null;
|
||||
// load the click data up.
|
||||
Path clkPath = Paths.get(clicksPath);
|
||||
PredGroupedRawData clickData = null;
|
||||
|
||||
Struct matclkStruct = Mat5.newStruct();
|
||||
try {
|
||||
Mat5File mfr = Mat5.readFromFile(clkPath.toAbsolutePath().normalize().toString());
|
||||
|
||||
@ -60,6 +75,7 @@ public class ClickDLTest {
|
||||
Matrix modelInputM= mlArrayRetrived.get("wave_pad", 0);
|
||||
|
||||
double[][] clickWaveform= PamArrayUtils.matrix2array(clickWavM);
|
||||
clickWaveform=PamArrayUtils.transposeMatrix(clickWaveform);
|
||||
|
||||
//get the raw model input so we can test the model directly.
|
||||
double[][] pythonModelInput= PamArrayUtils.matrix2array(modelInputM);
|
||||
@ -90,12 +106,14 @@ public class ClickDLTest {
|
||||
|
||||
//waveform transforms.
|
||||
dlTransformParamsArr.add(new SimpleTransformParams(DLTransformType.DECIMATE_SCIPY, 248000.));
|
||||
dlTransformParamsArr.add(new SimpleTransformParams(DLTransformType.NORMALISE_WAV, 0., 1, AudioData.ZSCORE)); //needs to be here
|
||||
dlTransformParamsArr.add(new SimpleTransformParams(DLTransformType.PEAK_TRIM, 64, 1));
|
||||
dlTransformParamsArr.add(new SimpleTransformParams(DLTransformType.NORMALISE_WAV, 0., 1, AudioData.ZSCORE));
|
||||
|
||||
|
||||
genericModelParams.dlTransfromParams = dlTransformParamsArr;
|
||||
genericModelParams.dlTransfroms = DLTransformsFactory.makeDLTransforms((ArrayList<DLTransfromParams>)genericModelParams.dlTransfromParams);
|
||||
|
||||
|
||||
|
||||
//create the clicks.
|
||||
path = Paths.get(clicksPath);
|
||||
|
||||
@ -107,28 +125,56 @@ public class ClickDLTest {
|
||||
|
||||
System.out.println("Waveform input: " + groupedData.get(0).getRawData().length + " " + groupedData.get(0).getRawData()[0].length);
|
||||
|
||||
ArrayList<StandardPrediction> genericPrediction = genericModelWorker.runModel(groupedData,SAMPLE_RATE, 0);
|
||||
ArrayList<StandardPrediction> genericPrediction = genericModelWorker.runModel(groupedData,248000, 0);
|
||||
|
||||
System.out.println("PAMGuard input len: " + pythonModelInputF.length);
|
||||
// System.out.println("PAMGuard input len: " + pythonModelInputF.length);
|
||||
|
||||
float[] outputPAMGuard = genericPrediction.get(0).getPrediction();
|
||||
|
||||
System.out.println("Model output PAMGuard: " + outputPAMGuard[0]);
|
||||
|
||||
//run the transforms so we can take a look at the inpout
|
||||
((WaveTransform) genericModelParams.dlTransfroms.get(0)).setWaveData(new AudioData(groupedData.get(0).getRawData()[0], 248000));;
|
||||
//create the transformed wave
|
||||
DLTransform transform = genericModelParams.dlTransfroms.get(0);
|
||||
double[] audioOut = null;
|
||||
for (int i=0; i<genericModelParams.dlTransfroms .size(); i++) {
|
||||
transform = genericModelParams.dlTransfroms.get(i).transformData(transform);
|
||||
audioOut = ((WaveTransform) transform).getWaveData().getScaledSampleAmplitudes();
|
||||
matclkStruct.set(transform.getDLTransformType().getJSONString(), DLMatFile.array2Matrix(audioOut));
|
||||
}
|
||||
|
||||
//RUN THE RAW MODEL with Python transformed input
|
||||
|
||||
System.out.println("Python input len: " + pythonModelInputF.length);
|
||||
// System.out.println("Python input len: " + pythonModelInputF.length);
|
||||
// float[] outPutPython = genericModelWorker.getModel().runModel(new float[][] {PamArrayUtils.double2Float(audioOut)});
|
||||
|
||||
float[] outPutPython = genericModelWorker.getModel().runModel(new float[][] {pythonModelInputF});
|
||||
|
||||
|
||||
System.out.println("Model output Python: " + outPutPython[0]);
|
||||
|
||||
assertEquals(outputPAMGuard[0], outPutPython[0], 0.05);
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
assertTrue(false); //make sure the unit test fails
|
||||
return;
|
||||
}
|
||||
|
||||
if (matout!=null) {
|
||||
// Create MAT file with a scalar in a nested struct
|
||||
MatFile matFile = Mat5.newMatFile()
|
||||
.addArray("click_transforms", matclkStruct);
|
||||
// Serialize to disk using default configurations
|
||||
try {
|
||||
Mat5.writeToFile(matFile, matout);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -141,8 +187,8 @@ public class ClickDLTest {
|
||||
System.out.println("*****Click classification Deep Learning C*****");
|
||||
|
||||
//relative paths to the resource folders.
|
||||
String relModelPath = "./src/test/resources/rawDeepLearningClassifier/Generic/risso_click/uniform_model/saved_model.pb";
|
||||
String clicksPath = "./src/test/resources/rawDeepLearningClassifier/Generic/risso_click/clicks.mat";
|
||||
String relModelPath = "/home/jamiemac/Dropbox/PAMGuard_dev/Deep_Learning/click_classifier_Thomas/model_v2/model_pb/saved_model.pb";
|
||||
String clicksPath = "/home/jamiemac/Dropbox/PAMGuard_dev/Deep_Learning/click_classifier_Thomas/model_v2/Click_Detector_Click_Detector_Clicks_20220603_111000.mat";
|
||||
|
||||
Path path = Paths.get(relModelPath);
|
||||
|
||||
@ -157,8 +203,8 @@ public class ClickDLTest {
|
||||
|
||||
//waveform transforms.
|
||||
dlTransformParamsArr.add(new SimpleTransformParams(DLTransformType.DECIMATE_SCIPY, 248000.));
|
||||
dlTransformParamsArr.add(new SimpleTransformParams(DLTransformType.PEAK_TRIM, 128, 1));
|
||||
dlTransformParamsArr.add(new SimpleTransformParams(DLTransformType.NORMALISE_WAV, 0., 1, AudioData.ZSCORE));
|
||||
dlTransformParamsArr.add(new SimpleTransformParams(DLTransformType.PEAK_TRIM, 64, 1));
|
||||
|
||||
genericModelParams.dlTransfromParams = dlTransformParamsArr;
|
||||
genericModelParams.dlTransfroms = DLTransformsFactory.makeDLTransforms((ArrayList<DLTransfromParams>)genericModelParams.dlTransfromParams);
|
||||
@ -203,7 +249,7 @@ public class ClickDLTest {
|
||||
Mat5File mfr = Mat5.readFromFile(filePath);
|
||||
|
||||
// //get array of a name "my_array" from file
|
||||
Struct mlArrayRetrived = mfr.getStruct( "clickpreds" );
|
||||
Struct mlArrayRetrived = mfr.getStruct( "binarydata" );
|
||||
|
||||
int numClicks= mlArrayRetrived.getNumCols();
|
||||
ArrayList<PredGroupedRawData> clicks = new ArrayList<PredGroupedRawData>(numClicks);
|
||||
|
Loading…
Reference in New Issue
Block a user