From a6c4a16d9aabc0ea5d7768dcdc0cb5110ad17bfe Mon Sep 17 00:00:00 2001 From: brian Date: Thu, 10 Aug 2023 10:55:46 +0200 Subject: [PATCH 1/7] Update underlying library versions for javacpp 1.5.9 Signed-off-by: brian --- cavis-common-platform/build.gradle | 65 ++++++------------- .../java/net/brutex/ai/dnn/api/dnnTest.java | 2 +- cavis-native/cavis-native-lib/build.gradle | 4 +- cavis-nd4j/cavis-nd4j-tensorflow/build.gradle | 2 +- 4 files changed, 25 insertions(+), 48 deletions(-) diff --git a/cavis-common-platform/build.gradle b/cavis-common-platform/build.gradle index ac94180c0..9d997dbfc 100644 --- a/cavis-common-platform/build.gradle +++ b/cavis-common-platform/build.gradle @@ -8,19 +8,22 @@ ext { javacppPlatform = osdetector.classifier } - def javacpp = [version: "1.5.7", presetsVersion: "1.5.7"] - def hdf5 = [version: "1.12.1"] + def javacpp = [version: "1.5.9", presetsVersion: "1.5.9"] + def hdf5 = [version: "1.14.1"] def jackson = [version: "2.13.4"] - def cuda = [version: "11.6"] - def cudnn = [version: "8.3"] - def openblas = [version: "0.3.19"] - def numpy = [version: "1.22.2"] + def cuda = [version: "12.1"] + def cudnn = [version: "8.9"] + def openblas = [version: "0.3.23"] + def numpy = [version: "1.24.3"] + def tensorflow_lite = [version: "2.12.0"] def tensorflow = [version: "1.15.5"] - def cpython = [version: "3.10.2"] + def tensorrt = [version: "8.6.1.6"] + def cpython = [version: "3.11.3"] + def mkl = [version:"2023.1"] - def javacv = [version:"1.5.7"] - def opencv = [version: "4.5.5"] - def leptonica = [version: "1.82.0"] + def javacv = [version:"1.5.9"] + def opencv = [version: "4.7.0"] + def leptonica = [version: "1.83.0"] def junit = [version: "5.9.1"] def flatbuffers = [version: "1.10.0"] @@ -41,7 +44,6 @@ dependencies { api enforcedPlatform("io.netty:netty-bom:${netty.version}") api enforcedPlatform("com.fasterxml.jackson:jackson-bom:${jackson.version}") - //api enforcedPlatform("com.fasterxml.jackson.core:jackson-annotations:${jackson.version}") api enforcedPlatform("com.squareup.okhttp3:okhttp-bom:${okhttp3.version}") @@ -49,9 +51,6 @@ dependencies { api enforcedPlatform("io.netty:netty-bom:${netty.version}") api enforcedPlatform("com.fasterxml.jackson:jackson-bom:${jackson.version}") api enforcedPlatform("com.squareup.okhttp3:okhttp-bom:${okhttp3.version}") - //api enforcedPlatform("com.fasterxml.jackson.core:jackson-annotations:${jackson.version}") - //api "com.squareup.okhttp3:okhttp:${okhttp3}.version" - //api "com.squareup.okhttp3:logging-interceptor:${okhttp3}.version" api 'com.google.guava:guava:30.1-jre' api "com.google.protobuf:protobuf-java:3.15.6" @@ -59,18 +58,6 @@ dependencies { api "com.google.protobuf:protobuf-java-util:3.15.6" api "com.google.flatbuffers:flatbuffers-java:${flatbuffers.version}" - /* - api "com.fasterxml.jackson.core:jackson-core:${jackson.version}" - api "com.fasterxml.jackson.core:jackson-databind:${jackson.version}" - api "com.fasterxml.jackson.core:jackson-annotations:${jackson.version}" - - api "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:${jackson.version}" - */ - // api "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jackson.version}" - // api "com.fasterxml.jackson.datatype:jackson-datatype-joda:${jackson.version}" - // api "com.fasterxml.jackson.module:jackson-module-scala_${scalaVersion}" - - api "org.projectlombok:lombok:1.18.28" /*Logging*/ @@ -81,7 +68,7 @@ dependencies { api "ch.qos.logback:logback-classic:1.2.3" api 'ch.qos.logback:logback-core:1.2.3' - + /* commons */ api 'commons-io:commons-io:2.5' api 'commons-codec:commons-codec:1.11' api 'commons-net:commons-net:3.6' @@ -122,18 +109,18 @@ dependencies { api "org.bytedeco:hdf5-platform:${hdf5.version}-${javacpp.presetsVersion}" api "org.bytedeco:hdf5:${hdf5.version}-${javacpp.presetsVersion}" api "org.bytedeco:hdf5:${hdf5.version}-${javacpp.presetsVersion}:${javacppPlatform}" - //api "org.bytedeco:hdf5:${hdf5.version}-${javacpp.presetsVersion}:linux-x86_64" - - api "org.bytedeco:cuda:${cuda.version}-${cudnn.version}-${javacpp.presetsVersion}" api "org.bytedeco:cuda-platform-redist:${cuda.version}-${cudnn.version}-${javacpp.presetsVersion}" - api "org.bytedeco:mkl-dnn:0.21.5-${javacpp.presetsVersion}" - api "org.bytedeco:tensorflow:${tensorflow.version}-${javacpp.presetsVersion}" + api "org.bytedeco:mkl:${mkl.version}-${javacpp.presetsVersion}" + api "org.bytedeco:tensorflow:${tensorflow.version}-1.5.8" //not available for javacpp 1.5.9 ? + api "org.bytedeco:tensorflow-platform:${tensorflow.version}-1.5.8" + api "org.bytedeco:tensorflow-lite:${tensorflow_lite.version}-${javacpp.presetsVersion}" + api "org.bytedeco:tensorflow-lite-platform:${tensorflow_lite.version}-${javacpp.presetsVersion}" + api "org.bytedeco:tensorrt:${tensorrt.version}-${javacpp.presetsVersion}" + api "org.bytedeco:tensorrt-platform:${tensorrt.version}-${javacpp.presetsVersion}" api "org.bytedeco:cpython:${cpython.version}-${javacpp.presetsVersion}:${javacppPlatform}" api "org.bytedeco:numpy:${numpy.version}-${javacpp.presetsVersion}:${javacppPlatform}" - //implementation "org.bytedeco:cpython-platform:3.9.6-1.5.6" - //implementation "org.bytedeco:numpy-platform:1.21.1-1.5.6" /* Apache Spark */ api "org.apache.spark:spark-core_${scalaVersion}:${spark.version}" @@ -167,16 +154,6 @@ dependencies { } } -/* -publishing { - publications { - myPlatform(MavenPublication) { - from components.javaPlatform - } - } -} -*/ - tasks.withType(GenerateModuleMetadata).configureEach { // The value 'enforced-platform' is provided in the validation // error message you got diff --git a/cavis-dnn/cavis-dnn-nn/src/test/java/net/brutex/ai/dnn/api/dnnTest.java b/cavis-dnn/cavis-dnn-nn/src/test/java/net/brutex/ai/dnn/api/dnnTest.java index 182dd9f31..43f32beef 100644 --- a/cavis-dnn/cavis-dnn-nn/src/test/java/net/brutex/ai/dnn/api/dnnTest.java +++ b/cavis-dnn/cavis-dnn-nn/src/test/java/net/brutex/ai/dnn/api/dnnTest.java @@ -78,7 +78,7 @@ class dnnTest { * DenseLayer.Builder().nIn(X_DIM*Y_DIM).nOut(X_DIM*Y_DIM*CHANNELS).activation(Activation.TANH) */ NeuralNetConfiguration network = - NN.net() + NN.nn() .seed(42) .updater(Adam.builder().learningRate(0.0002).beta1(0.5).build()) .gradientNormalization(GradientNormalization.RenormalizeL2PerLayer) diff --git a/cavis-native/cavis-native-lib/build.gradle b/cavis-native/cavis-native-lib/build.gradle index 002f84756..4369274b1 100644 --- a/cavis-native/cavis-native-lib/build.gradle +++ b/cavis-native/cavis-native-lib/build.gradle @@ -52,8 +52,8 @@ buildscript { classpath platform(project(":cavis-common-platform")) classpath group: "org.bytedeco", name: "openblas" classpath group: "org.bytedeco", name: "openblas", classifier: "${javacppPlatform}" - classpath group: "org.bytedeco", name:"mkl-dnn" - classpath group: "org.bytedeco", name:"mkl-dnn", classifier: "${javacppPlatform}" + classpath group: "org.bytedeco", name:"mkl" + classpath group: "org.bytedeco", name:"mkl", classifier: "${javacppPlatform}" classpath group: "org.bytedeco", name: "javacpp" classpath group: "org.bytedeco", name: "javacpp", classifier: "${javacppPlatform}" } diff --git a/cavis-nd4j/cavis-nd4j-tensorflow/build.gradle b/cavis-nd4j/cavis-nd4j-tensorflow/build.gradle index 74c5fed5a..cca9a6f2f 100644 --- a/cavis-nd4j/cavis-nd4j-tensorflow/build.gradle +++ b/cavis-nd4j/cavis-nd4j-tensorflow/build.gradle @@ -28,7 +28,7 @@ dependencies { implementation group: "org.bytedeco", name: "tensorflow" testRuntimeOnly group: "org.bytedeco", name: "tensorflow", classifier: buildTarget if(buildTarget.contains("windows") || buildTarget.contains("linux")) { - testRuntimeOnly group: "org.bytedeco", name: "tensorflow", classifier: "${buildTarget}-gpu" + testRuntimeOnly group: "org.bytedeco", name: 'tensorflow', classifier: "${buildTarget}-gpu", version: '' } implementation "commons-io:commons-io" implementation "com.google.code.gson:gson" From d40c044df4fe73d4d6006c8debb0d8b363bc045c Mon Sep 17 00:00:00 2001 From: brian Date: Thu, 10 Aug 2023 14:19:09 +0200 Subject: [PATCH 2/7] Jenkins pipeline for CUDA builds to include junit post build action Signed-off-by: brian --- .jenkins/linux-x86_64-cuda-build.jenkinsfile | 6 ++++++ .jenkins/linux-x86_64-docker-cuda-build.jenkinsfile | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/.jenkins/linux-x86_64-cuda-build.jenkinsfile b/.jenkins/linux-x86_64-cuda-build.jenkinsfile index a3c252363..61a84921b 100644 --- a/.jenkins/linux-x86_64-cuda-build.jenkinsfile +++ b/.jenkins/linux-x86_64-cuda-build.jenkinsfile @@ -59,4 +59,10 @@ pipeline { } } } + + post { + always { + junit '**/build/test-results/**/*.xml' + } + } } diff --git a/.jenkins/linux-x86_64-docker-cuda-build.jenkinsfile b/.jenkins/linux-x86_64-docker-cuda-build.jenkinsfile index 45cb8987a..fbc7de2fc 100644 --- a/.jenkins/linux-x86_64-docker-cuda-build.jenkinsfile +++ b/.jenkins/linux-x86_64-docker-cuda-build.jenkinsfile @@ -72,4 +72,10 @@ pipeline { } } } + + post { + always { + junit '**/build/test-results/**/*.xml' + } + } } From d5728cbd8e4c1f41961c484f78bfb14fa9c5cb8a Mon Sep 17 00:00:00 2001 From: brian Date: Thu, 10 Aug 2023 21:21:09 +0200 Subject: [PATCH 3/7] Fix internal archiva credential parameter Signed-off-by: brian --- .jenkins/linux-x86_64-cpu-build.jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.jenkins/linux-x86_64-cpu-build.jenkinsfile b/.jenkins/linux-x86_64-cpu-build.jenkinsfile index 8dc45ce09..4876b013c 100644 --- a/.jenkins/linux-x86_64-cpu-build.jenkinsfile +++ b/.jenkins/linux-x86_64-cpu-build.jenkinsfile @@ -65,7 +65,7 @@ pipeline { }*/ stage('publish-linux-cpu') { environment { - MAVEN = credentials('Internal Archiva') + MAVEN = credentials('Internal_Archiva') OSSRH = credentials('OSSRH') } From 704f4860d5c91ea08d08be28575d772804759486 Mon Sep 17 00:00:00 2001 From: brian Date: Fri, 11 Aug 2023 08:03:29 +0200 Subject: [PATCH 4/7] Update vulnerable hadoop-common from 3.2.0 to 3.2.4 Signed-off-by: brian --- cavis-dnn/cavis-dnn-spark/cavis-dnn-spark-core/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cavis-dnn/cavis-dnn-spark/cavis-dnn-spark-core/build.gradle b/cavis-dnn/cavis-dnn-spark/cavis-dnn-spark-core/build.gradle index 3b4b2ae41..8b23c7f1d 100644 --- a/cavis-dnn/cavis-dnn-spark/cavis-dnn-spark-core/build.gradle +++ b/cavis-dnn/cavis-dnn-spark/cavis-dnn-spark-core/build.gradle @@ -31,7 +31,7 @@ dependencies { implementation projects.cavisDnn.cavisDnnData.cavisDnnDataDatasets implementation projects.cavisDnn.cavisDnnData.cavisDnnDataDatavecIterators implementation projects.cavisDnn.cavisDnnData.cavisDnnDataUtilityIterators - implementation "org.apache.hadoop:hadoop-common:3.2.0" + implementation "org.apache.hadoop:hadoop-common:3.2.4" implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml" implementation projects.cavisDatavec.cavisDatavecApi implementation projects.cavisDatavec.cavisDatavecSpark.cavisDatavecSparkCore From d2972e4f24f2bb3c9e4a372dbcd34e07711baff1 Mon Sep 17 00:00:00 2001 From: brian Date: Fri, 11 Aug 2023 09:04:22 +0200 Subject: [PATCH 5/7] Adding collection of junit test results for jenkins CPU pipelines Signed-off-by: brian --- .jenkins/linux-x86_64-cpu-build.jenkinsfile | 5 +++++ .jenkins/linux-x86_64-docker-cpu-build.jenkinsfile | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/.jenkins/linux-x86_64-cpu-build.jenkinsfile b/.jenkins/linux-x86_64-cpu-build.jenkinsfile index 4876b013c..5473efbc2 100644 --- a/.jenkins/linux-x86_64-cpu-build.jenkinsfile +++ b/.jenkins/linux-x86_64-cpu-build.jenkinsfile @@ -79,4 +79,9 @@ pipeline { } } } + post { + always { + junit '**/build/test-results/**/*.xml' + } + } } diff --git a/.jenkins/linux-x86_64-docker-cpu-build.jenkinsfile b/.jenkins/linux-x86_64-docker-cpu-build.jenkinsfile index fc4b237db..816aa1efc 100644 --- a/.jenkins/linux-x86_64-docker-cpu-build.jenkinsfile +++ b/.jenkins/linux-x86_64-docker-cpu-build.jenkinsfile @@ -85,4 +85,9 @@ pipeline { } } } + post { + always { + junit '**/build/test-results/**/*.xml' + } + } } From a40d5aa7cf28b53c6d7cd32e542dbf5d59d285ed Mon Sep 17 00:00:00 2001 From: brian Date: Sat, 12 Aug 2023 20:25:46 +0200 Subject: [PATCH 6/7] Update docker image to 12.1.0-cudnn8-devel-ubuntu22.04 Signed-off-by: brian --- .docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 00e1ec14b..766b86554 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -1,4 +1,4 @@ -FROM nvidia/cuda:11.4.3-cudnn8-devel-ubuntu20.04 +FROM nvidia/cuda:12.1.0-cudnn8-devel-ubuntu22.04 RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y openjdk-11-jdk wget build-essential checkinstall zlib1g-dev libssl-dev git From 090c5ab2ebd7291ed6a26320596eb67745fb5ac5 Mon Sep 17 00:00:00 2001 From: brian Date: Mon, 14 Aug 2023 14:07:03 +0200 Subject: [PATCH 7/7] Updating extended GAN tests Signed-off-by: brian --- .../ai/nd4j/tests/LoadBackendTests.java | 4 +- .../src/test/java/net/brutex/gan/App2.java | 257 ++++++++++-------- .../test/java/net/brutex/gan/App2Config.java | 11 +- .../test/java/net/brutex/gan/App2Display.java | 160 +++++++++++ .../src/test/java/net/brutex/gan/App2GUI.java | 61 +++++ .../net/brutex/gan}/simplelogger.properties | 0 6 files changed, 374 insertions(+), 119 deletions(-) create mode 100644 brutex-extended-tests/src/test/java/net/brutex/gan/App2Display.java create mode 100644 brutex-extended-tests/src/test/java/net/brutex/gan/App2GUI.java rename brutex-extended-tests/src/test/{resources => java/net/brutex/gan}/simplelogger.properties (100%) diff --git a/brutex-extended-tests/src/test/java/net/brutex/ai/nd4j/tests/LoadBackendTests.java b/brutex-extended-tests/src/test/java/net/brutex/ai/nd4j/tests/LoadBackendTests.java index 4ce2844d5..4420a2b4a 100644 --- a/brutex-extended-tests/src/test/java/net/brutex/ai/nd4j/tests/LoadBackendTests.java +++ b/brutex-extended-tests/src/test/java/net/brutex/ai/nd4j/tests/LoadBackendTests.java @@ -36,9 +36,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class LoadBackendTests { @Test - public void loadBackend() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException { + public void loadBackend() throws NoSuchFieldException, IllegalAccessException { // check if Nd4j is there - //Logger.getLogger(LoadBackendTests.class.getName()).info("System java.library.path: " + System.getProperty("java.library.path")); + Logger.getLogger(LoadBackendTests.class.getName()).info("System java.library.path: " + System.getProperty("java.library.path")); final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths"); sysPathsField.setAccessible(true); sysPathsField.set(null, null); diff --git a/brutex-extended-tests/src/test/java/net/brutex/gan/App2.java b/brutex-extended-tests/src/test/java/net/brutex/gan/App2.java index 73e271fe1..1ed50b048 100644 --- a/brutex-extended-tests/src/test/java/net/brutex/gan/App2.java +++ b/brutex-extended-tests/src/test/java/net/brutex/gan/App2.java @@ -37,6 +37,8 @@ import org.datavec.image.loader.NativeImageLoader; import org.datavec.image.recordreader.ImageRecordReader; import org.datavec.image.transform.*; import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator; +import org.deeplearning4j.datasets.iterator.ExistingDataSetIterator; +import org.deeplearning4j.datasets.iterator.INDArrayDataSetIterator; import org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator; import org.deeplearning4j.nn.conf.GradientNormalization; import org.deeplearning4j.nn.conf.NeuralNetConfiguration; @@ -46,24 +48,27 @@ import org.deeplearning4j.nn.multilayer.MultiLayerNetwork; import org.deeplearning4j.optimize.listeners.PerformanceListener; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; +import org.nd4j.evaluation.classification.Evaluation; import org.nd4j.linalg.api.ndarray.INDArray; import org.nd4j.linalg.dataset.DataSet; import org.nd4j.linalg.dataset.api.iterator.DataSetIterator; import org.nd4j.linalg.factory.Nd4j; +import static net.brutex.gan.App2Config.BATCHSIZE; + @Slf4j public class App2 { final int INPUT = CHANNELS*DIMENSIONS*DIMENSIONS; - static final float COLORSPACE = 255f; + static final int DIMENSIONS = 28; static final int CHANNELS = 1; final int ARRAY_SIZE_PER_SAMPLE = DIMENSIONS*DIMENSIONS*CHANNELS; - final int OUTPUT_PER_PANEL = 10; + final boolean BIAS = true; - static final int BATCHSIZE=128; + private JFrame frame2, frame; static final String OUTPUT_DIR = "d:/out/"; @@ -76,7 +81,7 @@ public class App2 { Nd4j.getMemoryManager().setAutoGcWindow(15 * 1000); MnistDataSetIterator mnistIter = new MnistDataSetIterator(20, 200); - FileSplit fileSplit = new FileSplit(new File("c:/users/brian/downloads/humans2"), NativeImageLoader.getALLOWED_FORMATS()); + FileSplit fileSplit = new FileSplit(new File("c:/users/brian/downloads/humans3"), NativeImageLoader.getALLOWED_FORMATS()); ImageTransform transform = new ColorConversionTransform(new Random(42), 7 ); ImageTransform transform2 = new ShowImageTransform("Tester", 30); ImageTransform transform3 = new ResizeImageTransform(DIMENSIONS, DIMENSIONS); @@ -129,12 +134,94 @@ public class App2 { log.info("Generator Summary:\n{}", gen.summary()); log.info("GAN Summary:\n{}", gan.summary()); - dis.addTrainingListeners(new PerformanceListener(10, true, "DIS")); - gen.addTrainingListeners(new PerformanceListener(10, true, "GEN")); - gan.addTrainingListeners(new PerformanceListener(10, true, "GAN")); + dis.addTrainingListeners(new PerformanceListener(3, true, "DIS")); + //gen.addTrainingListeners(new PerformanceListener(3, true, "GEN")); //is never trained separately from GAN + gan.addTrainingListeners(new PerformanceListener(3, true, "GAN")); +/* + Thread vt = + new Thread( + new Runnable() { + @Override + public void run() { + while (true) { + visualize(0, 0, gen); + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + }); + vt.start(); +*/ - int j = 0; - for (int i = 0; i < 51; i++) { //epoch + App2Display display = new App2Display(); + //Repack training data with new fake/real label. Original MNist has 10 labels, one for each digit + DataSet data = null; + int j =0; + for(int i=0;i1) { - bi = new BufferedImage(DIMENSIONS, DIMENSIONS, BufferedImage.TYPE_INT_RGB); //need to change here based on channels - } else { - bi = new BufferedImage(DIMENSIONS, DIMENSIONS, BufferedImage.TYPE_BYTE_GRAY); //need to change here based on channels - } - final int imageSize = DIMENSIONS * DIMENSIONS; - final int offset = batchElement * imageSize; - int pxl = offset * CHANNELS; //where to start in the INDArray - - //Image in NCHW - channels first format - for (int c = 0; c < CHANNELS; c++) { //step through the num channels for each pixel - for (int y = 0; y < DIMENSIONS; y++) { // step through the columns x - for (int x = 0; x < DIMENSIONS; x++) { //step through the rows y - float f_pxl = tensor.getFloat(pxl) * COLORSPACE; - if(isOrig) log.trace("'{}.' Image (x,y,c): ({}, {}, {}) with INDArray with index {} and value '{}'", batchElement, x, y, c, pxl, f_pxl); - bi.getRaster().setSample(x, y, c, f_pxl); - pxl++; //next item in INDArray - } - } - } - ImageIcon orig = new ImageIcon(bi); - Image imageScaled = orig.getImage().getScaledInstance((4 * DIMENSIONS), (4 * DIMENSIONS), Image.SCALE_DEFAULT); - ImageIcon scaled = new ImageIcon(imageScaled); - if(! isOrig) saveImage(imageScaled, batchElement, isOrig); - return new JLabel(scaled); + */ } - private static void saveImage(Image image, int batchElement, boolean isOrig) { - String outputDirectory = OUTPUT_DIR; // Set the output directory where the images will be saved - try { - // Save the images to disk - saveImage(image, outputDirectory, UUID.randomUUID().toString()+".png"); - log.debug("Images saved successfully."); - } catch (IOException e) { - log.error("Error saving the images: {}", e.getMessage()); - } - } - private static void saveImage(Image image, String outputDirectory, String fileName) throws IOException { - File directory = new File(outputDirectory); - if (!directory.exists()) { - directory.mkdir(); - } - File outputFile = new File(directory, fileName); - ImageIO.write(imageToBufferedImage(image), "png", outputFile); - } - public static BufferedImage imageToBufferedImage(Image image) { - if (image instanceof BufferedImage) { - return (BufferedImage) image; - } - // Create a buffered image with the same dimensions and transparency as the original image - BufferedImage bufferedImage; - if (CHANNELS > 1) { - bufferedImage = - new BufferedImage( - image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); - } else { - bufferedImage = - new BufferedImage( - image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_BYTE_GRAY); - } - // Draw the original image onto the buffered image - Graphics2D g2d = bufferedImage.createGraphics(); - g2d.drawImage(image, 0, 0, null); - g2d.dispose(); - return bufferedImage; - } + + + + + + + + private static void updateGen(MultiLayerNetwork gen, MultiLayerNetwork gan) { for (int i = 0; i < gen.getLayers().length; i++) { gen.getLayer(i).setParams(gan.getLayer(i).getParams()); @@ -341,4 +331,41 @@ public class App2 { } } + + @Test + void testDiskriminator() throws IOException { + MultiLayerNetwork net = new MultiLayerNetwork(App2Config.discriminator()); + net.init(); + net.addTrainingListeners(new PerformanceListener(10, true, "DIS")); + DataSetIterator trainData = new MnistDataSetIterator(BATCHSIZE, true, 42); + + DataSet data = null; + for(int i=0;i=OUTPUT_PER_PANEL) { + real_panel.remove(0); + } + real_panel.add(new JLabel(icon)); + } else { + if(fake_panel.getComponents().length>=OUTPUT_PER_PANEL) { + fake_panel.remove(0); + } + fake_panel.add(new JLabel(icon)); + } + } + } + frame.pack(); + frame.repaint(); + } + + public Image getImage(INDArray tensor, int batchElement, boolean isOrig) { + final BufferedImage bi; + if(CHANNELS >1) { + bi = new BufferedImage(X_DIM, Y_DIM, BufferedImage.TYPE_INT_RGB); //need to change here based on channels + } else { + bi = new BufferedImage(X_DIM, Y_DIM, BufferedImage.TYPE_BYTE_GRAY); //need to change here based on channels + } + final int imageSize = X_DIM * Y_DIM; + final int offset = batchElement * imageSize; + int pxl = offset * CHANNELS; //where to start in the INDArray + + //Image in NCHW - channels first format + for (int c = 0; c < CHANNELS; c++) { //step through the num channels for each pixel + for (int y = 0; y < X_DIM; y++) { // step through the columns x + for (int x = 0; x < Y_DIM; x++) { //step through the rows y + float f_pxl = tensor.getFloat(pxl) * COLORSPACE; + if(isOrig) log.trace("'{}.'{} Image (x,y,c): ({}, {}, {}) with INDArray with index {} and value '{}'", batchElement, isOrig ? "Real" : "Fake", x, y, c, pxl, f_pxl); + bi.getRaster().setSample(x, y, c, f_pxl); + pxl++; //next item in INDArray + } + } + } + ImageIcon orig = new ImageIcon(bi); + Image imageScaled = orig.getImage().getScaledInstance((4 * X_DIM), (4 * Y_DIM), Image.SCALE_DEFAULT); + ImageIcon scaled = new ImageIcon(imageScaled); + //if(! isOrig) saveImage(imageScaled, batchElement, isOrig); + return imageScaled; + + } + + private static void saveImage(Image image, int batchElement, boolean isOrig) { + String outputDirectory = OUTPUT_DIR; // Set the output directory where the images will be saved + + try { + // Save the images to disk + saveImage(image, outputDirectory, UUID.randomUUID().toString()+".png"); + + log.debug("Images saved successfully."); + } catch (IOException e) { + log.error("Error saving the images: {}", e.getMessage()); + } + } + private static void saveImage(Image image, String outputDirectory, String fileName) throws IOException { + File directory = new File(outputDirectory); + if (!directory.exists()) { + directory.mkdir(); + } + + File outputFile = new File(directory, fileName); + ImageIO.write(imageToBufferedImage(image), "png", outputFile); + } + + public static BufferedImage imageToBufferedImage(Image image) { + if (image instanceof BufferedImage) { + return (BufferedImage) image; + } + + // Create a buffered image with the same dimensions and transparency as the original image + BufferedImage bufferedImage; + if (CHANNELS > 1) { + bufferedImage = + new BufferedImage( + image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); + } else { + bufferedImage = + new BufferedImage( + image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_BYTE_GRAY); + } + + // Draw the original image onto the buffered image + Graphics2D g2d = bufferedImage.createGraphics(); + g2d.drawImage(image, 0, 0, null); + g2d.dispose(); + + return bufferedImage; + } +} diff --git a/brutex-extended-tests/src/test/java/net/brutex/gan/App2GUI.java b/brutex-extended-tests/src/test/java/net/brutex/gan/App2GUI.java new file mode 100644 index 000000000..8478ab3e6 --- /dev/null +++ b/brutex-extended-tests/src/test/java/net/brutex/gan/App2GUI.java @@ -0,0 +1,61 @@ +package net.brutex.gan; + +import javax.swing.JPanel; +import javax.swing.JSplitPane; +import javax.swing.JLabel; +import java.awt.BorderLayout; + +public class App2GUI extends JPanel { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JPanel overall_panel; + private JPanel real_panel; + private JPanel gen_panel; + + /** + * Create the panel. + */ + public App2GUI() { + + overall_panel = new JPanel(); + add(overall_panel); + + JSplitPane splitPane = new JSplitPane(); + overall_panel.add(splitPane); + + JPanel p1 = new JPanel(); + splitPane.setLeftComponent(p1); + p1.setLayout(new BorderLayout(0, 0)); + + JLabel lblNewLabel = new JLabel("Generator"); + p1.add(lblNewLabel, BorderLayout.NORTH); + + gen_panel = new JPanel(); + p1.add(gen_panel, BorderLayout.SOUTH); + + JPanel p2 = new JPanel(); + splitPane.setRightComponent(p2); + p2.setLayout(new BorderLayout(0, 0)); + + JLabel lblNewLabel_1 = new JLabel("Real"); + p2.add(lblNewLabel_1, BorderLayout.NORTH); + + real_panel = new JPanel(); + p2.add(real_panel, BorderLayout.SOUTH); + + } + + + public JPanel getOverall_panel() { + return overall_panel; + } + public JPanel getReal_panel() { + return real_panel; + } + public JPanel getGen_panel() { + return gen_panel; + } +} diff --git a/brutex-extended-tests/src/test/resources/simplelogger.properties b/brutex-extended-tests/src/test/java/net/brutex/gan/simplelogger.properties similarity index 100% rename from brutex-extended-tests/src/test/resources/simplelogger.properties rename to brutex-extended-tests/src/test/java/net/brutex/gan/simplelogger.properties