deepjavalibrary / djl

An Engine-Agnostic Deep Learning Framework in Java
https://djl.ai
Apache License 2.0
4.13k stars 656 forks source link

Many warnings during training #2088

Closed Ledmington closed 2 years ago

Ledmington commented 2 years ago

Description

During training, a warning inside ai.djl.ndarray.index.NDArrayIndexer appears so many times that I cannot see the ProgressBar updating.

Expected Behavior

The warning should not show up.

Error Message

[main] WARN ai.djl.ndarray.index.NDArrayIndexer - The definition of the getter by array NDIndex: get(NDIndex array) has changed from pick to take.If you still want to use array index as pick, then do it explicitly by get(new NDIndex().addPickDim(array)); This message is repeated dozens of times during each step of each epoch.

How to Reproduce?

This is my Java source code:

package mlj;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import ai.djl.Application;
import ai.djl.Model;
import ai.djl.basicdataset.cv.classification.Mnist;
import ai.djl.metric.Metrics;
import ai.djl.ndarray.types.Shape;
import ai.djl.nn.Activation;
import ai.djl.nn.Blocks;
import ai.djl.nn.SequentialBlock;
import ai.djl.nn.core.Linear;
import ai.djl.training.DefaultTrainingConfig;
import ai.djl.training.EasyTrain;
import ai.djl.training.Trainer;
import ai.djl.training.evaluator.Accuracy;
import ai.djl.training.listener.TrainingListener;
import ai.djl.training.loss.Loss;
import ai.djl.training.util.ProgressBar;
import ai.djl.translate.TranslateException;

public class App {
    public static void main(final String[] args) {
        final Application application = Application.CV.IMAGE_CLASSIFICATION;
        final SequentialBlock block = new SequentialBlock();
        final long inputSize = 28 * 28;
        final long outputSize = 10;
        block.add(Blocks.batchFlattenBlock(inputSize));
        block.add(Linear.builder().setUnits(128).build());
        block.add(Activation::relu);
        block.add(Linear.builder().setUnits(64).build());
        block.add(Activation::relu);
        block.add(Linear.builder().setUnits(outputSize).build());
        System.out.println(block);

        final int batchSize = 32;
        final Mnist mnist = Mnist.builder().setSampling(batchSize, true).build();
        try {
            mnist.prepare(new ProgressBar());
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println("Prepared " + mnist.size() + " records");

        final Model model = Model.newInstance("belleffemo");
        model.setBlock(block);
        System.out.println("Model: " + model);

        final DefaultTrainingConfig config = new DefaultTrainingConfig(Loss.softmaxCrossEntropyLoss())
                .addEvaluator(new Accuracy())
                .addTrainingListeners(TrainingListener.Defaults.logging());

        final Trainer trainer = model.newTrainer(config);
        trainer.setMetrics(new Metrics());
        System.out.println("Trainer: " + trainer);

        System.out.println("Initializing...");
        trainer.initialize(new Shape(1, 28 * 28));

        final int epochs = 10;

        System.out.println("Training...");
        try {
            EasyTrain.fit(trainer, epochs, mnist, null);
        } catch (IOException | TranslateException e) {
            e.printStackTrace();
        }

        try {
            final Path modelDir = Paths.get("build/belleffemo");
            Files.createDirectories(modelDir);
            model.setProperty("Epoch", String.valueOf(epochs));
            model.save(modelDir, "belleffemo");
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println("Trained model: " + model);

        trainer.close();
        model.close();
    }
}

and this is my build.gradle:

plugins {
    id 'java'
    id 'application'
    id 'com.diffplug.spotless' version '6.11.0'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'ai.djl:api:0.19.0'
    implementation 'ai.djl:basicdataset:0.19.0'
    implementation 'ai.djl:model-zoo:0.19.0'
    implementation 'ai.djl.mxnet:mxnet-engine:0.19.0'
    //implementation 'org.slf4j:slf4j-simple:1.7.32'
    implementation 'org.slf4j:slf4j-simple:2.0.3'

    // utilities
    //implementation 'com.google.guava:guava:31.0.1-jre'

    //testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
}

application {
    mainClass = 'mlj.App'
}

tasks.withType(JavaCompile) {
    options.compilerArgs << '-Xdiags:verbose'
    options.compilerArgs << '-Xlint:unchecked'
    options.deprecation = true
    options.encoding = 'UTF-8'
}

tasks.named('test') {
    useJUnitPlatform()
}

spotless {
    // optional: limit format enforcement to just the files changed by this feature branch
    //ratchetFrom 'origin/main'

    format 'misc', {
        // define the files to apply `misc` to
        target '*.gradle', '*.md', '.gitignore'

        // define the steps to apply to those files
        trimTrailingWhitespace()
        indentWithTabs()
        endWithNewline()
        setEncoding('utf-8')
    }

    java {
        target fileTree('.') {
            include '**/*.java'
            exclude '**/build/**', '**/build-*/**'
        }
        removeUnusedImports()
        formatAnnotations()
        trimTrailingWhitespace()
        endWithNewline()
        setEncoding('utf-8')
        palantirJavaFormat('2.26.0')

        // check https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/latest/com/diffplug/gradle/spotless/JavaExtension.html
        importOrder('java', 'javax', 'javafx', 'com', 'org')

        licenseHeader '/* Copyright (C) 2022-$YEAR Ledmington */'
    }
}

tasks.compileJava.dependsOn(spotlessApply)

With this setup, I simply run ./gradlew run.

Environment Info

[DEBUG] - Registering EngineProvider: XGBoost
[DEBUG] - Registering EngineProvider: LightGBM
[DEBUG] - Registering EngineProvider: MXNet
[DEBUG] - Registering EngineProvider: PyTorch
[DEBUG] - Registering EngineProvider: TensorFlow
[DEBUG] - Found default engine: MXNet
----------- System Properties -----------
java.specification.version: 17
sun.jnu.encoding: UTF-8
java.class.path: /home/filippo/Desktop/djl/integration/build/classes/java/main:/home/filippo/Desktop/djl/integration/build/resources/main:/home/filippo/.gradle/caches/modules-2/files-2.1/commons-cli/commons-cli/1.5.0/dc98be5d5390230684a092589d70ea76a147925c/commons-cli-1.5.0.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j-impl/2.18.0/e0ea6ef49f1349bb30e8c6e8a7052d0f3ee7a719/log4j-slf4j-impl-2.18.0.jar:/home/filippo/Desktop/djl/basicdataset/build/libs/basicdataset-0.20.0-SNAPSHOT.jar:/home/filippo/Desktop/djl/model-zoo/build/libs/model-zoo-0.20.0-SNAPSHOT.jar:/home/filippo/Desktop/djl/testing/build/libs/testing-0.20.0-SNAPSHOT.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/org.testng/testng/7.5/1416a607fae667c14e390b484e8d02b5824c0674/testng-7.5.jar:/home/filippo/Desktop/djl/engines/mxnet/mxnet-model-zoo/build/libs/mxnet-model-zoo-0.20.0-SNAPSHOT.jar:/home/filippo/Desktop/djl/engines/pytorch/pytorch-model-zoo/build/libs/pytorch-model-zoo-0.20.0-SNAPSHOT.jar:/home/filippo/Desktop/djl/engines/pytorch/pytorch-jni/build/libs/pytorch-jni-1.12.1-0.20.0-SNAPSHOT.jar:/home/filippo/Desktop/djl/engines/tensorflow/tensorflow-model-zoo/build/libs/tensorflow-model-zoo-0.20.0-SNAPSHOT.jar:/home/filippo/Desktop/djl/engines/ml/xgboost/build/libs/xgboost-0.20.0-SNAPSHOT.jar:/home/filippo/Desktop/djl/engines/ml/lightgbm/build/libs/lightgbm-0.20.0-SNAPSHOT.jar:/home/filippo/Desktop/djl/engines/mxnet/mxnet-engine/build/libs/mxnet-engine-0.20.0-SNAPSHOT.jar:/home/filippo/Desktop/djl/engines/pytorch/pytorch-engine/build/libs/pytorch-engine-0.20.0-SNAPSHOT.jar:/home/filippo/Desktop/djl/engines/tensorflow/tensorflow-engine/build/libs/tensorflow-engine-0.20.0-SNAPSHOT.jar:/home/filippo/Desktop/djl/api/build/libs/api-0.20.0-SNAPSHOT.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.36/6c62681a2f655b49963a5983b8b0950a6120ae14/slf4j-api-1.7.36.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.18.0/7c1882ede137548925eadb750615edab2f6e13c/log4j-core-2.18.0.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.18.0/c72ad9b1d8d42e4ea7befd8248bf05877af4c63d/log4j-api-2.18.0.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-csv/1.9.0/b59d8f64cd0b83ee1c04ff1748de2504457018c1/commons-csv-1.9.0.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/com.google.code.findbugs/jsr305/3.0.1/f7be08ec23c21485b9b5a1cf1654c2ec8c58168d/jsr305-3.0.1.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/com.beust/jcommander/1.78/a3927de9bd6f351429bcf763712c9890629d8f51/jcommander-1.78.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/org.webjars/jquery/3.5.1/2392938e374f561c27c53872bdc9b6b351b6ba34/jquery-3.5.1.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/ml.dmlc/xgboost4j_2.12/1.6.1/da6824d8e57dc3cf4f873bd926ca5a4c7f914603/xgboost4j_2.12-1.6.1.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.2/4bfc12adfe4842bf07b657f0369c4cb522955686/commons-logging-1.2.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/com.microsoft.ml.lightgbm/lightgbmlib/3.2.110/f6c85e5d7cc44d49c4544240ea5c96004680007b/lightgbmlib-3.2.110.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/com.google.code.gson/gson/2.9.1/2cc2131b98ebfb04e2b2c7dfb84431f4045096b/gson-2.9.1.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/net.java.dev.jna/jna/5.12.1/b1e93a735caea94f503e95e6fe79bf9cdc1e985d/jna-5.12.1.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-compress/1.21/4ec95b60d4e86b5c95a0e919cb172a0af98011ef/commons-compress-1.21.jar:/home/filippo/Desktop/djl/engines/tensorflow/tensorflow-api/build/libs/tensorflow-api-0.20.0-SNAPSHOT.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/org.tensorflow/tensorflow-core-api/0.4.0/2ac35ca087607cce0e5419953cc1ef0c3a5edaea/tensorflow-core-api-0.4.0.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/org.bytedeco/javacpp/1.5.6/1f18a820aadd943577b0b372554f9e35e1232e25/javacpp-1.5.6.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/com.google.protobuf/protobuf-java/3.21.5/82f0d4bc703c7850cdf5e2c728f464cf4dff0b3d/protobuf-java-3.21.5.jar:/home/filippo/.gradle/caches/modules-2/files-2.1/org.tensorflow/ndarray/0.3.3/1b6d8cc3e3762f6e465b884580d9fc17ab7aeb4/ndarray-0.3.3.jar
java.vm.vendor: Eclipse Adoptium
sun.arch.data.model: 64
user.variant: 
java.vendor.url: https://adoptium.net/
user.timezone: Europe/Rome
java.vm.specification.version: 17
os.name: Linux
sun.java.launcher: SUN_STANDARD
user.country: US
sun.boot.library.path: /home/filippo/.sdkman/candidates/java/17.0.4.1-tem/lib:/home/filippo/.sdkman/candidates/java/17.0.4.1-tem/lib
sun.java.command: ai.djl.integration.util.DebugEnvironment
jdk.debug: release
sun.cpu.endian: little
user.home: /home/filippo
org.gradle.appname: gradlew
user.language: en
java.specification.vendor: Oracle Corporation
java.version.date: 2022-08-12
java.home: /home/filippo/.sdkman/candidates/java/17.0.4.1-tem
ai.djl.logging.level: debug
org.gradle.internal.http.connectionTimeout: 60000
file.separator: /
java.vm.compressedOopsMode: 32-bit
line.separator: 

java.vm.specification.vendor: Oracle Corporation
java.specification.name: Java Platform API Specification
sun.management.compiler: HotSpot 64-Bit Tiered Compilers
java.runtime.version: 17.0.4.1+1
user.name: filippo
path.separator: :
os.version: 5.15.0-50-generic
java.runtime.name: OpenJDK Runtime Environment
file.encoding: UTF-8
java.vm.name: OpenJDK 64-Bit Server VM
java.vendor.version: Temurin-17.0.4.1+1
java.vendor.url.bug: https://github.com/adoptium/adoptium-support/issues
java.io.tmpdir: /tmp
org.gradle.internal.http.socketTimeout: 120000
java.version: 17.0.4.1
user.dir: /home/filippo/Desktop/djl/integration
os.arch: amd64
java.vm.specification.name: Java Virtual Machine Specification
native.encoding: UTF-8
java.library.path: /usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib
java.vm.info: mixed mode, sharing
java.vendor: Eclipse Adoptium
java.vm.version: 17.0.4.1+1
sun.io.unicode.encoding: UnicodeLittle
library.jansi.path: /home/filippo/.gradle/native/jansi/1.18/linux64
java.class.version: 61.0
org.gradle.internal.publish.checksums.insecure: true

--------- Environment Variables ---------
PATH: /home/filippo/.sdkman/candidates/sbt/current/bin:/home/filippo/.sdkman/candidates/java/current/bin:/home/filippo/.sdkman/candidates/gradle/current/bin:/home/filippo/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/usr/local/go/bin
LC_MEASUREMENT: it_IT.UTF-8
XAUTHORITY: /run/user/1000/gdm/Xauthority
SDKMAN_VERSION: 5.16.0
XMODIFIERS: @im=ibus
LC_TELEPHONE: it_IT.UTF-8
XDG_DATA_DIRS: /usr/share/Lubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop:/usr/share
GDMSESSION: Lubuntu
LC_TIME: it_IT.UTF-8
GTK_IM_MODULE: ibus
DBUS_SESSION_BUS_ADDRESS: unix:path=/run/user/1000/bus
XDG_CURRENT_DESKTOP: LXQt
XDG_CACHE_HOME: /home/filippo/.cache
LXQT_SESSION_CONFIG: session
COLORTERM: truecolor
LC_PAPER: it_IT.UTF-8
SDKMAN_DIR: /home/filippo/.sdkman
USERNAME: filippo
LOGNAME: filippo
PWD: /home/filippo/Desktop/djl
LANGUAGE: 
SAL_VCL_QT5_USE_CAIRO: true
WINDOWID: 0
SHELL: /usr/bin/zsh
LC_ADDRESS: it_IT.UTF-8
PAGER: less
SDKMAN_CANDIDATES_API: https://api.sdkman.io/2
OLDPWD: /home/filippo/Desktop/djl
ZSH: /home/filippo/.oh-my-zsh
GTK_MODULES: gail:atk-bridge
CLUTTER_IM_MODULE: ibus
SAL_USE_VCLPLUGIN: qt5
LESS: -R
COLORFGBG: 15;0
SYSTEMD_EXEC_PID: 1810
LS_COLORS: di=34;40:ln=35;40:so=32;40:pi=33;40:ex=31;40:bd=31;40:cd=31;40:su=31;40:sg=31;40:tw=31;40:ow=31;40:
XDG_SESSION_DESKTOP: Lubuntu
SHLVL: 1
LC_IDENTIFICATION: it_IT.UTF-8
QT_PLATFORM_PLUGIN: lxqt
LC_MONETARY: it_IT.UTF-8
BROWSER: firefox
QT_IM_MODULE: ibus
JAVA_HOME: /home/filippo/.sdkman/candidates/java/current
TERM: xterm-256color
XDG_CONFIG_DIRS: /etc/xdg/xdg-Lubuntu:/etc/xdg:/etc:/usr/share
LANG: en_US.UTF-8
XDG_SESSION_ID: 2
XDG_SESSION_TYPE: x11
GRADLE_HOME: /home/filippo/.sdkman/candidates/gradle/current
DISPLAY: :0
LC_NAME: it_IT.UTF-8
SDKMAN_CANDIDATES_DIR: /home/filippo/.sdkman/candidates
XDG_SESSION_CLASS: user
_: /home/filippo/Desktop/djl/./gradlew
XDG_DATA_HOME: /home/filippo/.local/share
LSCOLORS: exfxcxdxbxbxbxbxbxbxbx
SBT_HOME: /home/filippo/.sdkman/candidates/sbt/current
GPG_AGENT_INFO: /run/user/1000/gnupg/S.gpg-agent:0:1
DESKTOP_SESSION: Lubuntu
SDKMAN_PLATFORM: linuxx64
USER: filippo
XDG_CONFIG_HOME: /home/filippo/.config
XDG_MENU_PREFIX: lxqt-
GTK_CSD: 0
QT_ACCESSIBILITY: 1
WINDOWPATH: 2
LC_NUMERIC: it_IT.UTF-8
XDG_SEAT: seat0
GTK_OVERLAY_SCROLLING: 0
QT_QPA_PLATFORMTHEME: lxqt
XDG_VTNR: 2
XDG_RUNTIME_DIR: /run/user/1000
HOME: /home/filippo

-------------- Directories --------------
temp directory: /tmp
DJL cache directory: /home/filippo/.djl.ai
Engine cache directory: /home/filippo/.djl.ai

------------------ CUDA -----------------
[DEBUG] - cudart library not found.
GPU Count: 0

----------------- Engines ---------------
DJL version: 0.20.0
[DEBUG] - Using cache dir: /home/filippo/.djl.ai/mxnet/1.9.1-mkl-linux-x86_64
[DEBUG] - Loading mxnet library from: /home/filippo/.djl.ai/mxnet/1.9.1-mkl-linux-x86_64/libmxnet.so
[DEBUG] - Using cache dir: /home/filippo/.djl.ai/mxnet/1.9.1-mkl-linux-x86_64
Default Engine: MXNet:1.9.0, capabilities: [
        CPU_SSE,
        SIGNAL_HANDLER,
        LAPACK,
        BLAS_OPEN,
        CPU_SSE2,
        DIST_KVSTORE,
        CPU_SSE3,
        OPENMP,
        OPENCV,
        MKLDNN,
]
MXNet Library: /home/filippo/.djl.ai/mxnet/1.9.1-mkl-linux-x86_64/libmxnet.so
Default Device: cpu()
PyTorch: 2
MXNet: 0
XGBoost: 10
LightGBM: 10
TensorFlow: 3

--------------- Hardware --------------
Available processors (cores): 4
Byte Order: LITTLE_ENDIAN
Free memory (bytes): 51759424
Maximum memory (bytes): 1000341504
Total memory available to JVM (bytes): 65011712
Heap committed: 65011712
Heap nonCommitted: 21692416
GCC: 
gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
tosterberg commented 2 years ago

Please assign to me.