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)
Description
During training, a warning inside
ai.djl.ndarray.index.NDArrayIndexer
appears so many times that I cannot see theProgressBar
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:
and this is my
build.gradle
:With this setup, I simply run
./gradlew run
.Environment Info