Deep Java Library
Since Camel 3.3
Only producer is supported
The Deep Java Library component is used to infer deep learning models from message exchanges data. This component uses the Deep Java Library as the underlying library.
To use the DJL component, Maven users will need to add the following dependency to their pom.xml
:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-djl</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
URI format
djl:application
Where application
represents the application in the context of DJL, the common functional signature for a group of deep learning models.
Supported applications
Currently, the component supports the following applications.
Application | Input types | Output type |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties
,*.yaml
files, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Deep Java Library component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean |
Endpoint Options
The Deep Java Library endpoint is configured using URI syntax:
djl:application
With the following path and query parameters:
Query Parameters (5 parameters)
Name | Description | Default | Type |
---|---|---|---|
Model Artifact. | String | ||
Model. | String | ||
Show progress while loading zoo models. This parameter takes effect only with zoo models. | false | boolean | |
Translator. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean |
Message Headers
The Deep Java Library component supports 2 message header(s), which is/are listed below:
Usage
Model Zoo
The following tables contain supported models in the model zoos per application.
Those applications without a table mean that there are no pre-trained models found for them from the basic, PyTorch, TensorFlow or MXNet DJL model zoos. You may still find more models for an application from other model zoos such as Hugging Face, ONNX, etc. |
CV - Image Classification
Application: cv/image_classification
Model family | Artifact ID | Options |
---|---|---|
MLP |
| {dataset=mnist} |
MLP |
| {dataset=mnist} |
ResNet |
| {layers=50, flavor=v1, dataset=cifar10} |
ResNet |
| {layers=50, dataset=imagenet} |
ResNet |
| {flavor=v1, layers=50, dataset=imagenet} |
ResNet |
| {layers=18, flavor=v1, dataset=imagenet} |
ResNet-18 |
| {} |
SENet |
| {layers=154, dataset=imagenet} |
SE-ResNeXt |
| {layers=101, flavor=32x4d, dataset=imagenet} |
ResNeSt |
| {layers=14, dataset=imagenet} |
SqueezeNet |
| {flavor=1.0, dataset=imagenet} |
MobileNet |
| {flavor=v2, dataset=imagenet} |
MobileNet |
| {flavor=v1, multiplier=0.25, dataset=imagenet} |
GoogLeNet |
| {dataset=imagenet} |
Darknet |
| {layers=53, flavor=v3, dataset=imagenet} |
Inception v3 |
| {dataset=imagenet} |
AlexNet |
| {dataset=imagenet} |
VGGNet |
| {layers=11, dataset=imagenet} |
DenseNet |
| {layers=121, dataset=imagenet} |
Xception |
| {flavor=65, dataset=imagenet} |
CV - Object Detection
Application: cv/object_detection
Model family | Artifact ID | Options |
---|---|---|
SSD |
| {flavor=tiny, dataset=pikachu} |
SSD |
| {size=300, backbone=resnet50, dataset=coco} |
SSD |
| {backbone=mobilenet_v2, dataset=openimages_v4} |
SSD |
| {size=512, backbone=resnet50, flavor=v1, dataset=voc} |
YOLO |
| {dataset=voc, version=3, backbone=darknet53, imageSize=320} |
YOLOv5 |
| {} |
YOLOv8 |
| {} |
CV - Semantic Segmentation
Application: cv/semantic_segmentation
Model family | Artifact ID | Options |
---|---|---|
DeepLabV3 |
| {backbone=resnet50, flavor=v1b, dataset=coco} |
CV - Instance Segmentation
Application: cv/instance_segmentation
Model family | Artifact ID | Options |
---|---|---|
Mask R-CNN |
| {backbone=resnet18, flavor=v1b, dataset=coco} |
CV - Pose Estimation
Application: cv/pose_estimation
Model family | Artifact ID | Options |
---|---|---|
Simple Pose |
| {backbone=resnet18, flavor=v1b, dataset=imagenet} |
CV - Action Recognition
Application: cv/action_recognition
Model family | Artifact ID | Options |
---|---|---|
Action Recognition |
| {backbone=vgg16, dataset=ucf101} |
CV - Image Generation
Application: cv/image_generation
Model family | Artifact ID | Options |
---|---|---|
CycleGAN |
| {artist=cezanne} |
BigGAN |
| {layers=12, size=128, dataset=imagenet} |
NLP - Question Answer
Application: nlp/question_answer
Model family | Artifact ID | Options |
---|---|---|
BertQA |
| {modelType=distilbert, size=base, cased=false, dataset=SQuAD} |
BertQA |
| {backbone=bert, dataset=book_corpus_wiki_en_uncased} |
NLP - Sentiment Analysis
Application: nlp/sentiment_analysis
Model family | Artifact ID | Options |
---|---|---|
DistilBERT |
| {backbone=distilbert, dataset=sst} |
DJL Engine implementation
Because DJL is deep learning framework-agnostic, you don’t have to make a choice between frameworks when creating your projects. You can switch frameworks at any point. To ensure the best performance, DJL also provides automatic CPU/GPU choice based on hardware configuration.
PyTorch engine
You can pull the PyTorch engine from the central Maven repository by including the following dependency:
<dependency>
<groupId>ai.djl.pytorch</groupId>
<artifactId>pytorch-engine</artifactId>
<version>x.x.x</version>
<scope>runtime</scope>
</dependency>
By default, DJL will download the PyTorch native libraries into the cache folder the first time you run DJL. It will automatically determine the appropriate jars for your system based on the platform and GPU support.
More information about PyTorch engine installation
TensorFlow engine
You can pull the TensorFlow engine from the central Maven repository by including the following dependency:
<dependency>
<groupId>ai.djl.tensorflow</groupId>
<artifactId>tensorflow-engine</artifactId>
<version>x.x.x</version>
<scope>runtime</scope>
</dependency>
By default, DJL will download the TensorFlow native libraries into cache folder the first time you run DJL. It will automatically determine the appropriate jars for your system based on the platform and GPU support.
More information about TensorFlow engine installation
MXNet engine
You can pull the MXNet engine from the central Maven repository by including the following dependency:
<dependency>
<groupId>ai.djl.mxnet</groupId>
<artifactId>mxnet-engine</artifactId>
<version>x.x.x</version>
<scope>runtime</scope>
</dependency>
By default, DJL will download the Apache MXNet native libraries into cache folder the first time you run DJL. It will automatically determine the appropriate jars for your system based on the platform and GPU support.
More information about MXNet engine installation
Examples
from("file:/data/mnist/0/10.png")
.to("djl:cv/image_classification?artifactId=ai.djl.mxnet:mlp:0.0.1");
from("file:/data/mnist/0/10.png")
.to("djl:cv/image_classification?artifactId=ai.djl.mxnet:mlp:0.0.1");
// create a deep learning model
Model model = Model.newInstance();
model.setBlock(new Mlp(28 * 28, 10, new int[]{128, 64}));
model.load(Paths.get(MODEL_DIR), MODEL_NAME);
// create translator for pre-processing and postprocessing
ImageClassificationTranslator.Builder builder = ImageClassificationTranslator.builder();
builder.setSynsetArtifactName("synset.txt");
builder.setPipeline(new Pipeline(new ToTensor()));
builder.optApplySoftmax(true);
ImageClassificationTranslator translator = new ImageClassificationTranslator(builder);
// Bind model and translator beans
context.getRegistry().bind("MyModel", model);
context.getRegistry().bind("MyTranslator", translator);
from("file:/data/mnist/0/10.png")
.to("djl:cv/image_classification?model=MyModel&translator=MyTranslator");
Spring Boot Auto-Configuration
When using djl with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-djl-starter</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
The component supports 3 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | Boolean | |
Whether to enable auto configuration of the djl component. This is enabled by default. | Boolean | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | Boolean |