This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 1bde2ed1d3bfd33a43b667f9070be95b411c7900 Author: Marat Gubaidullin <marat.gubaidul...@gmail.com> AuthorDate: Wed Apr 1 15:25:40 2020 -0400 CAMEL-14808. Initial component version --- bom/camel-bom/pom.xml | 5 + components/camel-djl/pom.xml | 174 ++++++++++++++++++ .../component/djl/DJLComponentConfigurer.java | 27 +++ .../camel/component/djl/DJLEndpointConfigurer.java | 32 ++++ .../services/org/apache/camel/component.properties | 7 + .../services/org/apache/camel/component/djl | 2 + .../org/apache/camel/configurer/djl-component | 2 + .../org/apache/camel/configurer/djl-endpoint | 2 + .../org/apache/camel/component/djl/djl.json | 34 ++++ .../camel-djl/src/main/docs/djl-component.adoc | 203 +++++++++++++++++++++ .../apache/camel/component/djl/DJLComponent.java | 25 +++ .../apache/camel/component/djl/DJLEndpoint.java | 82 +++++++++ .../apache/camel/component/djl/DJLProducer.java | 31 ++++ .../component/djl/model/AbstractPredictor.java | 9 + .../model/CustomImageClassificationPredictor.java | 82 +++++++++ .../djl/model/CustomObjectDetectionPredictor.java | 75 ++++++++ .../djl/model/ModelPredictorProducer.java | 27 +++ .../djl/model/ZooImageClassificationPredictor.java | 87 +++++++++ .../djl/model/ZooObjectDetectionPredictor.java | 85 +++++++++ .../services/org/apache/camel/component/djl | 1 + .../djl/ImageClassificationLocalTest.java | 81 ++++++++ .../component/djl/ImageClassificationTest.java | 30 +++ .../camel/component/djl/ObjectDetectionTest.java | 30 +++ .../component/djl/training/MnistTraining.java | 93 ++++++++++ .../src/test/resources/data/detect/dog-cat.jpg | Bin 0 -> 229963 bytes .../test/resources/data/detect/dog_bike_car.jpg | Bin 0 -> 163759 bytes .../src/test/resources/data/detect/kitten.jpg | Bin 0 -> 16016 bytes .../src/test/resources/data/mnist/0/10.png | Bin 0 -> 272 bytes .../src/test/resources/data/mnist/0/13.png | Bin 0 -> 288 bytes .../src/test/resources/data/mnist/0/25.png | Bin 0 -> 297 bytes .../src/test/resources/data/mnist/0/28.png | Bin 0 -> 261 bytes .../src/test/resources/data/mnist/0/3.png | Bin 0 -> 266 bytes .../src/test/resources/data/mnist/0/55.png | Bin 0 -> 267 bytes .../src/test/resources/data/mnist/0/69.png | Bin 0 -> 291 bytes .../src/test/resources/data/mnist/0/71.png | Bin 0 -> 289 bytes .../src/test/resources/data/mnist/1/14.png | Bin 0 -> 121 bytes .../src/test/resources/data/mnist/1/2.png | Bin 0 -> 181 bytes .../src/test/resources/data/mnist/1/29.png | Bin 0 -> 154 bytes .../src/test/resources/data/mnist/1/31.png | Bin 0 -> 163 bytes .../src/test/resources/data/mnist/1/37.png | Bin 0 -> 145 bytes .../src/test/resources/data/mnist/1/39.png | Bin 0 -> 176 bytes .../src/test/resources/data/mnist/1/5.png | Bin 0 -> 199 bytes .../src/test/resources/data/mnist/2/1.png | Bin 0 -> 255 bytes .../src/test/resources/data/mnist/2/35.png | Bin 0 -> 285 bytes .../src/test/resources/data/mnist/2/43.png | Bin 0 -> 204 bytes .../src/test/resources/data/mnist/2/47.png | Bin 0 -> 255 bytes .../src/test/resources/data/mnist/2/72.png | Bin 0 -> 282 bytes .../src/test/resources/data/mnist/2/77.png | Bin 0 -> 239 bytes .../src/test/resources/data/mnist/2/82.png | Bin 0 -> 256 bytes .../src/test/resources/data/mnist/3/18.png | Bin 0 -> 318 bytes .../src/test/resources/data/mnist/3/30.png | Bin 0 -> 242 bytes .../src/test/resources/data/mnist/3/32.png | Bin 0 -> 254 bytes .../src/test/resources/data/mnist/3/44.png | Bin 0 -> 224 bytes .../src/test/resources/data/mnist/3/51.png | Bin 0 -> 272 bytes .../src/test/resources/data/mnist/3/63.png | Bin 0 -> 248 bytes .../src/test/resources/data/mnist/3/68.png | Bin 0 -> 166 bytes .../src/test/resources/data/mnist/3/76.png | Bin 0 -> 250 bytes .../src/test/resources/data/mnist/3/87.png | Bin 0 -> 269 bytes .../src/test/resources/data/mnist/3/90.png | Bin 0 -> 294 bytes .../src/test/resources/data/mnist/3/93.png | Bin 0 -> 238 bytes .../src/test/resources/data/mnist/4/19.png | Bin 0 -> 232 bytes .../src/test/resources/data/mnist/4/24.png | Bin 0 -> 238 bytes .../src/test/resources/data/mnist/4/27.png | Bin 0 -> 254 bytes .../src/test/resources/data/mnist/4/33.png | Bin 0 -> 279 bytes .../src/test/resources/data/mnist/4/4.png | Bin 0 -> 251 bytes .../src/test/resources/data/mnist/4/42.png | Bin 0 -> 254 bytes .../src/test/resources/data/mnist/4/48.png | Bin 0 -> 257 bytes .../src/test/resources/data/mnist/4/49.png | Bin 0 -> 228 bytes .../src/test/resources/data/mnist/4/56.png | Bin 0 -> 264 bytes .../src/test/resources/data/mnist/4/6.png | Bin 0 -> 260 bytes .../src/test/resources/data/mnist/4/65.png | Bin 0 -> 187 bytes .../src/test/resources/data/mnist/4/67.png | Bin 0 -> 269 bytes .../src/test/resources/data/mnist/4/85.png | Bin 0 -> 272 bytes .../src/test/resources/data/mnist/4/95.png | Bin 0 -> 297 bytes .../src/test/resources/data/mnist/5/15.png | Bin 0 -> 252 bytes .../src/test/resources/data/mnist/5/23.png | Bin 0 -> 258 bytes .../src/test/resources/data/mnist/5/45.png | Bin 0 -> 243 bytes .../src/test/resources/data/mnist/5/52.png | Bin 0 -> 284 bytes .../src/test/resources/data/mnist/5/53.png | Bin 0 -> 253 bytes .../src/test/resources/data/mnist/5/59.png | Bin 0 -> 218 bytes .../src/test/resources/data/mnist/5/8.png | Bin 0 -> 263 bytes .../src/test/resources/data/mnist/6/11.png | Bin 0 -> 305 bytes .../src/test/resources/data/mnist/6/21.png | Bin 0 -> 252 bytes .../src/test/resources/data/mnist/6/22.png | Bin 0 -> 198 bytes .../src/test/resources/data/mnist/6/50.png | Bin 0 -> 251 bytes .../src/test/resources/data/mnist/6/54.png | Bin 0 -> 293 bytes .../src/test/resources/data/mnist/6/66.png | Bin 0 -> 297 bytes .../src/test/resources/data/mnist/6/81.png | Bin 0 -> 262 bytes .../src/test/resources/data/mnist/6/88.png | Bin 0 -> 278 bytes .../src/test/resources/data/mnist/6/91.png | Bin 0 -> 261 bytes .../src/test/resources/data/mnist/6/98.png | Bin 0 -> 271 bytes .../src/test/resources/data/mnist/7/0.png | Bin 0 -> 223 bytes .../src/test/resources/data/mnist/7/17.png | Bin 0 -> 245 bytes .../src/test/resources/data/mnist/7/26.png | Bin 0 -> 208 bytes .../src/test/resources/data/mnist/7/34.png | Bin 0 -> 244 bytes .../src/test/resources/data/mnist/7/36.png | Bin 0 -> 248 bytes .../src/test/resources/data/mnist/7/41.png | Bin 0 -> 233 bytes .../src/test/resources/data/mnist/7/60.png | Bin 0 -> 146 bytes .../src/test/resources/data/mnist/7/64.png | Bin 0 -> 268 bytes .../src/test/resources/data/mnist/7/70.png | Bin 0 -> 236 bytes .../src/test/resources/data/mnist/7/75.png | Bin 0 -> 233 bytes .../src/test/resources/data/mnist/7/79.png | Bin 0 -> 246 bytes .../src/test/resources/data/mnist/7/80.png | Bin 0 -> 179 bytes .../src/test/resources/data/mnist/7/83.png | Bin 0 -> 210 bytes .../src/test/resources/data/mnist/7/86.png | Bin 0 -> 225 bytes .../src/test/resources/data/mnist/7/97.png | Bin 0 -> 223 bytes .../src/test/resources/data/mnist/8/110.png | Bin 0 -> 304 bytes .../src/test/resources/data/mnist/8/128.png | Bin 0 -> 309 bytes .../src/test/resources/data/mnist/8/134.png | Bin 0 -> 298 bytes .../src/test/resources/data/mnist/8/146.png | Bin 0 -> 310 bytes .../src/test/resources/data/mnist/8/177.png | Bin 0 -> 251 bytes .../src/test/resources/data/mnist/8/179.png | Bin 0 -> 301 bytes .../src/test/resources/data/mnist/8/61.png | Bin 0 -> 287 bytes .../src/test/resources/data/mnist/8/84.png | Bin 0 -> 332 bytes .../src/test/resources/data/mnist/9/12.png | Bin 0 -> 259 bytes .../src/test/resources/data/mnist/9/16.png | Bin 0 -> 278 bytes .../src/test/resources/data/mnist/9/20.png | Bin 0 -> 268 bytes .../src/test/resources/data/mnist/9/58.png | Bin 0 -> 276 bytes .../src/test/resources/data/mnist/9/62.png | Bin 0 -> 213 bytes .../src/test/resources/data/mnist/9/7.png | Bin 0 -> 257 bytes .../src/test/resources/data/mnist/9/73.png | Bin 0 -> 248 bytes .../src/test/resources/data/mnist/9/78.png | Bin 0 -> 247 bytes .../src/test/resources/data/mnist/9/9.png | Bin 0 -> 299 bytes .../src/test/resources/data/mnist/9/92.png | Bin 0 -> 251 bytes .../src/test/resources/data/mnist/9/99.png | Bin 0 -> 270 bytes .../camel-djl/src/test/resources/log4j2.properties | 7 + .../test/resources/models/mnist/mlp-0007.params | Bin 0 -> 438209 bytes .../src/test/resources/models/mnist/synset.txt | 10 + components/pom.xml | 6 +- core/camel-allcomponents/pom.xml | 4 + parent/pom.xml | 5 + 131 files changed, 1255 insertions(+), 3 deletions(-) diff --git a/bom/camel-bom/pom.xml b/bom/camel-bom/pom.xml index 3879e1b..93cc084 100644 --- a/bom/camel-bom/pom.xml +++ b/bom/camel-bom/pom.xml @@ -614,6 +614,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-djl</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-dns</artifactId> <version>${project.version}</version> </dependency> diff --git a/components/camel-djl/pom.xml b/components/camel-djl/pom.xml new file mode 100644 index 0000000..45dd471 --- /dev/null +++ b/components/camel-djl/pom.xml @@ -0,0 +1,174 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <artifactId>components</artifactId> + <groupId>org.apache.camel</groupId> + <version>3.2.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-djl</artifactId> + <packaging>jar</packaging> + <name>Camel :: Deep Java Library</name> + <description>Camel Deep Java Library support</description> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <djl.version>0.4.0</djl.version> + </properties> + + <dependencyManagement> + <dependencies> + <!-- Camel BOM --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bom</artifactId> + <version>3.1.0</version> + <scope>import</scope> + <type>pom</type> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + + <!-- camel --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-support</artifactId> + </dependency> + + <!-- DJL --> + <dependency> + <groupId>ai.djl</groupId> + <artifactId>api</artifactId> + <version>${djl.version}</version> + </dependency> + <dependency> + <groupId>ai.djl</groupId> + <artifactId>model-zoo</artifactId> + <version>${djl.version}</version> + </dependency> + + <!-- MxNet Engine --> + <dependency> + <groupId>ai.djl.mxnet</groupId> + <artifactId>mxnet-model-zoo</artifactId> + <version>${djl.version}</version> + </dependency> + <dependency> + <groupId>ai.djl.mxnet</groupId> + <artifactId>mxnet-engine</artifactId> + <version>${djl.version}</version> + </dependency> + <dependency> + <groupId>ai.djl.mxnet</groupId> + <artifactId>mxnet-native-auto</artifactId> + <version>1.6.0</version> + <scope>runtime</scope> + </dependency> + + <!-- logging --> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <version>2.13.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>2.13.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <version>2.13.0</version> + <scope>test</scope> + </dependency> + + <!-- testing --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>ai.djl</groupId> + <artifactId>basicdataset</artifactId> + <version>${djl.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <defaultGoal>install</defaultGoal> + + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.1</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <version>3.1.0</version> + <configuration> + <encoding>UTF-8</encoding> + </configuration> + </plugin> + + <!-- generate components meta-data --> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-package-maven-plugin</artifactId> + <version>3.1.0</version> + <executions> + <execution> + <id>generate</id> + <goals> + <goal>generate-component</goal> + </goals> + <phase>process-classes</phase> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <phase>initialize</phase> + <goals> + <goal>add-source</goal> + <goal>add-resource</goal> + </goals> + <configuration> + <sources> + <source>src/generated/java</source> + </sources> + <resources> + <resource> + <directory>src/generated/resources</directory> + </resource> + </resources> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> diff --git a/components/camel-djl/src/generated/java/org/apache/camel/component/djl/DJLComponentConfigurer.java b/components/camel-djl/src/generated/java/org/apache/camel/component/djl/DJLComponentConfigurer.java new file mode 100644 index 0000000..57673b3 --- /dev/null +++ b/components/camel-djl/src/generated/java/org/apache/camel/component/djl/DJLComponentConfigurer.java @@ -0,0 +1,27 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.component.djl; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.support.component.PropertyConfigurerSupport; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@SuppressWarnings("unchecked") +public class DJLComponentConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + DJLComponent target = (DJLComponent) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "lazystartproducer": + case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; + case "basicpropertybinding": + case "basicPropertyBinding": target.setBasicPropertyBinding(property(camelContext, boolean.class, value)); return true; + default: return false; + } + } + +} + diff --git a/components/camel-djl/src/generated/java/org/apache/camel/component/djl/DJLEndpointConfigurer.java b/components/camel-djl/src/generated/java/org/apache/camel/component/djl/DJLEndpointConfigurer.java new file mode 100644 index 0000000..c084797 --- /dev/null +++ b/components/camel-djl/src/generated/java/org/apache/camel/component/djl/DJLEndpointConfigurer.java @@ -0,0 +1,32 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.component.djl; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.support.component.PropertyConfigurerSupport; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@SuppressWarnings("unchecked") +public class DJLEndpointConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + DJLEndpoint target = (DJLEndpoint) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "artifactid": + case "artifactId": target.setArtifactId(property(camelContext, java.lang.String.class, value)); return true; + case "lazystartproducer": + case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; + case "model": target.setModel(property(camelContext, java.lang.String.class, value)); return true; + case "translator": target.setTranslator(property(camelContext, java.lang.String.class, value)); return true; + case "basicpropertybinding": + case "basicPropertyBinding": target.setBasicPropertyBinding(property(camelContext, boolean.class, value)); return true; + case "synchronous": target.setSynchronous(property(camelContext, boolean.class, value)); return true; + default: return false; + } + } + +} + diff --git a/components/camel-djl/src/generated/resources/META-INF/services/org/apache/camel/component.properties b/components/camel-djl/src/generated/resources/META-INF/services/org/apache/camel/component.properties new file mode 100644 index 0000000..4846236 --- /dev/null +++ b/components/camel-djl/src/generated/resources/META-INF/services/org/apache/camel/component.properties @@ -0,0 +1,7 @@ +# Generated by camel build tools - do NOT edit this file! +components=djl +groupId=org.apache.camel +artifactId=camel-djl +version=3.2.0-SNAPSHOT +projectName=Camel Deep Java Library Component +projectDescription=Camel Components diff --git a/components/camel-djl/src/generated/resources/META-INF/services/org/apache/camel/component/djl b/components/camel-djl/src/generated/resources/META-INF/services/org/apache/camel/component/djl new file mode 100644 index 0000000..cc722e4 --- /dev/null +++ b/components/camel-djl/src/generated/resources/META-INF/services/org/apache/camel/component/djl @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.component.djl.DJLComponent diff --git a/components/camel-djl/src/generated/resources/META-INF/services/org/apache/camel/configurer/djl-component b/components/camel-djl/src/generated/resources/META-INF/services/org/apache/camel/configurer/djl-component new file mode 100644 index 0000000..194b97e --- /dev/null +++ b/components/camel-djl/src/generated/resources/META-INF/services/org/apache/camel/configurer/djl-component @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.component.djl.DJLComponentConfigurer diff --git a/components/camel-djl/src/generated/resources/META-INF/services/org/apache/camel/configurer/djl-endpoint b/components/camel-djl/src/generated/resources/META-INF/services/org/apache/camel/configurer/djl-endpoint new file mode 100644 index 0000000..6c8a289 --- /dev/null +++ b/components/camel-djl/src/generated/resources/META-INF/services/org/apache/camel/configurer/djl-endpoint @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.component.djl.DJLEndpointConfigurer diff --git a/components/camel-djl/src/generated/resources/org/apache/camel/component/djl/djl.json b/components/camel-djl/src/generated/resources/org/apache/camel/component/djl/djl.json new file mode 100644 index 0000000..545ba21 --- /dev/null +++ b/components/camel-djl/src/generated/resources/org/apache/camel/component/djl/djl.json @@ -0,0 +1,34 @@ +{ + "component": { + "kind": "component", + "scheme": "djl", + "extendsScheme": "", + "syntax": "djl:application", + "title": "DJL", + "description": "Represents a DJL endpoint.", + "label": "djl", + "deprecated": false, + "async": false, + "consumerOnly": false, + "producerOnly": true, + "lenientProperties": false, + "javaType": "org.apache.camel.component.djl.DJLComponent", + "firstVersion": "3.2.0", + "groupId": "org.apache.camel", + "artifactId": "camel-djl", + "version": "3.2.0-SNAPSHOT" + }, + "componentProperties": { + "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the r [...] + "basicPropertyBinding": { "kind": "property", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" } + }, + "properties": { + "application": { "kind": "path", "displayName": "Application", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "secret": false, "description": "Application name" }, + "artifactId": { "kind": "parameter", "displayName": "Artifact Id", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "secret": false, "description": "Model Artifact" }, + "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the [...] + "model": { "kind": "parameter", "displayName": "Model", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "secret": false, "description": "Model" }, + "translator": { "kind": "parameter", "displayName": "Translator", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "secret": false, "description": "Translator" }, + "basicPropertyBinding": { "kind": "parameter", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" }, + "synchronous": { "kind": "parameter", "displayName": "Synchronous", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": "false", "description": "Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported)." } + } +} diff --git a/components/camel-djl/src/main/docs/djl-component.adoc b/components/camel-djl/src/main/docs/djl-component.adoc new file mode 100644 index 0000000..d99e703 --- /dev/null +++ b/components/camel-djl/src/main/docs/djl-component.adoc @@ -0,0 +1,203 @@ +[[djl-component]] += Deep Java Library Component + +*Since Camel 3.2* + +// HEADER START +*Only producer is supported* +// HEADER END + +The *Deep Java Library* component is used to infer Deep Learning models from message exchanges data. +This component uses https://djl.ai/[Deep Java Library] as underlying library. + +In order to use the DJL component, Maven users will need to add the +following dependency to their `pom.xml`: + +*pom.xml* + +[source,xml] +---- +<dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-djl</artifactId> + <version>x.x.x</version> + <!-- use the same version as your Camel core version --> +</dependency> +---- + +The DJL component only supports producer endpoints. + +// endpoint options: START +The DJL endpoint is configured using URI syntax: + +---- +djl:application +---- + +with the following path and query parameters: + +=== Path Parameters (1 parameters): + +[width="100%",cols="2,5,^1,2",options="header"] +|=== +| Name | Description | Default | Type +| *application* | *Required* Common deep learning application type. The value can be one of: +`cv/image_classification`, +`cv/object_detection`, +`cv/semantic_segmentation`, +`cv/instance_segmentation`, +`cv/pose_estimation`, +`cv/image_classification`, +`cv/action_recognition`, +`nlp/question_answer`, +`nlp/text_classification` + +| | String +|=== + +=== Query Parameters (3 parameters): + + +[width="100%",cols="2,5,^1,2",options="header"] +|=== +| Name | Description | Default | Type +| *artifactId* (producer) | The artifact id identifies Zoo inference model | | String +| *model* (producer) | Custom Deep Learning Model bean id. Bean should implement ai.djl.Model | | String +| *translator* (producer) | Custom Translator for pre-processing and postprocessing bean id. Bean should implement ai.djl.translate.Translator | | String +|=== +// endpoint options: END + + +=== Model Zoo + +The following table contains supported models in the model zoo: + +[width="100%",cols="1,3,5,3,5,5",options="header"] +|=== +| CV | Image Classification | Resnet image classification | `cv/image_classification` | `ai.djl.zoo:resnet:0.0.1` | {layers=50, flavor=v1, dataset=cifar10} +| CV | Image Classification | MLP image classification | `cv/image_classification` | `ai.djl.zoo:mlp:0.0.2` | {dataset=mnist} +| CV | Image Classification | MLP image classification | `cv/image_classification` | `ai.djl.mxnet:mlp:0.0.1` | {dataset=mnist} +| CV | Image Classification | Resnet image classification | `cv/image_classification` | `ai.djl.mxnet:resnet:0.0.1` | {layers=18, flavor=v1, dataset=imagenet} +| CV | Image Classification | Resnet image classification | `cv/image_classification` | `ai.djl.mxnet:resnet:0.0.1` | {layers=50, flavor=v2, dataset=imagenet} +| CV | Image Classification | Resnet image classification | `cv/image_classification` | `ai.djl.mxnet:resnet:0.0.1` | {layers=152, flavor=v1d, dataset=imagenet} +| CV | Image Classification | Resnet image classification | `cv/image_classification` | `ai.djl.mxnet:resnet:0.0.1` | {layers=50, flavor=v1, dataset=cifar10} +| CV | Image Classification | Resnext image classification | `cv/image_classification` | `ai.djl.mxnet:resnext:0.0.1` | {layers=101, flavor=64x4d, dataset=imagenet} +| CV | Image Classification | Senet image classification | `cv/image_classification` | `ai.djl.mxnet:senet:0.0.1` | {layers=154, dataset=imagenet} +| CV | Image Classification | Senet and Resnext image classification | `cv/image_classification` | `ai.djl.mxnet:se_resnext:0.0.1` | {layers=101, flavor=32x4d, dataset=imagenet} +| CV | Image Classification | Senet and Resnext image classification | `cv/image_classification` | `ai.djl.mxnet:se_resnext:0.0.1` | {layers=101, flavor=64x4d, dataset=imagenet} +| CV | Image Classification | Squeezenet image classification | `cv/image_classification` | `ai.djl.mxnet:squeezenet:0.0.1` | {flavor=1.0, dataset=imagenet} +| CV | Object Detection | Single Shot Detection for Object Detection | `cv/object_detection` | `ai.djl.zoo:ssd:0.0.1` | {flavor=tiny, dataset=pikachu} +| CV | Object Detection | Single-shot object detection | `cv/object_detection` | `ai.djl.mxnet:ssd:0.0.1` | {size=512, backbone=resnet50, flavor=v1, dataset=voc} +| CV | Object Detection | Single-shot object detection | `cv/object_detection` | `ai.djl.mxnet:ssd:0.0.1` | {size=512, backbone=vgg16, flavor=atrous, dataset=coco} +| CV | Object Detection | Single-shot object detection | `cv/object_detection` | `ai.djl.mxnet:ssd:0.0.1` | {size=512, backbone=mobilenet1.0, dataset=voc} +| CV | Object Detection | Single-shot object detection | `cv/object_detection` | `ai.djl.mxnet:ssd:0.0.1` | {size=300, backbone=vgg16, flavor=atrous, dataset=voc} +|=== + + +=== DJL Engine implementation + +Because DJL is deep learning framework agnostic, you don't have to make a choice between frameworks when creating your projects. +You can switch frameworks at any point. +To ensure the best performance, DJL also provides automatic CPU/GPU choice based on hardware configuration. + +==== MxNet engine + +You can pull the MXNet engine from the central Maven repository by including the following dependency: + +[source,xml] +---- +<dependency> + <groupId>ai.djl.mxnet</groupId> + <artifactId>mxnet-engine</artifactId> + <version>0.4.0</version> + <scope>runtime</scope> +</dependency> +---- + +DJL offers an automatic option that will download the jars the first time you run DJL. +It will automatically determine the appropriate jars for your system based on the platform and GPU support. + +[source,xml] +---- + <dependency> + <groupId>ai.djl.mxnet</groupId> + <artifactId>mxnet-native-auto</artifactId> + <version>1.6.0</version> + <scope>runtime</scope> + </dependency> +---- + +More information about https://github.com/awslabs/djl/blob/master/mxnet/mxnet-engine/README.md#installation[MxNet engine installation] + +==== PyTorch engine + +You can pull the PyTorch engine from the central Maven repository by including the following dependency: + +[source,xml] +---- +<dependency> + <groupId>ai.djl.mxnet</groupId> + <artifactId>pytorch-engine</artifactId> + <version>0.4.0</version> + <scope>runtime</scope> +</dependency> +---- + +DJL offers an automatic option that will download the jars the first time you run DJL. +It will automatically determine the appropriate jars for your system based on the platform and GPU support. + +[source,xml] +---- + <dependency> + <groupId>ai.djl.mxnet</groupId> + <artifactId>pytorch-native-auto</artifactId> + <version>1.4.0</version> + <scope>runtime</scope> + </dependency> +---- + +More information about https://github.com/awslabs/djl/blob/master/pytorch/pytorch-engine/README.md#installation[PyTorch engine installation] + +==== Tensorflow engine + +Right now, the TensorFlow Engine is still experimental. + + +=== Examples + +==== MNIST image classification from file +[source,java] +---- +from("file:/data/mnist/0/10.png") + .to("djl:cv/image_classification?artifactId=ai.djl.mxnet:mlp:0.0.1"); +---- + +==== Object detection +[source,java] +---- +from("file:/data/mnist/0/10.png") + .to("djl:cv/image_classification?artifactId=ai.djl.mxnet:mlp:0.0.1"); +---- + +==== Custom deep learning model +[source,java] +---- +// create deep learning model +Model model = Model.newInstance(); +model.setBlock(new Mlp(28 * 28, 10, new int[]{128, 64})); +model.load(Paths.get(MODEL_DIR), MODEL_NAME); + +// create translator for pre-processing and postprocessing +ImageClassificationTranslator.Builder builder = ImageClassificationTranslator.builder(); +builder.setSynsetArtifactName("synset.txt"); +builder.setPipeline(new Pipeline(new ToTensor())); +builder.optApplySoftmax(true); +ImageClassificationTranslator translator = new ImageClassificationTranslator(builder); + +// Bind model and translator beans +context.getRegistry().bind("MyModel", model); +context.getRegistry().bind("MyTranslator", translator); + +from("file:/data/mnist/0/10.png") + .to("djl:cv/image_classification?model=MyModel&translator=MyTranslator"); +---- \ No newline at end of file diff --git a/components/camel-djl/src/main/java/org/apache/camel/component/djl/DJLComponent.java b/components/camel-djl/src/main/java/org/apache/camel/component/djl/DJLComponent.java new file mode 100644 index 0000000..3273c93 --- /dev/null +++ b/components/camel-djl/src/main/java/org/apache/camel/component/djl/DJLComponent.java @@ -0,0 +1,25 @@ +package org.apache.camel.component.djl; + +import java.util.Map; + +import org.apache.camel.Endpoint; + +import org.apache.camel.spi.annotations.Component; +import org.apache.camel.support.DefaultComponent; +import org.apache.camel.util.ObjectHelper; + +/** + * Represents the component that manages {@link DJLEndpoint}. + */ +@Component("djl") +public class DJLComponent extends DefaultComponent { + + protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { + if (ObjectHelper.isEmpty(remaining)) { + throw new IllegalArgumentException("Application must be configured on endpoint using syntax djl:application"); + } + Endpoint endpoint = new DJLEndpoint(uri, this, remaining); + setProperties(endpoint, parameters); + return endpoint; + } +} diff --git a/components/camel-djl/src/main/java/org/apache/camel/component/djl/DJLEndpoint.java b/components/camel-djl/src/main/java/org/apache/camel/component/djl/DJLEndpoint.java new file mode 100644 index 0000000..e905936 --- /dev/null +++ b/components/camel-djl/src/main/java/org/apache/camel/component/djl/DJLEndpoint.java @@ -0,0 +1,82 @@ +package org.apache.camel.component.djl; + +import ai.djl.Application; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; +import org.apache.camel.support.DefaultEndpoint; + +/** + * Represents a DJL endpoint. + */ +@UriEndpoint(firstVersion = "3.2.0", scheme = "djl", title = "DJL", syntax = "djl:application", label = "djl", producerOnly = true) +public class DJLEndpoint extends DefaultEndpoint { + + @UriPath @Metadata(required = true, description = "Application name") + private String application; + + @Metadata(required = false) + @UriParam(label = "producer", description = "Model Artifact") + private String artifactId; + + @Metadata(required = false) + @UriParam(label = "producer", description = "Model") + private String model; + + @Metadata(required = false) + @UriParam(label = "producer", description = "Translator") + private String translator; + + public DJLEndpoint(String uri, DJLComponent component, String application) { + super(uri, component); + this.application = application; + } + + public Producer createProducer() throws Exception { + return new DJLProducer(this); + } + + public Consumer createConsumer(Processor processor) throws Exception { + throw new UnsupportedOperationException("Consumer not supported"); + } + + public boolean isSingleton() { + return true; + } + + public String getApplication() { + return application; + } + + public void setApplication(String application) { + this.application = application; + } + + public String getArtifactId() { + return artifactId; + } + + public void setArtifactId(String artifactId) { + this.artifactId = artifactId; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public String getTranslator() { + return translator; + } + + public void setTranslator(String translator) { + this.translator = translator; + } +} diff --git a/components/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java b/components/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java new file mode 100644 index 0000000..fec3523 --- /dev/null +++ b/components/camel-djl/src/main/java/org/apache/camel/component/djl/DJLProducer.java @@ -0,0 +1,31 @@ +package org.apache.camel.component.djl; + +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; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The DJL producer. + */ +public class DJLProducer extends DefaultProducer { + private static final Logger LOG = LoggerFactory.getLogger(DJLProducer.class); + private DJLEndpoint endpoint; + private AbstractPredictor abstractPredictor; + + public DJLProducer(DJLEndpoint endpoint) throws Exception { + super(endpoint); + this.endpoint = 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 void process(Exchange exchange) throws Exception { + this.abstractPredictor.process(exchange); + } +} diff --git a/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/AbstractPredictor.java b/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/AbstractPredictor.java new file mode 100644 index 0000000..9d2b2b5 --- /dev/null +++ b/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/AbstractPredictor.java @@ -0,0 +1,9 @@ +package org.apache.camel.component.djl.model; + +import org.apache.camel.Exchange; + +public abstract class AbstractPredictor { + + public abstract void process(Exchange exchange) throws Exception; + +} diff --git a/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/CustomImageClassificationPredictor.java b/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/CustomImageClassificationPredictor.java new file mode 100644 index 0000000..56cc9d9 --- /dev/null +++ b/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/CustomImageClassificationPredictor.java @@ -0,0 +1,82 @@ +package org.apache.camel.component.djl.model; + +import ai.djl.Model; +import ai.djl.inference.Predictor; +import ai.djl.modality.Classifications; +import ai.djl.translate.TranslateException; +import ai.djl.translate.Translator; +import org.apache.camel.Exchange; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class CustomImageClassificationPredictor extends AbstractPredictor { + private static final Logger LOG = LoggerFactory.getLogger(CustomImageClassificationPredictor.class); + + private String modelName; + private String translatorName; + + public CustomImageClassificationPredictor(String modelName, String translatorName) { + this.modelName = modelName; + this.translatorName = translatorName; + } + + @Override + public void process(Exchange exchange) throws Exception { + Model model = exchange.getContext().getRegistry().lookupByNameAndType(modelName, Model.class); + Translator translator = exchange.getContext().getRegistry().lookupByNameAndType(translatorName, Translator.class); + + if (exchange.getIn().getBody() instanceof byte[]) { + byte[] bytes = exchange.getIn().getBody(byte[].class); + Map<String, Float> result = classify(model, translator, new ByteArrayInputStream(bytes)); + exchange.getIn().setBody(result); + } else if (exchange.getIn().getBody() instanceof File) { + Map<String, Float> result = classify(model, translator, exchange.getIn().getBody(File.class)); + exchange.getIn().setBody(result); + } else if (exchange.getIn().getBody() instanceof InputStream) { + Map<String, Float> result = classify(model, translator, exchange.getIn().getBody(InputStream.class)); + exchange.getIn().setBody(result); + } + } + + private Map<String, Float> classify(Model model, Translator translator, File input) throws Exception { + try { + return classify(model, translator, ImageIO.read(input)); + } catch (IOException e) { + LOG.error("Couldn't transform input into a BufferedImage"); + throw new Exception("Couldn't transform input into a BufferedImage", e); + } + } + + private Map<String, Float> classify(Model model, Translator translator, InputStream input) throws Exception { + try { + return classify(model, translator, ImageIO.read(input)); + } catch (IOException e) { + LOG.error("Couldn't transform input into a BufferedImage"); + throw new Exception("Couldn't transform input into a BufferedImage", e); + } + } + + private Map<String, Float> classify(Model model, Translator translator, BufferedImage input) throws Exception { + try (Predictor<BufferedImage, Classifications> predictor = model.newPredictor(translator)) { + Classifications classifications = predictor.predict(input); + List<Classifications.Classification> list = classifications.items(); + return list.stream() + .collect( + Collectors.toMap( + Classifications.Classification::getClassName, + x -> (float) x.getProbability())); + } catch (TranslateException e) { + throw new Exception("Failed to process output", e); + } + } +} diff --git a/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/CustomObjectDetectionPredictor.java b/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/CustomObjectDetectionPredictor.java new file mode 100644 index 0000000..392d208 --- /dev/null +++ b/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/CustomObjectDetectionPredictor.java @@ -0,0 +1,75 @@ +package org.apache.camel.component.djl.model; + +import ai.djl.Model; +import ai.djl.inference.Predictor; +import ai.djl.modality.cv.output.DetectedObjects; +import ai.djl.translate.TranslateException; +import ai.djl.translate.Translator; +import org.apache.camel.Exchange; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +public class CustomObjectDetectionPredictor extends AbstractPredictor { + + private static final Logger LOG = LoggerFactory.getLogger(CustomObjectDetectionPredictor.class); + + private String modelName; + private String translatorName; + + public CustomObjectDetectionPredictor(String modelName, String translatorName) { + this.modelName = modelName; + this.translatorName = translatorName; + } + + @Override + public void process(Exchange exchange) throws Exception { + Model model = exchange.getContext().getRegistry().lookupByNameAndType(modelName, Model.class); + Translator translator = exchange.getContext().getRegistry().lookupByNameAndType(translatorName, Translator.class); + + if (exchange.getIn().getBody() instanceof byte[]){ + byte[] bytes = exchange.getIn().getBody(byte[].class); + DetectedObjects result = classify(model, translator, new ByteArrayInputStream(bytes)); + exchange.getIn().setBody(result); + } else if (exchange.getIn().getBody() instanceof File){ + DetectedObjects result = classify(model, translator, exchange.getIn().getBody(File.class)); + exchange.getIn().setBody(result); + } else if (exchange.getIn().getBody() instanceof InputStream){ + DetectedObjects result = classify(model, translator, exchange.getIn().getBody(InputStream.class)); + exchange.getIn().setBody(result); + } + } + + public DetectedObjects classify(Model model, Translator translator,BufferedImage input) throws Exception { + try (Predictor<BufferedImage, DetectedObjects> predictor = model.newPredictor(translator)) { + DetectedObjects detectedObjects = predictor.predict(input); + return detectedObjects; + } catch (TranslateException e) { + throw new Exception("Failed to process output", e); + } + } + + public DetectedObjects classify(Model model, Translator translator,File input) throws Exception { + try { + return classify(model, translator, ImageIO.read(input)); + } catch (IOException e) { + LOG.error("Couldn't transform input into a BufferedImage"); + throw new Exception("Couldn't transform input into a BufferedImage", e); + } + } + + public DetectedObjects classify(Model model, Translator translator,InputStream input) throws Exception { + try { + return classify(model, translator, ImageIO.read(input)); + } catch (IOException e) { + LOG.error("Couldn't transform input into a BufferedImage"); + throw new Exception("Couldn't transform input into a BufferedImage", e); + } + } +} diff --git a/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/ModelPredictorProducer.java b/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/ModelPredictorProducer.java new file mode 100644 index 0000000..61849b0 --- /dev/null +++ b/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/ModelPredictorProducer.java @@ -0,0 +1,27 @@ +package org.apache.camel.component.djl.model; + +import static ai.djl.Application.CV.IMAGE_CLASSIFICATION; +import static ai.djl.Application.CV.OBJECT_DETECTION; + +public class ModelPredictorProducer { + + public static AbstractPredictor getZooPredictor(String applicationPath, String artifactId) throws Exception { + if (applicationPath.equals(IMAGE_CLASSIFICATION.getPath())){ + return new ZooImageClassificationPredictor(artifactId); + } else if (applicationPath.equals(OBJECT_DETECTION.getPath())){ + return new ZooObjectDetectionPredictor(artifactId); + } else { + throw new RuntimeException("Application not supported "); + } + } + + public static AbstractPredictor getCustomPredictor(String applicationPath, String model, String translator) { + if (applicationPath.equals(IMAGE_CLASSIFICATION.getPath())){ + return new CustomImageClassificationPredictor(model, translator); + } else if (applicationPath.equals(OBJECT_DETECTION.getPath())){ + return new CustomObjectDetectionPredictor(model, translator); + } else { + throw new RuntimeException("Application not supported "); + } + } +} diff --git a/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/ZooImageClassificationPredictor.java b/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/ZooImageClassificationPredictor.java new file mode 100644 index 0000000..3d4d789 --- /dev/null +++ b/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/ZooImageClassificationPredictor.java @@ -0,0 +1,87 @@ +package org.apache.camel.component.djl.model; + +import ai.djl.Application; +import ai.djl.inference.Predictor; +import ai.djl.modality.Classifications; +import ai.djl.repository.zoo.Criteria; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class ZooImageClassificationPredictor extends AbstractPredictor { + private static final Logger LOG = LoggerFactory.getLogger(ZooImageClassificationPredictor.class); + + private ZooModel<BufferedImage, Classifications> model; + + public ZooImageClassificationPredictor(String artifactId) throws Exception { + Criteria<BufferedImage, Classifications> criteria = + Criteria.builder() + .optApplication(Application.CV.IMAGE_CLASSIFICATION) + .setTypes(BufferedImage.class, Classifications.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 byte[]){ + byte[] bytes = exchange.getIn().getBody(byte[].class); + Map<String, Float> result = classify(new ByteArrayInputStream(bytes)); + exchange.getIn().setBody(result); + } else if (exchange.getIn().getBody() instanceof File){ + Map<String, Float> result = classify(exchange.getIn().getBody(File.class)); + exchange.getIn().setBody(result); + } else if (exchange.getIn().getBody() instanceof InputStream){ + Map<String, Float> result = classify(exchange.getIn().getBody(InputStream.class)); + exchange.getIn().setBody(result); + } + } + + public Map<String, Float> classify(File input) throws Exception { + try { + return classify(ImageIO.read(input)); + } catch (IOException e) { + LOG.error("Couldn't transform input into a BufferedImage"); + throw new Exception("Couldn't transform input into a BufferedImage", e); + } + } + + public Map<String, Float> classify(InputStream input) throws Exception { + try { + return classify(ImageIO.read(input)); + } catch (IOException e) { + LOG.error("Couldn't transform input into a BufferedImage"); + throw new Exception("Couldn't transform input into a BufferedImage", e); + } + } + + public Map<String, Float> classify(BufferedImage input) throws Exception { + try (Predictor<BufferedImage, Classifications> predictor = model.newPredictor()) { + Classifications classifications = predictor.predict(input); + List<Classifications.Classification> list = classifications.items(); + return list.stream() + .collect( + Collectors.toMap( + Classifications.Classification::getClassName, + x -> (float) x.getProbability())); + } catch (TranslateException e) { + throw new Exception("Failed to process output", e); + } + } +} diff --git a/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/ZooObjectDetectionPredictor.java b/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/ZooObjectDetectionPredictor.java new file mode 100644 index 0000000..5772cea --- /dev/null +++ b/components/camel-djl/src/main/java/org/apache/camel/component/djl/model/ZooObjectDetectionPredictor.java @@ -0,0 +1,85 @@ +package org.apache.camel.component.djl.model; + +import ai.djl.Application; +import ai.djl.inference.Predictor; +import ai.djl.modality.cv.ImageVisualization; +import ai.djl.modality.cv.output.DetectedObjects; +import ai.djl.repository.zoo.Criteria; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class ZooObjectDetectionPredictor extends AbstractPredictor { + + private static final Logger LOG = LoggerFactory.getLogger(ZooObjectDetectionPredictor.class); + + private ZooModel<BufferedImage, DetectedObjects> model; + + public ZooObjectDetectionPredictor(String artifactId) throws Exception { + Criteria<BufferedImage, DetectedObjects> criteria = + Criteria.builder() + .optApplication(Application.CV.OBJECT_DETECTION) + .setTypes(BufferedImage.class, DetectedObjects.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 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); + } + } + + public DetectedObjects classify(BufferedImage input) throws Exception { + try (Predictor<BufferedImage, DetectedObjects> predictor = model.newPredictor()) { + DetectedObjects detectedObjects = predictor.predict(input); + return detectedObjects; + } catch (TranslateException e) { + throw new Exception("Failed to process output", e); + } + } + + public DetectedObjects classify(File input) throws Exception { + try { + return classify(ImageIO.read(input)); + } catch (IOException e) { + LOG.error("Couldn't transform input into a BufferedImage"); + throw new Exception("Couldn't transform input into a BufferedImage", e); + } + } + + public DetectedObjects classify(InputStream input) throws Exception { + try { + return classify(ImageIO.read(input)); + } catch (IOException e) { + LOG.error("Couldn't transform input into a BufferedImage"); + throw new Exception("Couldn't transform input into a BufferedImage", e); + } + } +} diff --git a/components/camel-djl/src/main/resources/META-INF/services/org/apache/camel/component/djl b/components/camel-djl/src/main/resources/META-INF/services/org/apache/camel/component/djl new file mode 100644 index 0000000..0694061 --- /dev/null +++ b/components/camel-djl/src/main/resources/META-INF/services/org/apache/camel/component/djl @@ -0,0 +1 @@ +class=org.apache.camel.component.djl.DJLComponent diff --git a/components/camel-djl/src/test/java/org/apache/camel/component/djl/ImageClassificationLocalTest.java b/components/camel-djl/src/test/java/org/apache/camel/component/djl/ImageClassificationLocalTest.java new file mode 100644 index 0000000..a4dc21c --- /dev/null +++ b/components/camel-djl/src/test/java/org/apache/camel/component/djl/ImageClassificationLocalTest.java @@ -0,0 +1,81 @@ +package org.apache.camel.component.djl; + +import ai.djl.MalformedModelException; +import ai.djl.Model; +import ai.djl.basicmodelzoo.basic.Mlp; +import ai.djl.modality.cv.transform.ToTensor; +import ai.djl.modality.cv.translator.ImageClassificationTranslator; +import ai.djl.translate.Pipeline; +import ai.djl.translate.TranslateException; +import ai.djl.translate.Translator; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.Comparator; +import java.util.Map; + +public class ImageClassificationLocalTest extends CamelTestSupport { + private static final Logger LOG = LoggerFactory.getLogger(ImageClassificationLocalTest.class); + + private static final String MODEL_DIR = "src/test/resources/models/mnist"; + private static final String MODEL_NAME = "mlp"; + + @Test + public void testDJL() throws Exception { + LOG.info("Read and load local model"); + loadLocalModel(); + + LOG.info("Starting route to infer"); + context.createProducerTemplate().sendBody("controlbus:route?routeId=infer&action=start", null); + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMinimumMessageCount(98); + mock.await(); + long count = mock.getExchanges().stream().filter(exchange -> exchange.getIn().getBody(Boolean.class)).count(); + assertEquals(98, count); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + from("file:src/test/resources/data/mnist?recursive=true&noop=true") + .routeId("infer").autoStartup(false) + .convertBodyTo(byte[].class) + .to("djl:cv/image_classification?model=MyModel&translator=MyTranslator") + .log("${header.CamelFileName} = ${body}") + .process(exchange -> { + String filename = exchange.getIn().getHeader("CamelFileName", String.class); + Map<String, Float> result = exchange.getIn().getBody(Map.class); + String max = Collections.max(result.entrySet(), Comparator.comparingDouble(Map.Entry::getValue)).getKey(); + exchange.getIn().setBody(filename.startsWith(max)); + }) + .log("${header.CamelFileName} = ${body}") + .to("mock:result"); + } + }; + } + + private void loadLocalModel() throws IOException, MalformedModelException, TranslateException { + // create deep learning model + Model model = Model.newInstance(); + model.setBlock(new Mlp(28 * 28, 10, new int[]{128, 64})); + model.load(Paths.get(MODEL_DIR), MODEL_NAME); + // create translator for pre-processing and postprocessing + ImageClassificationTranslator.Builder builder = ImageClassificationTranslator.builder(); + builder.setSynsetArtifactName("synset.txt"); + builder.setPipeline(new Pipeline(new ToTensor())); + builder.optApplySoftmax(true); + ImageClassificationTranslator translator = new ImageClassificationTranslator(builder); + + // Bind model beans + context.getRegistry().bind("MyModel", model); + context.getRegistry().bind("MyTranslator", translator); + } +} diff --git a/components/camel-djl/src/test/java/org/apache/camel/component/djl/ImageClassificationTest.java b/components/camel-djl/src/test/java/org/apache/camel/component/djl/ImageClassificationTest.java new file mode 100644 index 0000000..fd6b3f3 --- /dev/null +++ b/components/camel-djl/src/test/java/org/apache/camel/component/djl/ImageClassificationTest.java @@ -0,0 +1,30 @@ +package org.apache.camel.component.djl; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class ImageClassificationTest extends CamelTestSupport { + + @Test + public void testDJL() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMinimumMessageCount(98); + mock.await(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + 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.mxnet:mlp:0.0.1") + .log("${header.CamelFileName} = ${body}") + .to("mock:result"); + } + }; + } + +} diff --git a/components/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java b/components/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java new file mode 100644 index 0000000..752a3fa --- /dev/null +++ b/components/camel-djl/src/test/java/org/apache/camel/component/djl/ObjectDetectionTest.java @@ -0,0 +1,30 @@ +package org.apache.camel.component.djl; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class ObjectDetectionTest extends CamelTestSupport { + + @Test + public void testDJL() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMinimumMessageCount(3); + mock.await(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + 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.mxnet:ssd:0.0.1") + .log("${header.CamelFileName} = ${body}") + .to("mock:result"); + } + }; + } + +} diff --git a/components/camel-djl/src/test/java/org/apache/camel/component/djl/training/MnistTraining.java b/components/camel-djl/src/test/java/org/apache/camel/component/djl/training/MnistTraining.java new file mode 100644 index 0000000..9e8d2eb --- /dev/null +++ b/components/camel-djl/src/test/java/org/apache/camel/component/djl/training/MnistTraining.java @@ -0,0 +1,93 @@ +package org.apache.camel.component.djl.training; + +import ai.djl.Device; +import ai.djl.Model; +import ai.djl.basicdataset.Mnist; +import ai.djl.basicmodelzoo.basic.Mlp; +import ai.djl.metric.Metrics; +import ai.djl.ndarray.types.Shape; +import ai.djl.nn.Block; +import ai.djl.training.DefaultTrainingConfig; +import ai.djl.training.Trainer; +import ai.djl.training.dataset.Batch; +import ai.djl.training.dataset.Dataset; +import ai.djl.training.dataset.RandomAccessDataset; +import ai.djl.training.evaluator.Accuracy; +import ai.djl.training.listener.TrainingListener; +import ai.djl.training.loss.Loss; +import ai.djl.training.util.ProgressBar; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.nio.file.Paths; + +// Helper to train mnist model for tests +public class MnistTraining { + private static final Logger LOG = LoggerFactory.getLogger(MnistTraining.class); + + private static final String MODEL_DIR = "src/test/resources/models/mnist"; + private static final String MODEL_NAME = "mlp"; + + + public static void main(String[] args) throws IOException { + // Construct neural network + Block block = new Mlp(Mnist.IMAGE_HEIGHT * Mnist.IMAGE_WIDTH, Mnist.NUM_CLASSES, new int[]{128, 64}); + + try (Model model = Model.newInstance()) { + model.setBlock(block); + + // get training and validation dataset + RandomAccessDataset trainingSet = prepareDataset(Dataset.Usage.TRAIN, 64, Long.MAX_VALUE); + RandomAccessDataset validateSet = prepareDataset(Dataset.Usage.TEST, 64, Long.MAX_VALUE); + + // setup training configuration + DefaultTrainingConfig config = new DefaultTrainingConfig(Loss.softmaxCrossEntropyLoss()) + .addEvaluator(new Accuracy()).optDevices(Device.getDevices(Device.getGpuCount())) + .addTrainingListeners(TrainingListener.Defaults.logging()); + + try (Trainer trainer = model.newTrainer(config)) { + trainer.setMetrics(new Metrics()); + + Shape inputShape = new Shape(1, Mnist.IMAGE_HEIGHT * Mnist.IMAGE_WIDTH); + + // initialize trainer with proper input shape + trainer.initialize(inputShape); + fit(trainer, 10, trainingSet, validateSet, MODEL_DIR, MODEL_NAME); + } + model.save(Paths.get(MODEL_DIR), MODEL_NAME); + } + } + + private static void fit(Trainer trainer, int numEpoch, Dataset trainingSet, Dataset validateSet, String outputDir, String modelName) throws IOException { + for (int epoch = 0; epoch < numEpoch; epoch++) { + for (Batch batch : trainer.iterateDataset(trainingSet)) { + trainer.trainBatch(batch); + trainer.step(); + batch.close(); + } + + if (validateSet != null) { + for (Batch batch : trainer.iterateDataset(validateSet)) { + trainer.validateBatch(batch); + batch.close(); + } + } + // reset training and validation evaluators at end of epoch + trainer.endEpoch(); + // save model at end of each epoch + if (outputDir != null) { + Model model = trainer.getModel(); + model.setProperty("Epoch", String.valueOf(epoch)); + model.save(Paths.get(outputDir), modelName); + } + } + } + + private static RandomAccessDataset prepareDataset(Dataset.Usage usage, int batchSize, long limit) throws IOException { + Mnist mnist = Mnist.builder().optUsage(usage).setSampling(batchSize, true).optLimit(limit).build(); + mnist.prepare(new ProgressBar()); + return mnist; + } + +} diff --git a/components/camel-djl/src/test/resources/data/detect/dog-cat.jpg b/components/camel-djl/src/test/resources/data/detect/dog-cat.jpg new file mode 100644 index 0000000..9149efb Binary files /dev/null and b/components/camel-djl/src/test/resources/data/detect/dog-cat.jpg differ diff --git a/components/camel-djl/src/test/resources/data/detect/dog_bike_car.jpg b/components/camel-djl/src/test/resources/data/detect/dog_bike_car.jpg new file mode 100644 index 0000000..77b0381 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/detect/dog_bike_car.jpg differ diff --git a/components/camel-djl/src/test/resources/data/detect/kitten.jpg b/components/camel-djl/src/test/resources/data/detect/kitten.jpg new file mode 100644 index 0000000..3353026 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/detect/kitten.jpg differ diff --git a/components/camel-djl/src/test/resources/data/mnist/0/10.png b/components/camel-djl/src/test/resources/data/mnist/0/10.png new file mode 100644 index 0000000..a193c47 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/0/10.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/0/13.png b/components/camel-djl/src/test/resources/data/mnist/0/13.png new file mode 100644 index 0000000..f2a97d0 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/0/13.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/0/25.png b/components/camel-djl/src/test/resources/data/mnist/0/25.png new file mode 100644 index 0000000..5a2093d Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/0/25.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/0/28.png b/components/camel-djl/src/test/resources/data/mnist/0/28.png new file mode 100644 index 0000000..6f4e36b Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/0/28.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/0/3.png b/components/camel-djl/src/test/resources/data/mnist/0/3.png new file mode 100644 index 0000000..dd21aaa Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/0/3.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/0/55.png b/components/camel-djl/src/test/resources/data/mnist/0/55.png new file mode 100644 index 0000000..a0a9902 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/0/55.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/0/69.png b/components/camel-djl/src/test/resources/data/mnist/0/69.png new file mode 100644 index 0000000..5873f5a Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/0/69.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/0/71.png b/components/camel-djl/src/test/resources/data/mnist/0/71.png new file mode 100644 index 0000000..9507f14 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/0/71.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/1/14.png b/components/camel-djl/src/test/resources/data/mnist/1/14.png new file mode 100644 index 0000000..ee6d7c4 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/1/14.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/1/2.png b/components/camel-djl/src/test/resources/data/mnist/1/2.png new file mode 100644 index 0000000..765d4e2 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/1/2.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/1/29.png b/components/camel-djl/src/test/resources/data/mnist/1/29.png new file mode 100644 index 0000000..4983303 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/1/29.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/1/31.png b/components/camel-djl/src/test/resources/data/mnist/1/31.png new file mode 100644 index 0000000..9768343 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/1/31.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/1/37.png b/components/camel-djl/src/test/resources/data/mnist/1/37.png new file mode 100644 index 0000000..0c1323d Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/1/37.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/1/39.png b/components/camel-djl/src/test/resources/data/mnist/1/39.png new file mode 100644 index 0000000..4120425 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/1/39.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/1/5.png b/components/camel-djl/src/test/resources/data/mnist/1/5.png new file mode 100644 index 0000000..9470ab1 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/1/5.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/2/1.png b/components/camel-djl/src/test/resources/data/mnist/2/1.png new file mode 100644 index 0000000..bc46413 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/2/1.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/2/35.png b/components/camel-djl/src/test/resources/data/mnist/2/35.png new file mode 100644 index 0000000..24b5d74 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/2/35.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/2/43.png b/components/camel-djl/src/test/resources/data/mnist/2/43.png new file mode 100644 index 0000000..897ad94 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/2/43.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/2/47.png b/components/camel-djl/src/test/resources/data/mnist/2/47.png new file mode 100644 index 0000000..b048cef Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/2/47.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/2/72.png b/components/camel-djl/src/test/resources/data/mnist/2/72.png new file mode 100644 index 0000000..46798e0 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/2/72.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/2/77.png b/components/camel-djl/src/test/resources/data/mnist/2/77.png new file mode 100644 index 0000000..49bdfc8 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/2/77.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/2/82.png b/components/camel-djl/src/test/resources/data/mnist/2/82.png new file mode 100644 index 0000000..73f36d0 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/2/82.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/3/18.png b/components/camel-djl/src/test/resources/data/mnist/3/18.png new file mode 100644 index 0000000..c19152a Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/3/18.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/3/30.png b/components/camel-djl/src/test/resources/data/mnist/3/30.png new file mode 100644 index 0000000..492878f Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/3/30.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/3/32.png b/components/camel-djl/src/test/resources/data/mnist/3/32.png new file mode 100644 index 0000000..33b66f2 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/3/32.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/3/44.png b/components/camel-djl/src/test/resources/data/mnist/3/44.png new file mode 100644 index 0000000..50d7c2d Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/3/44.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/3/51.png b/components/camel-djl/src/test/resources/data/mnist/3/51.png new file mode 100644 index 0000000..bfe6b62 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/3/51.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/3/63.png b/components/camel-djl/src/test/resources/data/mnist/3/63.png new file mode 100644 index 0000000..7fe0630 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/3/63.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/3/68.png b/components/camel-djl/src/test/resources/data/mnist/3/68.png new file mode 100644 index 0000000..184cfda Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/3/68.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/3/76.png b/components/camel-djl/src/test/resources/data/mnist/3/76.png new file mode 100644 index 0000000..4532ccc Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/3/76.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/3/87.png b/components/camel-djl/src/test/resources/data/mnist/3/87.png new file mode 100644 index 0000000..ec37e36 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/3/87.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/3/90.png b/components/camel-djl/src/test/resources/data/mnist/3/90.png new file mode 100644 index 0000000..900e078 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/3/90.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/3/93.png b/components/camel-djl/src/test/resources/data/mnist/3/93.png new file mode 100644 index 0000000..b9ccbd5 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/3/93.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/4/19.png b/components/camel-djl/src/test/resources/data/mnist/4/19.png new file mode 100644 index 0000000..1091241 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/4/19.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/4/24.png b/components/camel-djl/src/test/resources/data/mnist/4/24.png new file mode 100644 index 0000000..04d7537 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/4/24.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/4/27.png b/components/camel-djl/src/test/resources/data/mnist/4/27.png new file mode 100644 index 0000000..c33937a Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/4/27.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/4/33.png b/components/camel-djl/src/test/resources/data/mnist/4/33.png new file mode 100644 index 0000000..09bb9d3 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/4/33.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/4/4.png b/components/camel-djl/src/test/resources/data/mnist/4/4.png new file mode 100644 index 0000000..da45e7a Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/4/4.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/4/42.png b/components/camel-djl/src/test/resources/data/mnist/4/42.png new file mode 100644 index 0000000..fbb6520 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/4/42.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/4/48.png b/components/camel-djl/src/test/resources/data/mnist/4/48.png new file mode 100644 index 0000000..aec5ad4 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/4/48.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/4/49.png b/components/camel-djl/src/test/resources/data/mnist/4/49.png new file mode 100644 index 0000000..a9b43d0 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/4/49.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/4/56.png b/components/camel-djl/src/test/resources/data/mnist/4/56.png new file mode 100644 index 0000000..9c0129f Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/4/56.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/4/6.png b/components/camel-djl/src/test/resources/data/mnist/4/6.png new file mode 100644 index 0000000..84d4622 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/4/6.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/4/65.png b/components/camel-djl/src/test/resources/data/mnist/4/65.png new file mode 100644 index 0000000..de8e6f8 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/4/65.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/4/67.png b/components/camel-djl/src/test/resources/data/mnist/4/67.png new file mode 100644 index 0000000..1727b05 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/4/67.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/4/85.png b/components/camel-djl/src/test/resources/data/mnist/4/85.png new file mode 100644 index 0000000..aa49a51 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/4/85.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/4/95.png b/components/camel-djl/src/test/resources/data/mnist/4/95.png new file mode 100644 index 0000000..8c34738 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/4/95.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/5/15.png b/components/camel-djl/src/test/resources/data/mnist/5/15.png new file mode 100644 index 0000000..649a54e Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/5/15.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/5/23.png b/components/camel-djl/src/test/resources/data/mnist/5/23.png new file mode 100644 index 0000000..58546c1 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/5/23.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/5/45.png b/components/camel-djl/src/test/resources/data/mnist/5/45.png new file mode 100644 index 0000000..7272712 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/5/45.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/5/52.png b/components/camel-djl/src/test/resources/data/mnist/5/52.png new file mode 100644 index 0000000..0cdeb5c Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/5/52.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/5/53.png b/components/camel-djl/src/test/resources/data/mnist/5/53.png new file mode 100644 index 0000000..3117ec7 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/5/53.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/5/59.png b/components/camel-djl/src/test/resources/data/mnist/5/59.png new file mode 100644 index 0000000..0c784e0 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/5/59.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/5/8.png b/components/camel-djl/src/test/resources/data/mnist/5/8.png new file mode 100644 index 0000000..f2daf23 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/5/8.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/6/11.png b/components/camel-djl/src/test/resources/data/mnist/6/11.png new file mode 100644 index 0000000..ef011c4 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/6/11.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/6/21.png b/components/camel-djl/src/test/resources/data/mnist/6/21.png new file mode 100644 index 0000000..250ecb9 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/6/21.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/6/22.png b/components/camel-djl/src/test/resources/data/mnist/6/22.png new file mode 100644 index 0000000..2a5fd92 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/6/22.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/6/50.png b/components/camel-djl/src/test/resources/data/mnist/6/50.png new file mode 100644 index 0000000..8345d75 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/6/50.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/6/54.png b/components/camel-djl/src/test/resources/data/mnist/6/54.png new file mode 100644 index 0000000..49f0212 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/6/54.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/6/66.png b/components/camel-djl/src/test/resources/data/mnist/6/66.png new file mode 100644 index 0000000..afe2765 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/6/66.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/6/81.png b/components/camel-djl/src/test/resources/data/mnist/6/81.png new file mode 100644 index 0000000..28f8a95 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/6/81.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/6/88.png b/components/camel-djl/src/test/resources/data/mnist/6/88.png new file mode 100644 index 0000000..4ebc2b3 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/6/88.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/6/91.png b/components/camel-djl/src/test/resources/data/mnist/6/91.png new file mode 100644 index 0000000..7a34f92 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/6/91.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/6/98.png b/components/camel-djl/src/test/resources/data/mnist/6/98.png new file mode 100644 index 0000000..5cf5a30 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/6/98.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/7/0.png b/components/camel-djl/src/test/resources/data/mnist/7/0.png new file mode 100644 index 0000000..e6b5011 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/7/0.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/7/17.png b/components/camel-djl/src/test/resources/data/mnist/7/17.png new file mode 100644 index 0000000..953258c Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/7/17.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/7/26.png b/components/camel-djl/src/test/resources/data/mnist/7/26.png new file mode 100644 index 0000000..1f51757 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/7/26.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/7/34.png b/components/camel-djl/src/test/resources/data/mnist/7/34.png new file mode 100644 index 0000000..0e209d2 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/7/34.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/7/36.png b/components/camel-djl/src/test/resources/data/mnist/7/36.png new file mode 100644 index 0000000..4acb76f Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/7/36.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/7/41.png b/components/camel-djl/src/test/resources/data/mnist/7/41.png new file mode 100644 index 0000000..0fe8701 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/7/41.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/7/60.png b/components/camel-djl/src/test/resources/data/mnist/7/60.png new file mode 100644 index 0000000..494a11a Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/7/60.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/7/64.png b/components/camel-djl/src/test/resources/data/mnist/7/64.png new file mode 100644 index 0000000..6bb01a6 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/7/64.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/7/70.png b/components/camel-djl/src/test/resources/data/mnist/7/70.png new file mode 100644 index 0000000..546345f Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/7/70.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/7/75.png b/components/camel-djl/src/test/resources/data/mnist/7/75.png new file mode 100644 index 0000000..2f3d7ab Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/7/75.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/7/79.png b/components/camel-djl/src/test/resources/data/mnist/7/79.png new file mode 100644 index 0000000..1bc0bef Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/7/79.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/7/80.png b/components/camel-djl/src/test/resources/data/mnist/7/80.png new file mode 100644 index 0000000..0ce6185 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/7/80.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/7/83.png b/components/camel-djl/src/test/resources/data/mnist/7/83.png new file mode 100644 index 0000000..984fa8f Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/7/83.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/7/86.png b/components/camel-djl/src/test/resources/data/mnist/7/86.png new file mode 100644 index 0000000..bafa23d Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/7/86.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/7/97.png b/components/camel-djl/src/test/resources/data/mnist/7/97.png new file mode 100644 index 0000000..2053582 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/7/97.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/8/110.png b/components/camel-djl/src/test/resources/data/mnist/8/110.png new file mode 100644 index 0000000..74191c6 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/8/110.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/8/128.png b/components/camel-djl/src/test/resources/data/mnist/8/128.png new file mode 100644 index 0000000..04562c9 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/8/128.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/8/134.png b/components/camel-djl/src/test/resources/data/mnist/8/134.png new file mode 100644 index 0000000..8dcfe0c Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/8/134.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/8/146.png b/components/camel-djl/src/test/resources/data/mnist/8/146.png new file mode 100644 index 0000000..591610e Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/8/146.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/8/177.png b/components/camel-djl/src/test/resources/data/mnist/8/177.png new file mode 100644 index 0000000..8cc4458 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/8/177.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/8/179.png b/components/camel-djl/src/test/resources/data/mnist/8/179.png new file mode 100644 index 0000000..d74bd33 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/8/179.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/8/61.png b/components/camel-djl/src/test/resources/data/mnist/8/61.png new file mode 100644 index 0000000..88083cc Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/8/61.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/8/84.png b/components/camel-djl/src/test/resources/data/mnist/8/84.png new file mode 100644 index 0000000..625b1b3 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/8/84.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/9/12.png b/components/camel-djl/src/test/resources/data/mnist/9/12.png new file mode 100644 index 0000000..37787f1 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/9/12.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/9/16.png b/components/camel-djl/src/test/resources/data/mnist/9/16.png new file mode 100644 index 0000000..d72d155 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/9/16.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/9/20.png b/components/camel-djl/src/test/resources/data/mnist/9/20.png new file mode 100644 index 0000000..73b45fc Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/9/20.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/9/58.png b/components/camel-djl/src/test/resources/data/mnist/9/58.png new file mode 100644 index 0000000..b8bbda5 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/9/58.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/9/62.png b/components/camel-djl/src/test/resources/data/mnist/9/62.png new file mode 100644 index 0000000..9ad1c69 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/9/62.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/9/7.png b/components/camel-djl/src/test/resources/data/mnist/9/7.png new file mode 100644 index 0000000..eb1a5f1 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/9/7.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/9/73.png b/components/camel-djl/src/test/resources/data/mnist/9/73.png new file mode 100644 index 0000000..f7cba0b Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/9/73.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/9/78.png b/components/camel-djl/src/test/resources/data/mnist/9/78.png new file mode 100644 index 0000000..652409d Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/9/78.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/9/9.png b/components/camel-djl/src/test/resources/data/mnist/9/9.png new file mode 100644 index 0000000..6fab54a Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/9/9.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/9/92.png b/components/camel-djl/src/test/resources/data/mnist/9/92.png new file mode 100644 index 0000000..d6fb9e6 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/9/92.png differ diff --git a/components/camel-djl/src/test/resources/data/mnist/9/99.png b/components/camel-djl/src/test/resources/data/mnist/9/99.png new file mode 100644 index 0000000..d1a8a23 Binary files /dev/null and b/components/camel-djl/src/test/resources/data/mnist/9/99.png differ diff --git a/components/camel-djl/src/test/resources/log4j2.properties b/components/camel-djl/src/test/resources/log4j2.properties new file mode 100644 index 0000000..328db35 --- /dev/null +++ b/components/camel-djl/src/test/resources/log4j2.properties @@ -0,0 +1,7 @@ + +appender.out.type = Console +appender.out.name = out +appender.out.layout.type = PatternLayout +appender.out.layout.pattern = [%30.30t] %-30.30c{1} %-5p %m%n +rootLogger.level = INFO +rootLogger.appenderRef.out.ref = out diff --git a/components/camel-djl/src/test/resources/models/mnist/mlp-0007.params b/components/camel-djl/src/test/resources/models/mnist/mlp-0007.params new file mode 100644 index 0000000..46c099f Binary files /dev/null and b/components/camel-djl/src/test/resources/models/mnist/mlp-0007.params differ diff --git a/components/camel-djl/src/test/resources/models/mnist/synset.txt b/components/camel-djl/src/test/resources/models/mnist/synset.txt new file mode 100644 index 0000000..f55b5c9 --- /dev/null +++ b/components/camel-djl/src/test/resources/models/mnist/synset.txt @@ -0,0 +1,10 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 \ No newline at end of file diff --git a/components/pom.xml b/components/pom.xml index 9b0089a..d5b626a 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -16,8 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -375,7 +374,8 @@ <module>camel-zipkin</module> <module>camel-zookeeper-master</module> <module>camel-zookeeper</module> - </modules> + <module>camel-djl</module> + </modules> <properties> <camel.osgi.manifest>${project.build.outputDirectory}/META-INF/MANIFEST.MF</camel.osgi.manifest> diff --git a/core/camel-allcomponents/pom.xml b/core/camel-allcomponents/pom.xml index ede377c..abf4fb2 100644 --- a/core/camel-allcomponents/pom.xml +++ b/core/camel-allcomponents/pom.xml @@ -404,6 +404,10 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-djl</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-dns</artifactId> </dependency> <dependency> diff --git a/parent/pom.xml b/parent/pom.xml index c4e9466..dbcfbc1 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -1240,6 +1240,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-djl</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-dns</artifactId> <version>${project.version}</version> </dependency>