deepjavalibrary/djl
An Engine-Agnostic Deep Learning Framework in Java
Deep Java Library (DJL) – Quick Overview
What it is – DJL is a Java‑first, high‑level deep‑learning framework that sits on top of popular native engines (TensorFlow, PyTorch, MXNet, etc.). It lets Java developers load, train, and run inference with neural networks without learning a new language or switching away from their usual IDEs.
Key ideas
- Engine‑agnostic – you pick an engine at runtime; you can swap TensorFlow ↔ PyTorch ↔ MXNet without changing your code.
- Automatic CPU/GPU selection – DJL detects the hardware and chooses the best backend.
- Model zoo integration – pre‑trained models are discovered via a simple
Criteriabuilder. - Full training support – you can define a network with built‑in blocks, create a
Trainer, and run classic training loops.
Typical usage
// Inference – pick a pre‑trained object‑detection model
Criteria<Image, Classifications> criteria = Criteria.builder()
.optApplication(Application.CV.OBJECT_DETECTION)
.setTypes(Image.class, Classifications.class)
.optFilter("backbone", "resnet50")
.build();
Image img = ImageFactory.getInstance().fromUrl("http://…");
try (ZooModel<Image, Classifications> model = criteria.loadModel();
Predictor<Image, Classifications> pred = model.newPredictor()) {
Classifications result = pred.predict(img);
// …process result…
}
// Training – a tiny MLP on MNIST
Block block = new Mlp(28*28, 10, new int[]{128,64});
Model model = Model.newInstance("mlp");
model.setBlock(block);
Dataset train = new Mnist.Builder().setUsage(Usage.TRAIN).build();
Dataset test = new Mnist.Builder().setUsage(Usage.TEST).build();
TrainingConfig cfg = setupTrainingConfig();
Trainer trainer = model.newTrainer(cfg);
trainer.initialize(new Shape(1, 28*28));
EasyTrain.fit(trainer, epochs, train, test);
model.save(modelDir, "mlp");
Who it’s for – Java developers who want to experiment with deep learning, embed inference in enterprise services, or build end‑to‑end ML pipelines without leaving the JVM ecosystem.
Where to learn more –
- Official docs: https://docs.djl.ai/
- DJL’s “Dive into Deep Learning” book (Java version)
- Javadoc API reference
- Community Slack, GitHub discussions, and Zhihu column for Chinese‑language updates.
License – Apache‑2.0, so you can use it in both open‑source and commercial projects.
All details are taken directly from the repository’s README.
Related
- Project
- Project
- Project
- Project
- Project