This is an automated email from the ASF dual-hosted git repository.
tsato pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 942f3c4ec4e CAMEL-20905: camel-djl - Support more model applications
for zoo models
942f3c4ec4e is described below
commit 942f3c4ec4e16a18529d41256ef57fb414d819ac
Author: Tadayoshi Sato <[email protected]>
AuthorDate: Tue Jul 2 12:53:07 2024 +0900
CAMEL-20905: camel-djl - Support more model applications for zoo models
Added support for:
* `cv/semantic_segmentation`
* `cv/instance_segmentation`
* `cv/pose_estimation`
* `cv/action_recognition`
* `cv/word_recognition`
* `cv/image_generation`
* `cv/image_enhancement`
* `nlp/fill_mask`
* `nlp/question_answer`
* `nlp/text_classification`
* `nlp/sentiment_analysis`
* `nlp/token_classification`
* `nlp/word_embedding`
* `nlp/text_generation`
* `nlp/machine_translation`
* `nlp/multiple_choice`
* `nlp/text_embedding`
* `tabular/linear_regression`
* `tabular/softmax_regression`
* `audio`
* `timeseries/forecasting`
---
components/camel-ai/camel-djl/pom.xml | 8 ++
.../apache/camel/component/djl/DJLConstants.java | 27 +++++
.../apache/camel/component/djl/DJLProducer.java | 12 +--
.../djl/model/ModelPredictorProducer.java | 109 ++++++++++++++++++++-
.../djl/model/ZooObjectDetectionPredictor.java | 98 ------------------
.../audio/ZooAudioClassificationPredictor.java} | 22 ++---
.../AbstractCvZooPredictor.java} | 64 +++++-------
.../CustomImageClassificationPredictor.java | 4 +-
.../{ => cv}/CustomObjectDetectionPredictor.java | 3 +-
.../model/cv/ZooActionRecognitionPredictor.java | 41 ++++++++
.../model/cv/ZooImageClassificationPredictor.java | 42 ++++++++
.../djl/model/cv/ZooImageEnhancementPredictor.java | 41 ++++++++
.../djl/model/cv/ZooImageGenerationPredictor.java | 70 +++++++++++++
.../model/cv/ZooInstanceSegmentationPredictor.java | 42 ++++++++
.../djl/model/cv/ZooObjectDetectionPredictor.java | 41 ++++++++
.../djl/model/cv/ZooPoseEstimationPredictor.java | 40 ++++++++
.../model/cv/ZooSemanticSegmentationPredictor.java | 42 ++++++++
.../djl/model/cv/ZooWordRecognitionPredictor.java | 41 ++++++++
.../djl/model/nlp/AbstractNlpZooPredictor.java | 50 ++++++++++
.../djl/model/nlp/ZooFillMaskPredictor.java | 39 ++++++++
.../model/nlp/ZooMachineTranslationPredictor.java | 40 ++++++++
.../djl/model/nlp/ZooMultipleChoicePredictor.java | 40 ++++++++
.../djl/model/nlp/ZooQuestionAnswerPredictor.java | 78 +++++++++++++++
.../model/nlp/ZooSentimentAnalysisPredictor.java | 41 ++++++++
.../model/nlp/ZooTextClassificationPredictor.java | 41 ++++++++
.../djl/model/nlp/ZooTextEmbeddingPredictor.java | 41 ++++++++
.../djl/model/nlp/ZooTextGenerationPredictor.java | 40 ++++++++
.../model/nlp/ZooTokenClassificationPredictor.java | 41 ++++++++
.../djl/model/nlp/ZooWordEmbeddingPredictor.java | 50 ++++++++++
.../tabular/ZooLinearRegressionPredictor.java} | 22 ++---
.../tabular/ZooSoftmaxRegressionPredictor.java} | 22 ++---
.../model/timeseries/ZooForecastingPredictor.java | 70 +++++++++++++
...ctionTest.java => CvActionRecognitionTest.java} | 12 +--
...st.java => CvImageClassificationLocalTest.java} | 4 +-
...ionTest.java => CvImageClassificationTest.java} | 5 +-
...tectionTest.java => CvImageGenerationTest.java} | 27 +++--
...onTest.java => CvInstanceSegmentationTest.java} | 8 +-
...tectionTest.java => CvObjectDetectionTest.java} | 5 +-
...etectionTest.java => CvPoseEstimationTest.java} | 28 ++++--
...onTest.java => CvSemanticSegmentationTest.java} | 8 +-
...icationTest.java => NlpQuestionAnswerTest.java} | 19 ++--
...tionTest.java => NlpSentimentAnalysisTest.java} | 20 ++--
...etectionTest.java => NlpWordEmbeddingTest.java} | 19 ++--
.../component/djl/TimeSeriesForecastingTest.java | 75 ++++++++++++++
.../djl/model/ModelPredictorProducerTest.java | 94 ++++++++++++++++++
.../resources/data/action/action_discus_throw.png | Bin 0 -> 150725 bytes
.../src/test/resources/data/pose/pose_soccer.png | Bin 0 -> 1598682 bytes
47 files changed, 1423 insertions(+), 263 deletions(-)
diff --git a/components/camel-ai/camel-djl/pom.xml
b/components/camel-ai/camel-djl/pom.xml
index 973f1b4eab2..41737c0396d 100644
--- a/components/camel-ai/camel-djl/pom.xml
+++ b/components/camel-ai/camel-djl/pom.xml
@@ -54,10 +54,18 @@
<artifactId>api</artifactId>
<version>${djl-version}</version>
</dependency>
+ <dependency>
+ <groupId>ai.djl.timeseries</groupId>
+ <artifactId>timeseries</artifactId>
+ <version>${djl-version}</version>
+ </dependency>
+
+ <!-- DJL builtin model -->
<dependency>
<groupId>ai.djl</groupId>
<artifactId>model-zoo</artifactId>
<version>${djl-version}</version>
+ <scope>test</scope>
</dependency>
<!-- MxNet Engine-->
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLConstants.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLConstants.java
new file mode 100644
index 00000000000..52832d84812
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLConstants.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl;
+
+import org.apache.camel.spi.Metadata;
+
+/**
+ * Constants used in Camel DJL component.
+ */
+public interface DJLConstants {
+ @Metadata(description = "The input data used for prediction")
+ String INPUT = "CamelDjlInput";
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java
index 316bff2e1fc..584c6af394d 100644
---
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java
@@ -22,20 +22,20 @@ import
org.apache.camel.component.djl.model.ModelPredictorProducer;
import org.apache.camel.support.DefaultProducer;
public class DJLProducer extends DefaultProducer {
- private AbstractPredictor abstractPredictor;
+ private final AbstractPredictor predictor;
public DJLProducer(DJLEndpoint endpoint) throws Exception {
super(endpoint);
if (endpoint.getArtifactId() != null) {
- this.abstractPredictor
- =
ModelPredictorProducer.getZooPredictor(endpoint.getApplication(),
endpoint.getArtifactId());
+ this.predictor = ModelPredictorProducer.getZooPredictor(
+ endpoint.getApplication(), endpoint.getArtifactId());
} else {
- this.abstractPredictor =
ModelPredictorProducer.getCustomPredictor(endpoint.getApplication(),
endpoint.getModel(),
- endpoint.getTranslator());
+ this.predictor = ModelPredictorProducer.getCustomPredictor(
+ endpoint.getApplication(), endpoint.getModel(),
endpoint.getTranslator());
}
}
public void process(Exchange exchange) throws Exception {
- this.abstractPredictor.process(exchange);
+ this.predictor.process(exchange);
}
}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/ModelPredictorProducer.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/ModelPredictorProducer.java
index 7283ddfb674..5c3f2db8930 100644
---
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/ModelPredictorProducer.java
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/ModelPredictorProducer.java
@@ -18,12 +18,58 @@ package org.apache.camel.component.djl.model;
import java.io.IOException;
+import ai.djl.Application;
import ai.djl.MalformedModelException;
import ai.djl.repository.zoo.ModelNotFoundException;
import org.apache.camel.RuntimeCamelException;
+import
org.apache.camel.component.djl.model.audio.ZooAudioClassificationPredictor;
+import
org.apache.camel.component.djl.model.cv.CustomImageClassificationPredictor;
+import org.apache.camel.component.djl.model.cv.CustomObjectDetectionPredictor;
+import org.apache.camel.component.djl.model.cv.ZooActionRecognitionPredictor;
+import org.apache.camel.component.djl.model.cv.ZooImageClassificationPredictor;
+import org.apache.camel.component.djl.model.cv.ZooImageEnhancementPredictor;
+import org.apache.camel.component.djl.model.cv.ZooImageGenerationPredictor;
+import
org.apache.camel.component.djl.model.cv.ZooInstanceSegmentationPredictor;
+import org.apache.camel.component.djl.model.cv.ZooObjectDetectionPredictor;
+import org.apache.camel.component.djl.model.cv.ZooPoseEstimationPredictor;
+import
org.apache.camel.component.djl.model.cv.ZooSemanticSegmentationPredictor;
+import org.apache.camel.component.djl.model.cv.ZooWordRecognitionPredictor;
+import org.apache.camel.component.djl.model.nlp.ZooFillMaskPredictor;
+import org.apache.camel.component.djl.model.nlp.ZooMachineTranslationPredictor;
+import org.apache.camel.component.djl.model.nlp.ZooMultipleChoicePredictor;
+import org.apache.camel.component.djl.model.nlp.ZooQuestionAnswerPredictor;
+import org.apache.camel.component.djl.model.nlp.ZooSentimentAnalysisPredictor;
+import org.apache.camel.component.djl.model.nlp.ZooTextClassificationPredictor;
+import org.apache.camel.component.djl.model.nlp.ZooTextEmbeddingPredictor;
+import org.apache.camel.component.djl.model.nlp.ZooTextGenerationPredictor;
+import
org.apache.camel.component.djl.model.nlp.ZooTokenClassificationPredictor;
+import org.apache.camel.component.djl.model.nlp.ZooWordEmbeddingPredictor;
+import
org.apache.camel.component.djl.model.tabular.ZooLinearRegressionPredictor;
+import
org.apache.camel.component.djl.model.tabular.ZooSoftmaxRegressionPredictor;
+import org.apache.camel.component.djl.model.timeseries.ZooForecastingPredictor;
+import static ai.djl.Application.CV.ACTION_RECOGNITION;
import static ai.djl.Application.CV.IMAGE_CLASSIFICATION;
+import static ai.djl.Application.CV.IMAGE_ENHANCEMENT;
+import static ai.djl.Application.CV.IMAGE_GENERATION;
+import static ai.djl.Application.CV.INSTANCE_SEGMENTATION;
import static ai.djl.Application.CV.OBJECT_DETECTION;
+import static ai.djl.Application.CV.POSE_ESTIMATION;
+import static ai.djl.Application.CV.SEMANTIC_SEGMENTATION;
+import static ai.djl.Application.CV.WORD_RECOGNITION;
+import static ai.djl.Application.NLP.FILL_MASK;
+import static ai.djl.Application.NLP.MACHINE_TRANSLATION;
+import static ai.djl.Application.NLP.MULTIPLE_CHOICE;
+import static ai.djl.Application.NLP.QUESTION_ANSWER;
+import static ai.djl.Application.NLP.SENTIMENT_ANALYSIS;
+import static ai.djl.Application.NLP.TEXT_CLASSIFICATION;
+import static ai.djl.Application.NLP.TEXT_EMBEDDING;
+import static ai.djl.Application.NLP.TEXT_GENERATION;
+import static ai.djl.Application.NLP.TOKEN_CLASSIFICATION;
+import static ai.djl.Application.NLP.WORD_EMBEDDING;
+import static ai.djl.Application.Tabular.LINEAR_REGRESSION;
+import static ai.djl.Application.Tabular.SOFTMAX_REGRESSION;
+import static ai.djl.Application.TimeSeries.FORECASTING;
public final class ModelPredictorProducer {
@@ -33,13 +79,68 @@ public final class ModelPredictorProducer {
public static AbstractPredictor getZooPredictor(String applicationPath,
String artifactId)
throws ModelNotFoundException, MalformedModelException,
IOException {
- if (applicationPath.equals(IMAGE_CLASSIFICATION.getPath())) {
+ // CV
+ if (IMAGE_CLASSIFICATION.getPath().equals(applicationPath)) {
return new ZooImageClassificationPredictor(artifactId);
- } else if (applicationPath.equals(OBJECT_DETECTION.getPath())) {
+ } else if (OBJECT_DETECTION.getPath().equals(applicationPath)) {
return new ZooObjectDetectionPredictor(artifactId);
- } else {
- throw new RuntimeCamelException("Application not supported ");
+ } else if (SEMANTIC_SEGMENTATION.getPath().equals(applicationPath)) {
+ return new ZooSemanticSegmentationPredictor(artifactId);
+ } else if (INSTANCE_SEGMENTATION.getPath().equals(applicationPath)) {
+ return new ZooInstanceSegmentationPredictor(artifactId);
+ } else if (POSE_ESTIMATION.getPath().equals(applicationPath)) {
+ return new ZooPoseEstimationPredictor(artifactId);
+ } else if (ACTION_RECOGNITION.getPath().equals(applicationPath)) {
+ return new ZooActionRecognitionPredictor(artifactId);
+ } else if (WORD_RECOGNITION.getPath().equals(applicationPath)) {
+ return new ZooWordRecognitionPredictor(artifactId);
+ } else if (IMAGE_GENERATION.getPath().equals(applicationPath)) {
+ return new ZooImageGenerationPredictor(artifactId);
+ } else if (IMAGE_ENHANCEMENT.getPath().equals(applicationPath)) {
+ return new ZooImageEnhancementPredictor(artifactId);
}
+
+ // NLP
+ if (FILL_MASK.getPath().equals(applicationPath)) {
+ return new ZooFillMaskPredictor(artifactId);
+ } else if (QUESTION_ANSWER.getPath().equals(applicationPath)) {
+ return new ZooQuestionAnswerPredictor(artifactId);
+ } else if (TEXT_CLASSIFICATION.getPath().equals(applicationPath)) {
+ return new ZooTextClassificationPredictor(artifactId);
+ } else if (SENTIMENT_ANALYSIS.getPath().equals(applicationPath)) {
+ return new ZooSentimentAnalysisPredictor(artifactId);
+ } else if (TOKEN_CLASSIFICATION.getPath().equals(applicationPath)) {
+ return new ZooTokenClassificationPredictor(artifactId);
+ } else if (WORD_EMBEDDING.getPath().equals(applicationPath)) {
+ return new ZooWordEmbeddingPredictor(artifactId);
+ } else if (TEXT_GENERATION.getPath().equals(applicationPath)) {
+ return new ZooTextGenerationPredictor(artifactId);
+ } else if (MACHINE_TRANSLATION.getPath().equals(applicationPath)) {
+ return new ZooMachineTranslationPredictor(artifactId);
+ } else if (MULTIPLE_CHOICE.getPath().equals(applicationPath)) {
+ return new ZooMultipleChoicePredictor(artifactId);
+ } else if (TEXT_EMBEDDING.getPath().equals(applicationPath)) {
+ return new ZooTextEmbeddingPredictor(artifactId);
+ }
+
+ // Tabular
+ if (LINEAR_REGRESSION.getPath().equals(applicationPath)) {
+ return new ZooLinearRegressionPredictor(artifactId);
+ } else if (SOFTMAX_REGRESSION.getPath().equals(applicationPath)) {
+ return new ZooSoftmaxRegressionPredictor(artifactId);
+ }
+
+ // Audio
+ if (Application.Audio.ANY.getPath().equals(applicationPath)) {
+ return new ZooAudioClassificationPredictor(artifactId);
+ }
+
+ // Time Series
+ if (FORECASTING.getPath().equals(applicationPath)) {
+ return new ZooForecastingPredictor(artifactId);
+ }
+
+ throw new RuntimeCamelException("Application not supported: " +
applicationPath);
}
public static AbstractPredictor getCustomPredictor(String applicationPath,
String model, String translator) {
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/ZooObjectDetectionPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/ZooObjectDetectionPredictor.java
deleted file mode 100644
index cbb1c8c3545..00000000000
---
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/ZooObjectDetectionPredictor.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.djl.model;
-
-import java.io.*;
-
-import ai.djl.Application;
-import ai.djl.MalformedModelException;
-import ai.djl.inference.Predictor;
-import ai.djl.modality.cv.Image;
-import ai.djl.modality.cv.ImageFactory;
-import ai.djl.modality.cv.output.DetectedObjects;
-import ai.djl.repository.zoo.Criteria;
-import ai.djl.repository.zoo.ModelNotFoundException;
-import ai.djl.repository.zoo.ModelZoo;
-import ai.djl.repository.zoo.ZooModel;
-import ai.djl.training.util.ProgressBar;
-import ai.djl.translate.TranslateException;
-import org.apache.camel.Exchange;
-import org.apache.camel.RuntimeCamelException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ZooObjectDetectionPredictor extends AbstractPredictor {
-
- private static final Logger LOG =
LoggerFactory.getLogger(ZooObjectDetectionPredictor.class);
-
- private final ZooModel<Image, DetectedObjects> model;
-
- public ZooObjectDetectionPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException, IOException {
- Criteria<Image, DetectedObjects> criteria = Criteria.builder()
- .optApplication(Application.CV.OBJECT_DETECTION)
- .setTypes(Image.class, DetectedObjects.class)
- .optArtifactId(artifactId)
- .optProgress(new ProgressBar())
- .build();
- this.model = ModelZoo.loadModel(criteria);
- }
-
- @Override
- public void process(Exchange exchange) {
- if (exchange.getIn().getBody() instanceof byte[]) {
- byte[] bytes = exchange.getIn().getBody(byte[].class);
- DetectedObjects result = classify(new ByteArrayInputStream(bytes));
- exchange.getIn().setBody(result);
- } else if (exchange.getIn().getBody() instanceof File) {
- DetectedObjects result =
classify(exchange.getIn().getBody(File.class));
- exchange.getIn().setBody(result);
- } else if (exchange.getIn().getBody() instanceof InputStream) {
- DetectedObjects result =
classify(exchange.getIn().getBody(InputStream.class));
- exchange.getIn().setBody(result);
- } else {
- throw new RuntimeCamelException("Data type is not supported. Body
should be byte[], InputStream or File");
- }
- }
-
- public DetectedObjects classify(Image image) {
- try (Predictor<Image, DetectedObjects> predictor =
model.newPredictor()) {
- return predictor.predict(image);
- } catch (TranslateException e) {
- throw new RuntimeCamelException("Could not process input or
output", e);
- }
- }
-
- public DetectedObjects classify(File input) {
- try (InputStream fileInputStream = new FileInputStream(input)) {
- Image image =
ImageFactory.getInstance().fromInputStream(fileInputStream);
- return classify(image);
- } catch (IOException e) {
- LOG.error(FAILED_TO_TRANSFORM_MESSAGE);
- throw new RuntimeCamelException(FAILED_TO_TRANSFORM_MESSAGE, e);
- }
- }
-
- public DetectedObjects classify(InputStream input) {
- try {
- Image image = ImageFactory.getInstance().fromInputStream(input);
- return classify(image);
- } catch (IOException e) {
- LOG.error(FAILED_TO_TRANSFORM_MESSAGE);
- throw new RuntimeCamelException(FAILED_TO_TRANSFORM_MESSAGE, e);
- }
- }
-}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/audio/ZooAudioClassificationPredictor.java
similarity index 55%
copy from
components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java
copy to
components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/audio/ZooAudioClassificationPredictor.java
index 316bff2e1fc..bf210081d76 100644
---
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/audio/ZooAudioClassificationPredictor.java
@@ -14,28 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.djl;
+package org.apache.camel.component.djl.model.audio;
import org.apache.camel.Exchange;
import org.apache.camel.component.djl.model.AbstractPredictor;
-import org.apache.camel.component.djl.model.ModelPredictorProducer;
-import org.apache.camel.support.DefaultProducer;
-public class DJLProducer extends DefaultProducer {
- private AbstractPredictor abstractPredictor;
-
- public DJLProducer(DJLEndpoint endpoint) throws Exception {
- super(endpoint);
- if (endpoint.getArtifactId() != null) {
- this.abstractPredictor
- =
ModelPredictorProducer.getZooPredictor(endpoint.getApplication(),
endpoint.getArtifactId());
- } else {
- this.abstractPredictor =
ModelPredictorProducer.getCustomPredictor(endpoint.getApplication(),
endpoint.getModel(),
- endpoint.getTranslator());
- }
+public class ZooAudioClassificationPredictor extends AbstractPredictor {
+ public ZooAudioClassificationPredictor(String artifactId) {
+ super();
}
+ @Override
public void process(Exchange exchange) throws Exception {
- this.abstractPredictor.process(exchange);
+
}
}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/ZooImageClassificationPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/AbstractCvZooPredictor.java
similarity index 50%
rename from
components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/ZooImageClassificationPredictor.java
rename to
components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/AbstractCvZooPredictor.java
index acd3faf01df..12a1aad8915 100644
---
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/ZooImageClassificationPredictor.java
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/AbstractCvZooPredictor.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.djl.model;
+package org.apache.camel.component.djl.model.cv;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -22,81 +22,69 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-import ai.djl.Application;
-import ai.djl.MalformedModelException;
import ai.djl.inference.Predictor;
-import ai.djl.modality.Classifications;
import ai.djl.modality.cv.Image;
import ai.djl.modality.cv.ImageFactory;
-import ai.djl.repository.zoo.Criteria;
-import ai.djl.repository.zoo.ModelNotFoundException;
-import ai.djl.repository.zoo.ModelZoo;
import ai.djl.repository.zoo.ZooModel;
-import ai.djl.training.util.ProgressBar;
import ai.djl.translate.TranslateException;
import org.apache.camel.Exchange;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.djl.DJLConstants;
+import org.apache.camel.component.djl.model.AbstractPredictor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ZooImageClassificationPredictor extends AbstractPredictor {
- private static final Logger LOG =
LoggerFactory.getLogger(ZooImageClassificationPredictor.class);
+public abstract class AbstractCvZooPredictor<T> extends AbstractPredictor {
- private final ZooModel<Image, Classifications> model;
+ private static final Logger LOG =
LoggerFactory.getLogger(AbstractCvZooPredictor.class);
- public ZooImageClassificationPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
- IOException {
- Criteria<Image, Classifications> criteria = Criteria.builder()
- .optApplication(Application.CV.IMAGE_CLASSIFICATION)
- .setTypes(Image.class, Classifications.class)
- .optArtifactId(artifactId)
- .optProgress(new ProgressBar())
- .build();
- this.model = ModelZoo.loadModel(criteria);
- }
+ protected ZooModel<Image, T> model;
@Override
public void process(Exchange exchange) {
- if (exchange.getIn().getBody() instanceof byte[]) {
+ Object body = exchange.getIn().getBody();
+ T result;
+ if (body instanceof Image) {
+ result = predict(exchange, exchange.getIn().getBody(Image.class));
+ } else if (body instanceof byte[]) {
byte[] bytes = exchange.getIn().getBody(byte[].class);
- Classifications result = classify(new ByteArrayInputStream(bytes));
- exchange.getIn().setBody(result);
- } else if (exchange.getIn().getBody() instanceof File) {
- Classifications result =
classify(exchange.getIn().getBody(File.class));
- exchange.getIn().setBody(result);
- } else if (exchange.getIn().getBody() instanceof InputStream) {
- Classifications result =
classify(exchange.getIn().getBody(InputStream.class));
- exchange.getIn().setBody(result);
+ result = predict(exchange, new ByteArrayInputStream(bytes));
+ } else if (body instanceof File) {
+ result = predict(exchange, exchange.getIn().getBody(File.class));
+ } else if (body instanceof InputStream) {
+ result = predict(exchange,
exchange.getIn().getBody(InputStream.class));
} else {
- throw new RuntimeCamelException("Data type is not supported. Body
should be byte[], InputStream or File");
+ throw new RuntimeCamelException(
+ "Data type is not supported. Body should be
ai.djl.modality.cv.Image, byte[], InputStream or File");
}
+ exchange.getIn().setBody(result);
}
- public Classifications classify(File input) {
+ protected T predict(Exchange exchange, File input) {
try (InputStream fileInputStream = new FileInputStream(input)) {
Image image =
ImageFactory.getInstance().fromInputStream(fileInputStream);
- return classify(image);
+ return predict(exchange, image);
} catch (IOException e) {
LOG.error(FAILED_TO_TRANSFORM_MESSAGE);
throw new RuntimeCamelException(FAILED_TO_TRANSFORM_MESSAGE, e);
}
}
- public Classifications classify(InputStream input) {
+ protected T predict(Exchange exchange, InputStream input) {
try {
Image image = ImageFactory.getInstance().fromInputStream(input);
- return classify(image);
+ return predict(exchange, image);
} catch (IOException e) {
LOG.error(FAILED_TO_TRANSFORM_MESSAGE);
throw new RuntimeCamelException(FAILED_TO_TRANSFORM_MESSAGE, e);
}
}
- public Classifications classify(Image image) {
- try (Predictor<Image, Classifications> predictor =
model.newPredictor()) {
+ protected T predict(Exchange exchange, Image image) {
+ exchange.getIn().setHeader(DJLConstants.INPUT, image);
+ try (Predictor<Image, T> predictor = model.newPredictor()) {
return predictor.predict(image);
} catch (TranslateException e) {
- LOG.error("Could not process input or output", e);
throw new RuntimeCamelException("Could not process input or
output", e);
}
}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/CustomImageClassificationPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/CustomImageClassificationPredictor.java
similarity index 96%
rename from
components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/CustomImageClassificationPredictor.java
rename to
components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/CustomImageClassificationPredictor.java
index 11bd46054a5..3e98db60853 100644
---
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/CustomImageClassificationPredictor.java
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/CustomImageClassificationPredictor.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.djl.model;
+package org.apache.camel.component.djl.model.cv;
import java.io.*;
@@ -27,6 +27,7 @@ import ai.djl.translate.TranslateException;
import ai.djl.translate.Translator;
import org.apache.camel.Exchange;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.djl.model.AbstractPredictor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,6 +45,7 @@ public class CustomImageClassificationPredictor extends
AbstractPredictor {
@Override
public void process(Exchange exchange) throws Exception {
Model model =
exchange.getContext().getRegistry().lookupByNameAndType(modelName, Model.class);
+ @SuppressWarnings("unchecked")
Translator<Image, Classifications> translator
=
exchange.getContext().getRegistry().lookupByNameAndType(translatorName,
Translator.class);
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/CustomObjectDetectionPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/CustomObjectDetectionPredictor.java
similarity index 97%
rename from
components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/CustomObjectDetectionPredictor.java
rename to
components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/CustomObjectDetectionPredictor.java
index 8c7b95255e3..f253dd83a1e 100644
---
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/CustomObjectDetectionPredictor.java
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/CustomObjectDetectionPredictor.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.djl.model;
+package org.apache.camel.component.djl.model.cv;
import java.io.*;
@@ -27,6 +27,7 @@ import ai.djl.translate.TranslateException;
import ai.djl.translate.Translator;
import org.apache.camel.Exchange;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.djl.model.AbstractPredictor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooActionRecognitionPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooActionRecognitionPredictor.java
new file mode 100644
index 00000000000..6965ff4ba85
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooActionRecognitionPredictor.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.cv;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.modality.Classifications;
+import ai.djl.modality.cv.Image;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooActionRecognitionPredictor extends
AbstractCvZooPredictor<Classifications> {
+ public ZooActionRecognitionPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
+ IOException {
+ Criteria<Image, Classifications> criteria = Criteria.builder()
+ .optApplication(Application.CV.ACTION_RECOGNITION)
+ .setTypes(Image.class, Classifications.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooImageClassificationPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooImageClassificationPredictor.java
new file mode 100644
index 00000000000..f4555950dba
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooImageClassificationPredictor.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.cv;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.modality.Classifications;
+import ai.djl.modality.cv.Image;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooImageClassificationPredictor extends
AbstractCvZooPredictor<Classifications> {
+
+ public ZooImageClassificationPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
+ IOException {
+ Criteria<Image, Classifications> criteria = Criteria.builder()
+ .optApplication(Application.CV.IMAGE_CLASSIFICATION)
+ .setTypes(Image.class, Classifications.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooImageEnhancementPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooImageEnhancementPredictor.java
new file mode 100644
index 00000000000..a9056497c18
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooImageEnhancementPredictor.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.cv;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.modality.cv.Image;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooImageEnhancementPredictor extends
AbstractCvZooPredictor<Image> {
+
+ public ZooImageEnhancementPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
+ IOException {
+ Criteria<Image, Image> criteria = Criteria.builder()
+ .optApplication(Application.CV.SEMANTIC_SEGMENTATION)
+ .setTypes(Image.class, Image.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooImageGenerationPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooImageGenerationPredictor.java
new file mode 100644
index 00000000000..7e3a77e84cc
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooImageGenerationPredictor.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.cv;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.inference.Predictor;
+import ai.djl.modality.cv.Image;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.repository.zoo.ZooModel;
+import ai.djl.training.util.ProgressBar;
+import ai.djl.translate.TranslateException;
+import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.djl.DJLConstants;
+import org.apache.camel.component.djl.model.AbstractPredictor;
+
+public class ZooImageGenerationPredictor extends AbstractPredictor {
+
+ protected ZooModel<int[], Image[]> model;
+
+ public ZooImageGenerationPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
+ IOException {
+ Criteria<int[], Image[]> criteria = Criteria.builder()
+ .optApplication(Application.CV.IMAGE_GENERATION)
+ .setTypes(int[].class, Image[].class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+
+ @Override
+ public void process(Exchange exchange) {
+ if (exchange.getIn().getBody() instanceof int[]) {
+ int[] seed = exchange.getIn().getBody(int[].class);
+ Image[] result = predict(exchange, seed);
+ exchange.getIn().setBody(result);
+ } else {
+ throw new RuntimeCamelException("Data type is not supported. Body
should be int[]");
+ }
+ }
+
+ protected Image[] predict(Exchange exchange, int[] seed) {
+ exchange.getIn().setHeader(DJLConstants.INPUT, seed);
+ try (Predictor<int[], Image[]> predictor = model.newPredictor()) {
+ return predictor.predict(seed);
+ } catch (TranslateException e) {
+ throw new RuntimeCamelException("Could not process input or
output", e);
+ }
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooInstanceSegmentationPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooInstanceSegmentationPredictor.java
new file mode 100644
index 00000000000..9741b1e7dda
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooInstanceSegmentationPredictor.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.cv;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.modality.cv.Image;
+import ai.djl.modality.cv.output.DetectedObjects;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooInstanceSegmentationPredictor extends
AbstractCvZooPredictor<DetectedObjects> {
+
+ public ZooInstanceSegmentationPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
+ IOException {
+ Criteria<Image, DetectedObjects> criteria = Criteria.builder()
+ .optApplication(Application.CV.INSTANCE_SEGMENTATION)
+ .setTypes(Image.class, DetectedObjects.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooObjectDetectionPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooObjectDetectionPredictor.java
new file mode 100644
index 00000000000..7e918a7cb50
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooObjectDetectionPredictor.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.cv;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.modality.cv.Image;
+import ai.djl.modality.cv.output.DetectedObjects;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooObjectDetectionPredictor extends
AbstractCvZooPredictor<DetectedObjects> {
+
+ public ZooObjectDetectionPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException, IOException {
+ Criteria<Image, DetectedObjects> criteria = Criteria.builder()
+ .optApplication(Application.CV.OBJECT_DETECTION)
+ .setTypes(Image.class, DetectedObjects.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooPoseEstimationPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooPoseEstimationPredictor.java
new file mode 100644
index 00000000000..3edf7659957
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooPoseEstimationPredictor.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.cv;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.modality.cv.Image;
+import ai.djl.modality.cv.output.Joints;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooPoseEstimationPredictor extends AbstractCvZooPredictor<Joints>
{
+ public ZooPoseEstimationPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException, IOException {
+ Criteria<Image, Joints> criteria = Criteria.builder()
+ .optApplication(Application.CV.POSE_ESTIMATION)
+ .setTypes(Image.class, Joints.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooSemanticSegmentationPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooSemanticSegmentationPredictor.java
new file mode 100644
index 00000000000..d1d8143d103
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooSemanticSegmentationPredictor.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.cv;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.modality.cv.Image;
+import ai.djl.modality.cv.output.CategoryMask;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooSemanticSegmentationPredictor extends
AbstractCvZooPredictor<CategoryMask> {
+
+ public ZooSemanticSegmentationPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
+ IOException {
+ Criteria<Image, CategoryMask> criteria = Criteria.builder()
+ .optApplication(Application.CV.SEMANTIC_SEGMENTATION)
+ .setTypes(Image.class, CategoryMask.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooWordRecognitionPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooWordRecognitionPredictor.java
new file mode 100644
index 00000000000..682e9336898
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/cv/ZooWordRecognitionPredictor.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.cv;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.modality.cv.Image;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooWordRecognitionPredictor extends
AbstractCvZooPredictor<String> {
+
+ public ZooWordRecognitionPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
+ IOException {
+ Criteria<Image, String> criteria = Criteria.builder()
+ .optApplication(Application.CV.WORD_RECOGNITION)
+ .setTypes(Image.class, String.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/AbstractNlpZooPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/AbstractNlpZooPredictor.java
new file mode 100644
index 00000000000..bed368f64dd
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/AbstractNlpZooPredictor.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.nlp;
+
+import ai.djl.inference.Predictor;
+import ai.djl.repository.zoo.ZooModel;
+import ai.djl.translate.TranslateException;
+import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.djl.DJLConstants;
+import org.apache.camel.component.djl.model.AbstractPredictor;
+
+public abstract class AbstractNlpZooPredictor<T> extends AbstractPredictor {
+
+ protected ZooModel<String, T> model;
+
+ @Override
+ public void process(Exchange exchange) {
+ if (exchange.getIn().getBody() instanceof String) {
+ String input = exchange.getIn().getBody(String.class);
+ T result = predict(exchange, input);
+ exchange.getIn().setBody(result);
+ } else {
+ throw new RuntimeCamelException("Data type is not supported. Body
should be String");
+ }
+ }
+
+ protected T predict(Exchange exchange, String input) {
+ exchange.getIn().setHeader(DJLConstants.INPUT, input);
+ try (Predictor<String, T> predictor = model.newPredictor()) {
+ return predictor.predict(input);
+ } catch (TranslateException e) {
+ throw new RuntimeCamelException("Could not process input or
output", e);
+ }
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooFillMaskPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooFillMaskPredictor.java
new file mode 100644
index 00000000000..4bc85b0d997
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooFillMaskPredictor.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.nlp;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooFillMaskPredictor extends AbstractNlpZooPredictor<String[]> {
+
+ public ZooFillMaskPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException, IOException {
+ Criteria<String, String[]> criteria = Criteria.builder()
+ .optApplication(Application.NLP.FILL_MASK)
+ .setTypes(String.class, String[].class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooMachineTranslationPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooMachineTranslationPredictor.java
new file mode 100644
index 00000000000..02bac9975ec
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooMachineTranslationPredictor.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.nlp;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooMachineTranslationPredictor extends
AbstractNlpZooPredictor<String> {
+
+ public ZooMachineTranslationPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
+ IOException {
+ Criteria<String, String> criteria = Criteria.builder()
+ .optApplication(Application.NLP.TEXT_GENERATION)
+ .setTypes(String.class, String.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooMultipleChoicePredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooMultipleChoicePredictor.java
new file mode 100644
index 00000000000..324b4be0192
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooMultipleChoicePredictor.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.nlp;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooMultipleChoicePredictor extends
AbstractNlpZooPredictor<String> {
+
+ public ZooMultipleChoicePredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
+ IOException {
+ Criteria<String, String> criteria = Criteria.builder()
+ .optApplication(Application.NLP.MULTIPLE_CHOICE)
+ .setTypes(String.class, String.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooQuestionAnswerPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooQuestionAnswerPredictor.java
new file mode 100644
index 00000000000..a64e5c579b8
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooQuestionAnswerPredictor.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.nlp;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.inference.Predictor;
+import ai.djl.modality.nlp.qa.QAInput;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.repository.zoo.ZooModel;
+import ai.djl.training.util.ProgressBar;
+import ai.djl.translate.TranslateException;
+import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.djl.DJLConstants;
+import org.apache.camel.component.djl.model.AbstractPredictor;
+
+public class ZooQuestionAnswerPredictor extends AbstractPredictor {
+
+ private final ZooModel<QAInput, String> model;
+
+ public ZooQuestionAnswerPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException, IOException {
+ Criteria<QAInput, String> criteria = Criteria.builder()
+ .optApplication(Application.NLP.QUESTION_ANSWER)
+ .setTypes(QAInput.class, String.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Object body = exchange.getIn().getBody();
+ String result;
+ if (body instanceof QAInput) {
+ QAInput input = exchange.getIn().getBody(QAInput.class);
+ result = predict(exchange, input);
+ } else if (body instanceof String[]) {
+ String[] strs = exchange.getIn().getBody(String[].class);
+ if (strs.length < 2) {
+ throw new RuntimeCamelException("Input String[] should have
two elements");
+ }
+ QAInput input = new QAInput(strs[0], strs[1]);
+ result = predict(exchange, input);
+ } else {
+ throw new RuntimeCamelException("Data type is not supported. Body
should be String[] or QAInput");
+ }
+ exchange.getIn().setBody(result);
+ }
+
+ protected String predict(Exchange exchange, QAInput input) {
+ exchange.getIn().setHeader(DJLConstants.INPUT, input);
+ try (Predictor<QAInput, String> predictor = model.newPredictor()) {
+ return predictor.predict(input);
+ } catch (TranslateException e) {
+ throw new RuntimeCamelException("Could not process input or
output", e);
+ }
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooSentimentAnalysisPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooSentimentAnalysisPredictor.java
new file mode 100644
index 00000000000..e43032730b4
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooSentimentAnalysisPredictor.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.nlp;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.modality.Classifications;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooSentimentAnalysisPredictor extends
AbstractNlpZooPredictor<Classifications> {
+
+ public ZooSentimentAnalysisPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
+ IOException {
+ Criteria<String, Classifications> criteria = Criteria.builder()
+ .optApplication(Application.NLP.SENTIMENT_ANALYSIS)
+ .setTypes(String.class, Classifications.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooTextClassificationPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooTextClassificationPredictor.java
new file mode 100644
index 00000000000..98aca9d19aa
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooTextClassificationPredictor.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.nlp;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.modality.Classifications;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooTextClassificationPredictor extends
AbstractNlpZooPredictor<Classifications> {
+
+ public ZooTextClassificationPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
+ IOException {
+ Criteria<String, Classifications> criteria = Criteria.builder()
+ .optApplication(Application.NLP.TEXT_CLASSIFICATION)
+ .setTypes(String.class, Classifications.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooTextEmbeddingPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooTextEmbeddingPredictor.java
new file mode 100644
index 00000000000..8369bb3ade1
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooTextEmbeddingPredictor.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.nlp;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.ndarray.NDArray;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooTextEmbeddingPredictor extends
AbstractNlpZooPredictor<NDArray> {
+
+ public ZooTextEmbeddingPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
+ IOException {
+ Criteria<String, NDArray> criteria = Criteria.builder()
+ .optApplication(Application.NLP.TEXT_EMBEDDING)
+ .setTypes(String.class, NDArray.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooTextGenerationPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooTextGenerationPredictor.java
new file mode 100644
index 00000000000..47574950357
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooTextGenerationPredictor.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.nlp;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooTextGenerationPredictor extends
AbstractNlpZooPredictor<String> {
+
+ public ZooTextGenerationPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
+ IOException {
+ Criteria<String, String> criteria = Criteria.builder()
+ .optApplication(Application.NLP.TEXT_GENERATION)
+ .setTypes(String.class, String.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooTokenClassificationPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooTokenClassificationPredictor.java
new file mode 100644
index 00000000000..0084645d33a
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooTokenClassificationPredictor.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.nlp;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.modality.Classifications;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+
+public class ZooTokenClassificationPredictor extends
AbstractNlpZooPredictor<Classifications> {
+
+ public ZooTokenClassificationPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
+ IOException {
+ Criteria<String, Classifications> criteria = Criteria.builder()
+ .optApplication(Application.NLP.TOKEN_CLASSIFICATION)
+ .setTypes(String.class, Classifications.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooWordEmbeddingPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooWordEmbeddingPredictor.java
new file mode 100644
index 00000000000..88326bd4a32
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/nlp/ZooWordEmbeddingPredictor.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.nlp;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.ndarray.NDList;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.training.util.ProgressBar;
+import org.apache.camel.Exchange;
+
+public class ZooWordEmbeddingPredictor extends AbstractNlpZooPredictor<NDList>
{
+
+ public ZooWordEmbeddingPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException,
+ IOException {
+ Criteria<String, NDList> criteria = Criteria.builder()
+ .optApplication(Application.NLP.WORD_EMBEDDING)
+ .setTypes(String.class, NDList.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+
+ @Override
+ public void process(Exchange exchange) {
+ super.process(exchange);
+ // DJL NDList should not be exposed outside the endpoint
+ NDList result = exchange.getIn().getBody(NDList.class);
+ exchange.getIn().setBody(result.encode());
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/tabular/ZooLinearRegressionPredictor.java
similarity index 55%
copy from
components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java
copy to
components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/tabular/ZooLinearRegressionPredictor.java
index 316bff2e1fc..3d221f95127 100644
---
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/tabular/ZooLinearRegressionPredictor.java
@@ -14,28 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.djl;
+package org.apache.camel.component.djl.model.tabular;
import org.apache.camel.Exchange;
import org.apache.camel.component.djl.model.AbstractPredictor;
-import org.apache.camel.component.djl.model.ModelPredictorProducer;
-import org.apache.camel.support.DefaultProducer;
-public class DJLProducer extends DefaultProducer {
- private AbstractPredictor abstractPredictor;
-
- public DJLProducer(DJLEndpoint endpoint) throws Exception {
- super(endpoint);
- if (endpoint.getArtifactId() != null) {
- this.abstractPredictor
- =
ModelPredictorProducer.getZooPredictor(endpoint.getApplication(),
endpoint.getArtifactId());
- } else {
- this.abstractPredictor =
ModelPredictorProducer.getCustomPredictor(endpoint.getApplication(),
endpoint.getModel(),
- endpoint.getTranslator());
- }
+public class ZooLinearRegressionPredictor extends AbstractPredictor {
+ public ZooLinearRegressionPredictor(String artifactId) {
+ super();
}
+ @Override
public void process(Exchange exchange) throws Exception {
- this.abstractPredictor.process(exchange);
+
}
}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/tabular/ZooSoftmaxRegressionPredictor.java
similarity index 55%
copy from
components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java
copy to
components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/tabular/ZooSoftmaxRegressionPredictor.java
index 316bff2e1fc..31dba3a7f77 100644
---
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/tabular/ZooSoftmaxRegressionPredictor.java
@@ -14,28 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.djl;
+package org.apache.camel.component.djl.model.tabular;
import org.apache.camel.Exchange;
import org.apache.camel.component.djl.model.AbstractPredictor;
-import org.apache.camel.component.djl.model.ModelPredictorProducer;
-import org.apache.camel.support.DefaultProducer;
-public class DJLProducer extends DefaultProducer {
- private AbstractPredictor abstractPredictor;
-
- public DJLProducer(DJLEndpoint endpoint) throws Exception {
- super(endpoint);
- if (endpoint.getArtifactId() != null) {
- this.abstractPredictor
- =
ModelPredictorProducer.getZooPredictor(endpoint.getApplication(),
endpoint.getArtifactId());
- } else {
- this.abstractPredictor =
ModelPredictorProducer.getCustomPredictor(endpoint.getApplication(),
endpoint.getModel(),
- endpoint.getTranslator());
- }
+public class ZooSoftmaxRegressionPredictor extends AbstractPredictor {
+ public ZooSoftmaxRegressionPredictor(String artifactId) {
+ super();
}
+ @Override
public void process(Exchange exchange) throws Exception {
- this.abstractPredictor.process(exchange);
+
}
}
diff --git
a/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/timeseries/ZooForecastingPredictor.java
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/timeseries/ZooForecastingPredictor.java
new file mode 100644
index 00000000000..d563f3fd946
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/main/java/org/apache/camel/component/djl/model/timeseries/ZooForecastingPredictor.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model.timeseries;
+
+import java.io.IOException;
+
+import ai.djl.Application;
+import ai.djl.MalformedModelException;
+import ai.djl.inference.Predictor;
+import ai.djl.repository.zoo.Criteria;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import ai.djl.repository.zoo.ModelZoo;
+import ai.djl.repository.zoo.ZooModel;
+import ai.djl.timeseries.Forecast;
+import ai.djl.timeseries.TimeSeriesData;
+import ai.djl.training.util.ProgressBar;
+import ai.djl.translate.TranslateException;
+import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.djl.DJLConstants;
+import org.apache.camel.component.djl.model.AbstractPredictor;
+
+public class ZooForecastingPredictor extends AbstractPredictor {
+
+ private final ZooModel<TimeSeriesData, Forecast> model;
+
+ public ZooForecastingPredictor(String artifactId) throws
ModelNotFoundException, MalformedModelException, IOException {
+ Criteria<TimeSeriesData, Forecast> criteria = Criteria.builder()
+ .optApplication(Application.TimeSeries.FORECASTING)
+ .setTypes(TimeSeriesData.class, Forecast.class)
+ .optArtifactId(artifactId)
+ .optProgress(new ProgressBar())
+ .build();
+ this.model = ModelZoo.loadModel(criteria);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ if (exchange.getIn().getBody() instanceof TimeSeriesData) {
+ TimeSeriesData input =
exchange.getIn().getBody(TimeSeriesData.class);
+ Forecast result = predict(exchange, input);
+ exchange.getIn().setBody(result);
+ } else {
+ throw new RuntimeCamelException("Data type is not supported. Body
should be TimeSeriesData");
+ }
+ }
+
+ protected Forecast predict(Exchange exchange, TimeSeriesData input) {
+ exchange.getIn().setHeader(DJLConstants.INPUT, input);
+ try (Predictor<TimeSeriesData, Forecast> predictor =
model.newPredictor()) {
+ return predictor.predict(input);
+ } catch (TranslateException e) {
+ throw new RuntimeCamelException("Could not process input or
output", e);
+ }
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvActionRecognitionTest.java
similarity index 81%
copy from
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
copy to
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvActionRecognitionTest.java
index e95de31d4ce..377f023b28a 100644
---
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
+++
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvActionRecognitionTest.java
@@ -14,16 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.component.djl;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-public class ObjectDetectionTest extends CamelTestSupport {
+public class CvActionRecognitionTest extends CamelTestSupport {
@BeforeAll
public static void setupDefaultEngine() {
@@ -33,8 +31,8 @@ public class ObjectDetectionTest extends CamelTestSupport {
@Test
void testDJL() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedMinimumMessageCount(3);
+ var mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
mock.await();
}
@@ -42,9 +40,9 @@ public class ObjectDetectionTest extends CamelTestSupport {
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
-
from("file:src/test/resources/data/detect?recursive=true&noop=true")
+
from("file:src/test/resources/data/action?recursive=true&noop=true")
.convertBodyTo(byte[].class)
-
.to("djl:cv/object_detection?artifactId=ai.djl.pytorch:ssd:0.0.1")
+
.to("djl:cv/action_recognition?artifactId=ai.djl.mxnet:action_recognition:0.0.1")
.log("${header.CamelFileName} = ${body}")
.to("mock:result");
}
diff --git
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ImageClassificationLocalTest.java
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvImageClassificationLocalTest.java
similarity index 96%
rename from
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ImageClassificationLocalTest.java
rename to
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvImageClassificationLocalTest.java
index 01d5dad583e..8c3c02180fc 100644
---
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ImageClassificationLocalTest.java
+++
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvImageClassificationLocalTest.java
@@ -41,8 +41,8 @@ import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
-public class ImageClassificationLocalTest extends CamelTestSupport {
- private static final Logger LOG =
LoggerFactory.getLogger(ImageClassificationLocalTest.class);
+public class CvImageClassificationLocalTest extends CamelTestSupport {
+ private static final Logger LOG =
LoggerFactory.getLogger(CvImageClassificationLocalTest.class);
private static final String MODEL_DIR = "src/test/resources/models/mnist";
private static final String MODEL_NAME = "mlp";
diff --git
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ImageClassificationTest.java
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvImageClassificationTest.java
similarity index 91%
copy from
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ImageClassificationTest.java
copy to
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvImageClassificationTest.java
index 08ca2ddd018..a567a520a6c 100644
---
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ImageClassificationTest.java
+++
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvImageClassificationTest.java
@@ -18,12 +18,11 @@
package org.apache.camel.component.djl;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-public class ImageClassificationTest extends CamelTestSupport {
+public class CvImageClassificationTest extends CamelTestSupport {
@BeforeAll
public static void setupDefaultEngine() {
@@ -33,7 +32,7 @@ public class ImageClassificationTest extends CamelTestSupport
{
@Test
void testDJL() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
+ var mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(98);
mock.await();
}
diff --git
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvImageGenerationTest.java
similarity index 60%
copy from
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
copy to
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvImageGenerationTest.java
index e95de31d4ce..d866e22518e 100644
---
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
+++
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvImageGenerationTest.java
@@ -14,16 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.component.djl;
+import java.io.ByteArrayOutputStream;
+
+import ai.djl.modality.cv.Image;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-public class ObjectDetectionTest extends CamelTestSupport {
+public class CvImageGenerationTest extends CamelTestSupport {
@BeforeAll
public static void setupDefaultEngine() {
@@ -33,8 +34,8 @@ public class ObjectDetectionTest extends CamelTestSupport {
@Test
void testDJL() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedMinimumMessageCount(3);
+ var mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(5);
mock.await();
}
@@ -42,10 +43,18 @@ public class ObjectDetectionTest extends CamelTestSupport {
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
-
from("file:src/test/resources/data/detect?recursive=true&noop=true")
- .convertBodyTo(byte[].class)
-
.to("djl:cv/object_detection?artifactId=ai.djl.pytorch:ssd:0.0.1")
- .log("${header.CamelFileName} = ${body}")
+ from("timer:testDJL?repeatCount=1")
+ .setBody(constant(new int[] { 100, 207, 971, 970, 933
}))
+
.to("djl:cv/image_generation?artifactId=ai.djl.pytorch:biggan-deep:0.0.1")
+ .split(body())
+ .log("image = ${body}")
+ .process(exchange -> {
+ var image = exchange.getIn().getBody(Image.class);
+ var os = new ByteArrayOutputStream();
+ image.save(os, "png");
+ exchange.getIn().setBody(os.toByteArray());
+ })
+
.to("file:target/output?fileName=ImageGenerationTest-${date:now:ssSSS}.png")
.to("mock:result");
}
};
diff --git
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvInstanceSegmentationTest.java
similarity index 87%
copy from
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
copy to
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvInstanceSegmentationTest.java
index e95de31d4ce..5b57616cc91 100644
---
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
+++
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvInstanceSegmentationTest.java
@@ -14,16 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.component.djl;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-public class ObjectDetectionTest extends CamelTestSupport {
+public class CvInstanceSegmentationTest extends CamelTestSupport {
@BeforeAll
public static void setupDefaultEngine() {
@@ -33,7 +31,7 @@ public class ObjectDetectionTest extends CamelTestSupport {
@Test
void testDJL() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
+ var mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(3);
mock.await();
}
@@ -44,7 +42,7 @@ public class ObjectDetectionTest extends CamelTestSupport {
public void configure() {
from("file:src/test/resources/data/detect?recursive=true&noop=true")
.convertBodyTo(byte[].class)
-
.to("djl:cv/object_detection?artifactId=ai.djl.pytorch:ssd:0.0.1")
+
.to("djl:cv/instance_segmentation?artifactId=ai.djl.mxnet:mask_rcnn:0.0.1")
.log("${header.CamelFileName} = ${body}")
.to("mock:result");
}
diff --git
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvObjectDetectionTest.java
similarity index 91%
copy from
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
copy to
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvObjectDetectionTest.java
index e95de31d4ce..6a84201fff4 100644
---
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
+++
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvObjectDetectionTest.java
@@ -18,12 +18,11 @@
package org.apache.camel.component.djl;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-public class ObjectDetectionTest extends CamelTestSupport {
+public class CvObjectDetectionTest extends CamelTestSupport {
@BeforeAll
public static void setupDefaultEngine() {
@@ -33,7 +32,7 @@ public class ObjectDetectionTest extends CamelTestSupport {
@Test
void testDJL() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
+ var mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(3);
mock.await();
}
diff --git
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvPoseEstimationTest.java
similarity index 55%
copy from
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
copy to
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvPoseEstimationTest.java
index e95de31d4ce..5d70f6acae2 100644
---
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
+++
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvPoseEstimationTest.java
@@ -14,16 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.component.djl;
+import ai.djl.modality.cv.Image;
+import ai.djl.modality.cv.output.DetectedObjects;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-public class ObjectDetectionTest extends CamelTestSupport {
+public class CvPoseEstimationTest extends CamelTestSupport {
@BeforeAll
public static void setupDefaultEngine() {
@@ -33,8 +33,8 @@ public class ObjectDetectionTest extends CamelTestSupport {
@Test
void testDJL() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedMinimumMessageCount(3);
+ var mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
mock.await();
}
@@ -42,9 +42,23 @@ public class ObjectDetectionTest extends CamelTestSupport {
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
-
from("file:src/test/resources/data/detect?recursive=true&noop=true")
+
from("file:src/test/resources/data/pose?recursive=true&noop=true")
.convertBodyTo(byte[].class)
-
.to("djl:cv/object_detection?artifactId=ai.djl.pytorch:ssd:0.0.1")
+
.to("djl:cv/object_detection?artifactId=ai.djl.mxnet:ssd:0.0.1")
+ .log("${header.CamelFileName} = ${body}")
+ .split(simple("${body.items}"))
+ .filter(simple("${body.className} == 'person'"))
+ .process(exchange -> {
+ var obj =
exchange.getMessage().getBody(DetectedObjects.DetectedObject.class);
+ var rect = obj.getBoundingBox().getBounds();
+ var image =
exchange.getIn().getHeader(DJLConstants.INPUT, Image.class);
+ exchange.getIn().setBody(image.getSubImage(
+ (int) (rect.getX() * image.getWidth()),
+ (int) (rect.getY() * image.getHeight()),
+ (int) (rect.getWidth() * image.getWidth()),
+ (int) (rect.getHeight() *
image.getHeight())));
+ })
+
.to("djl:cv/pose_estimation?artifactId=ai.djl.mxnet:simple_pose:0.0.1")
.log("${header.CamelFileName} = ${body}")
.to("mock:result");
}
diff --git
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvSemanticSegmentationTest.java
similarity index 87%
copy from
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
copy to
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvSemanticSegmentationTest.java
index e95de31d4ce..2035d690320 100644
---
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
+++
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/CvSemanticSegmentationTest.java
@@ -14,16 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.component.djl;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-public class ObjectDetectionTest extends CamelTestSupport {
+public class CvSemanticSegmentationTest extends CamelTestSupport {
@BeforeAll
public static void setupDefaultEngine() {
@@ -33,7 +31,7 @@ public class ObjectDetectionTest extends CamelTestSupport {
@Test
void testDJL() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
+ var mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(3);
mock.await();
}
@@ -44,7 +42,7 @@ public class ObjectDetectionTest extends CamelTestSupport {
public void configure() {
from("file:src/test/resources/data/detect?recursive=true&noop=true")
.convertBodyTo(byte[].class)
-
.to("djl:cv/object_detection?artifactId=ai.djl.pytorch:ssd:0.0.1")
+
.to("djl:cv/semantic_segmentation?artifactId=ai.djl.pytorch:deeplabv3:0.0.1")
.log("${header.CamelFileName} = ${body}")
.to("mock:result");
}
diff --git
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ImageClassificationTest.java
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/NlpQuestionAnswerTest.java
similarity index 68%
rename from
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ImageClassificationTest.java
rename to
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/NlpQuestionAnswerTest.java
index 08ca2ddd018..e17ecd34bff 100644
---
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ImageClassificationTest.java
+++
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/NlpQuestionAnswerTest.java
@@ -14,16 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.component.djl;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-public class ImageClassificationTest extends CamelTestSupport {
+public class NlpQuestionAnswerTest extends CamelTestSupport {
@BeforeAll
public static void setupDefaultEngine() {
@@ -33,8 +31,8 @@ public class ImageClassificationTest extends CamelTestSupport
{
@Test
void testDJL() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedMinimumMessageCount(98);
+ var mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
mock.await();
}
@@ -42,10 +40,13 @@ public class ImageClassificationTest extends
CamelTestSupport {
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
-
from("file:src/test/resources/data/mnist?recursive=true&noop=true")
- .convertBodyTo(byte[].class)
-
.to("djl:cv/image_classification?artifactId=ai.djl.zoo:mlp:0.0.3")
- .log("${header.CamelFileName} =
${body.best.className}")
+ from("timer:testDJL?repeatCount=1")
+ .setBody(constant((Object) new String[] {
+ "When did BBC Japan start broadcasting?",
+ "BBC Japan was a general entertainment
channel, which operated between December 2004 and April 2006. It ceased
operations after its Japanese distributor folded."
+ }))
+
.to("djl:nlp/question_answer?artifactId=ai.djl.pytorch:bertqa:0.0.1")
+ .log("Answer: ${body}")
.to("mock:result");
}
};
diff --git
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/NlpSentimentAnalysisTest.java
similarity index 71%
copy from
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
copy to
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/NlpSentimentAnalysisTest.java
index e95de31d4ce..3015df17a1b 100644
---
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
+++
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/NlpSentimentAnalysisTest.java
@@ -14,16 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.component.djl;
+import java.util.List;
+
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-public class ObjectDetectionTest extends CamelTestSupport {
+public class NlpSentimentAnalysisTest extends CamelTestSupport {
@BeforeAll
public static void setupDefaultEngine() {
@@ -33,7 +33,7 @@ public class ObjectDetectionTest extends CamelTestSupport {
@Test
void testDJL() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
+ var mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(3);
mock.await();
}
@@ -42,10 +42,14 @@ public class ObjectDetectionTest extends CamelTestSupport {
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
-
from("file:src/test/resources/data/detect?recursive=true&noop=true")
- .convertBodyTo(byte[].class)
-
.to("djl:cv/object_detection?artifactId=ai.djl.pytorch:ssd:0.0.1")
- .log("${header.CamelFileName} = ${body}")
+ from("timer:testDJL?repeatCount=1")
+ .setBody(constant(List.of(
+ "Camel AI is cool!",
+ "Donkey AI is awful...",
+ "Camel DJL is awesome!")))
+ .split(body())
+
.to("djl:nlp/sentiment_analysis?artifactId=ai.djl.pytorch:distilbert:0.0.1")
+ .log("\"${header.CamelDjlInput}\" =>
${body.best.className}")
.to("mock:result");
}
};
diff --git
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/NlpWordEmbeddingTest.java
similarity index 72%
rename from
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
rename to
components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/NlpWordEmbeddingTest.java
index e95de31d4ce..93625190cfe 100644
---
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java
+++
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/NlpWordEmbeddingTest.java
@@ -14,16 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.component.djl;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
-public class ObjectDetectionTest extends CamelTestSupport {
+@Disabled("There is an issue with the DJL model used")
+public class NlpWordEmbeddingTest extends CamelTestSupport {
@BeforeAll
public static void setupDefaultEngine() {
@@ -33,8 +33,8 @@ public class ObjectDetectionTest extends CamelTestSupport {
@Test
void testDJL() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedMinimumMessageCount(3);
+ var mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(4);
mock.await();
}
@@ -42,10 +42,11 @@ public class ObjectDetectionTest extends CamelTestSupport {
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
-
from("file:src/test/resources/data/detect?recursive=true&noop=true")
- .convertBodyTo(byte[].class)
-
.to("djl:cv/object_detection?artifactId=ai.djl.pytorch:ssd:0.0.1")
- .log("${header.CamelFileName} = ${body}")
+ from("timer:testDJL?repeatCount=1")
+ .setBody(constant("Camel AI is awesome"))
+ .split(body().tokenize(" "))
+
.to("djl:nlp/word_embedding?artifactId=ai.djl.mxnet:glove:0.0.2")
+ .log("\"${header.CamelDjlInput}\" => ${body}")
.to("mock:result");
}
};
diff --git
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/TimeSeriesForecastingTest.java
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/TimeSeriesForecastingTest.java
new file mode 100644
index 00000000000..c6e1292858d
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/TimeSeriesForecastingTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl;
+
+import java.time.LocalDateTime;
+
+import ai.djl.ndarray.NDManager;
+import ai.djl.timeseries.TimeSeriesData;
+import ai.djl.timeseries.dataset.FieldName;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+public class TimeSeriesForecastingTest extends CamelTestSupport {
+
+ @BeforeAll
+ public static void setupDefaultEngine() {
+ // Since Apache MXNet is discontinued, prefer PyTorch as the default
engine
+ System.setProperty("ai.djl.default_engine", "PyTorch");
+ }
+
+ @Test
+ void testDJL() throws Exception {
+ var mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
+ mock.await();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("timer:testDJL?repeatCount=1")
+ .process(exchange -> {
+ var input = new TimeSeriesData(10);
+ input.setStartTime(LocalDateTime.now());
+ var manager = NDManager.newBaseManager("PyTorch");
+ var data = manager.create(new float[] {
+ 1.0f, 2.0f, 1.0f, 2.0f, 3.0f,
+ 1.0f, 2.0f, 3.0f, 4.0f, 1.0f });
+ input.setField(FieldName.TARGET, data);
+ exchange.getIn().setBody(input);
+ exchange.getIn().setHeader("NDManager", manager);
+ })
+ .doTry()
+
.to("djl:timeseries/forecasting?artifactId=ai.djl.pytorch:deepar:0.0.1")
+ .log("Mean: ${body.mean}")
+ .log("Median: ${body.median}")
+ .doFinally()
+ .process(exchange -> {
+ var manager =
exchange.getIn().getHeader("NDManager", NDManager.class);
+ manager.close();
+ })
+ .end()
+ .to("mock:result");
+ }
+ };
+ }
+
+}
diff --git
a/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/model/ModelPredictorProducerTest.java
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/model/ModelPredictorProducerTest.java
new file mode 100644
index 00000000000..3dd441c0159
--- /dev/null
+++
b/components/camel-ai/camel-djl/src/test/java/org/apache/camel/component/djl/model/ModelPredictorProducerTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.djl.model;
+
+import java.io.IOException;
+
+import ai.djl.MalformedModelException;
+import ai.djl.repository.zoo.ModelNotFoundException;
+import org.apache.camel.component.djl.model.cv.ZooActionRecognitionPredictor;
+import org.apache.camel.component.djl.model.cv.ZooImageClassificationPredictor;
+import org.apache.camel.component.djl.model.cv.ZooImageGenerationPredictor;
+import
org.apache.camel.component.djl.model.cv.ZooInstanceSegmentationPredictor;
+import org.apache.camel.component.djl.model.cv.ZooObjectDetectionPredictor;
+import org.apache.camel.component.djl.model.cv.ZooPoseEstimationPredictor;
+import
org.apache.camel.component.djl.model.cv.ZooSemanticSegmentationPredictor;
+import org.apache.camel.component.djl.model.nlp.ZooQuestionAnswerPredictor;
+import org.apache.camel.component.djl.model.nlp.ZooSentimentAnalysisPredictor;
+import org.apache.camel.component.djl.model.nlp.ZooWordEmbeddingPredictor;
+import org.apache.camel.component.djl.model.timeseries.ZooForecastingPredictor;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static
org.apache.camel.component.djl.model.ModelPredictorProducer.getZooPredictor;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+
+class ModelPredictorProducerTest {
+
+ @BeforeAll
+ public static void setupDefaultEngine() {
+ // Since Apache MXNet is discontinued, prefer PyTorch as the default
engine
+ System.setProperty("ai.djl.default_engine", "PyTorch");
+ }
+
+ @Test
+ void testGetZooPredictor() throws ModelNotFoundException,
MalformedModelException, IOException {
+ // CV
+ assertInstanceOf(ZooImageClassificationPredictor.class,
+ getZooPredictor("cv/image_classification",
"ai.djl.zoo:mlp:0.0.3"));
+ assertInstanceOf(ZooObjectDetectionPredictor.class,
+ getZooPredictor("cv/object_detection",
"ai.djl.zoo:ssd:0.0.2"));
+ assertInstanceOf(ZooSemanticSegmentationPredictor.class,
+ getZooPredictor("cv/semantic_segmentation",
"ai.djl.pytorch:deeplabv3:0.0.1"));
+ assertInstanceOf(ZooInstanceSegmentationPredictor.class,
+ getZooPredictor("cv/instance_segmentation",
"ai.djl.mxnet:mask_rcnn:0.0.1"));
+ assertInstanceOf(ZooPoseEstimationPredictor.class,
+ getZooPredictor("cv/pose_estimation",
"ai.djl.mxnet:simple_pose:0.0.1"));
+ assertInstanceOf(ZooActionRecognitionPredictor.class,
+ getZooPredictor("cv/action_recognition",
"ai.djl.mxnet:action_recognition:0.0.1"));
+ // No builtin zoo model available for "cv/word_recognition"
+ assertInstanceOf(ZooImageGenerationPredictor.class,
+ getZooPredictor("cv/image_generation",
"ai.djl.pytorch:biggan-deep:0.0.1"));
+ // No builtin zoo model available for "cv/image_enhancement"
+
+ // NLP
+ // No builtin zoo model available for "nlp/fill_mask"
+ assertInstanceOf(ZooQuestionAnswerPredictor.class,
+ getZooPredictor("nlp/question_answer",
"ai.djl.pytorch:bertqa:0.0.1"));
+ // No builtin zoo model available for "nlp/text_classification"
+ assertInstanceOf(ZooSentimentAnalysisPredictor.class,
+ getZooPredictor("nlp/sentiment_analysis",
"ai.djl.pytorch:distilbert:0.0.1"));
+ // No builtin zoo model available for "nlp/token_classification"
+ assertInstanceOf(ZooWordEmbeddingPredictor.class,
+ getZooPredictor("nlp/word_embedding",
"ai.djl.mxnet:glove:0.0.2"));
+ // No builtin zoo model available for "nlp/text_generation"
+ // No builtin zoo model available for "nlp/machine_translation"
+ // No builtin zoo model available for "nlp/multiple_choice"
+ // No builtin zoo model available for "nlp/text_embedding"
+
+ // Tabular
+ // No builtin zoo model available for "tabular/linear_regression"
+ // No builtin zoo model available for "tabular/softmax_regression"
+
+ // Audio
+ // No builtin zoo model available for "audio"
+
+ // Time Series
+ assertInstanceOf(ZooForecastingPredictor.class,
+ getZooPredictor("timeseries/forecasting",
"ai.djl.pytorch:deepar:0.0.1"));
+ }
+}
diff --git
a/components/camel-ai/camel-djl/src/test/resources/data/action/action_discus_throw.png
b/components/camel-ai/camel-djl/src/test/resources/data/action/action_discus_throw.png
new file mode 100644
index 00000000000..40591fd4334
Binary files /dev/null and
b/components/camel-ai/camel-djl/src/test/resources/data/action/action_discus_throw.png
differ
diff --git
a/components/camel-ai/camel-djl/src/test/resources/data/pose/pose_soccer.png
b/components/camel-ai/camel-djl/src/test/resources/data/pose/pose_soccer.png
new file mode 100644
index 00000000000..81fd19eb0ea
Binary files /dev/null and
b/components/camel-ai/camel-djl/src/test/resources/data/pose/pose_soccer.png
differ