For the complete documentation index, see llms.txt. This page is also available as Markdown.

Model Zoo

Pretrained models in Deeplearning4j — available architectures, using pretrained weights, and transfer learning from zoo models

About the Deeplearning4j Model Zoo

Deeplearning4j ships with a native model zoo that lets you instantiate well-known neural network architectures directly from Java, with no external downloads or manual configuration beyond adding a single Maven dependency. The zoo also provides pretrained weights for popular datasets — ImageNet, MNIST, CIFAR-10, and VGGFace — that are downloaded automatically and verified with a checksum on first use.

The model zoo covers the most widely used image classification and object detection architectures as well as a text-generation LSTM. Each model can be used in three modes:

  1. Fresh initialization — a randomly initialized network with the original architecture, ready for training from scratch.

  2. Pretrained weights — weights transferred from a known training run on a reference dataset, ready for inference or fine-tuning.

  3. Custom input/output — a pretrained backbone with the classification head replaced to match your own number of classes.

Maven Dependency

<dependency>
    <groupId>org.deeplearning4j</groupId>
    <artifactId>deeplearning4j-zoo</artifactId>
    <version>${dl4j.version}</version>
</dependency>

The ZooModel Interface

Every model in the zoo extends the abstract class ZooModel and implements the InstantiableModel interface. The key methods are:

Method
Description

init()

Returns a fresh Model (MultiLayerNetwork or ComputationGraph) with random weights

initPretrained(PretrainedType)

Downloads (if needed) and returns a model loaded with pretrained weights

pretrainedAvailable(PretrainedType)

Returns true if weights are available for the given dataset

setInputShape(int[][])

Override the default input shape before calling init()

conf()

Returns the underlying MultiLayerConfiguration for inspection or modification

The PretrainedType enum specifies which dataset's weights to load:

  • PretrainedType.IMAGENET — ImageNet (1000 classes, ILSVRC)

  • PretrainedType.MNIST — MNIST handwritten digits

  • PretrainedType.CIFAR10 — CIFAR-10 (10 classes)

  • PretrainedType.VGGFACE — VGGFace (face recognition)

Input shapes follow the NCHW convention: {channels, height, width}. For example, {3, 224, 224} means 3 RGB channels at 224 × 224 pixels.


Initializing a Fresh Network

Use .init() to get a randomly initialized network for training from scratch. You must specify the number of output classes and a random seed via the builder:

To inspect or modify the configuration before building the network:

Changing the Input Shape

By default each model has a fixed input shape. For models that support multiple resolutions (such as Darknet19, which supports 224 × 224 and 448 × 448), call setInputShape() before init(). This does not affect pretrained models.


Loading Pretrained Weights

Call initPretrained(PretrainedType) to get a model loaded with weights from a reference training run. The weights file is downloaded to the DL4J cache directory on first use and verified via SHA-256 checksum on subsequent uses.

To check availability before loading:

Some models offer more than one set of pretrained weights. VGG16, for example, has ImageNet, CIFAR-10, and VGGFace variants.


Transfer Learning

Pretrained zoo models are the natural starting point for transfer learning. The general workflow is:

  1. Load a pretrained model via initPretrained.

  2. Use TransferLearning.Builder (for MultiLayerNetwork) or TransferLearning.GraphBuilder (for ComputationGraph) to freeze earlier layers and replace the output layer.

  3. Train the modified network on your own dataset.

Feature Extraction (Frozen Backbone)

In feature extraction mode you freeze all layers in the pretrained model and replace only the final classification head. The frozen layers act as a fixed feature extractor.

Fine-Tuning (Partial Unfreezing)

Fine-tuning unfreezes some of the later layers so they can adapt to the new dataset, while keeping early layers (which capture low-level features) frozen.

For a complete transfer learning guide, see the Transfer Learning documentation.


Memory and Workspace Configuration

Initialization methods accept an optional workspaceMode parameter. Most users will not need to change this. If you are running a model with a very large number of parameters (such as VGG19 with 143 million parameters) on a machine with ample RAM, passing WorkspaceMode.SINGLE can reduce memory overhead:

For general workspace configuration guidance, see the Workspaces documentation.


Available Models at a Glance

Model
Input Shape
Pretrained Datasets

AlexNet

3 × 224 × 224

Darknet19

3 × 224 × 224, 3 × 448 × 448

ImageNet

FaceNetNN4Small2

3 × 96 × 96

InceptionResNetV1

3 × 160 × 160

VGGFace

LeNet

1 × 28 × 28

MNIST

NASNet

3 × 224 × 224

ImageNet

ResNet50

3 × 224 × 224

ImageNet

SimpleCNN

3 × 224 × 224

SqueezeNet

3 × 227 × 227

ImageNet

TextGenerationLSTM

Walt Whitman corpus

TinyYOLO

3 × 416 × 416

ImageNet + VOC

UNet

1 × 512 × 512

Synthetic segmentation

VGG16

3 × 224 × 224

ImageNet, CIFAR-10, VGGFace

VGG19

3 × 224 × 224

ImageNet

Xception

3 × 299 × 299

ImageNet

YOLO2

3 × 608 × 608

ImageNet + COCO

For full per-model details including parameter counts, paper references, and code links, see the Available Models page.


Source Code

All zoo model implementations are in the deeplearning4j-zoo module: github.com/eclipse/deeplearning4j/tree/master/deeplearning4j/deeplearning4j-zoo/src/main/java/org/deeplearning4j/zoo/model

Last updated

Was this helpful?