Add fire_smoke, reflective_vest, safety_helmet detection sdks.
25
sec_sdks/fire_smoke_sdk_cpu/README.md
Normal file
@ -0,0 +1,25 @@
|
||||
# 烟火检测SDK
|
||||
支持烟雾-火灾2类检测.
|
||||
|
||||
|
||||
### SDK功能
|
||||
- 烟火检测,给出检测框和置信度
|
||||
- 支持类别:
|
||||
- fire
|
||||
- smoke
|
||||
|
||||
## 运行例子 - FireSmokeDetectExample
|
||||
- 测试图片
|
||||
![fire_detect](https://djl-model.oss-cn-hongkong.aliyuncs.com/AIAS/sec_sdks/images/fire_detect_result.png)
|
||||
|
||||
运行成功后,命令行应该看到下面的信息:
|
||||
```text
|
||||
[INFO ] - [
|
||||
class: "fire 0.847178041934967", probability: 0.84717, bounds: [x=0.522, y=0.516, width=0.083, height=0.173]
|
||||
class: "smoke 0.4434642493724823", probability: 0.44346, bounds: [x=0.492, y=0.000, width=0.295, height=0.116]
|
||||
class: "smoke 0.36228814721107483", probability: 0.36228, bounds: [x=0.576, y=0.110, width=0.113, height=0.121]
|
||||
]
|
||||
```
|
||||
|
||||
### 帮助
|
||||
添加依赖库:lib/aias-fire-smoke-lib-0.1.0.jar
|
BIN
sec_sdks/fire_smoke_sdk_cpu/build/output/fire_detect_result.png
Normal file
After Width: | Height: | Size: 1.7 MiB |
BIN
sec_sdks/fire_smoke_sdk_cpu/doc/img/fire_detect_result.png
Normal file
After Width: | Height: | Size: 88 KiB |
44
sec_sdks/fire_smoke_sdk_cpu/fire_smoke_sdk_cpu.iml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="CheckStyle-IDEA-Module">
|
||||
<option name="configuration">
|
||||
<map />
|
||||
</option>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-cli:commons-cli:1.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-slf4j-impl:2.12.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.12.1" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.logging.log4j:log4j-core:2.12.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl:api:0.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.java.dev.jna:jna:5.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.20" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl:basicdataset:0.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-csv:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl:model-zoo:0.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl.pytorch:pytorch-engine:0.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl.pytorch:pytorch-model-zoo:0.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl.pytorch:pytorch-native-auto:1.8.1" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.18" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.testng:testng:6.8.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.10" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.beanshell:bsh:2.0b4" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: com.beust:jcommander:1.27" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.yaml:snakeyaml:1.6" level="project" />
|
||||
<orderEntry type="library" name="aias-fire-smoke-lib-0.1.0" level="project" />
|
||||
</component>
|
||||
</module>
|
BIN
sec_sdks/fire_smoke_sdk_cpu/lib/aias-fire-smoke-lib-0.1.0.jar
Normal file
118
sec_sdks/fire_smoke_sdk_cpu/pom.xml
Normal file
@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one
|
||||
~ or more contributor license agreements. See the NOTICE file
|
||||
~ distributed with this work for additional information
|
||||
~ regarding copyright ownership. The ASF licenses this file
|
||||
~ to you under the Apache License, Version 2.0 (the
|
||||
~ "License"); you may not use this file except in compliance
|
||||
~ with the License. You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
-->
|
||||
|
||||
<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>
|
||||
|
||||
<groupId>calvin</groupId>
|
||||
<artifactId>fire-smoke-sdk</artifactId>
|
||||
<version>0.1</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<djl.version>0.12.0</djl.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
<version>3.8.1</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.30</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
<artifactId>commons-cli</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.12.1</version>
|
||||
</dependency>
|
||||
<!-- 服务器端推理引擎 -->
|
||||
<dependency>
|
||||
<groupId>ai.djl</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>${djl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ai.djl</groupId>
|
||||
<artifactId>basicdataset</artifactId>
|
||||
<version>${djl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ai.djl</groupId>
|
||||
<artifactId>model-zoo</artifactId>
|
||||
<version>${djl.version}</version>
|
||||
</dependency>
|
||||
<!-- Pytorch -->
|
||||
<dependency>
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-engine</artifactId>
|
||||
<version>${djl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-model-zoo</artifactId>
|
||||
<version>${djl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-native-auto</artifactId>
|
||||
<version>1.8.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.18</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>6.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,67 @@
|
||||
package me.calvin.example;
|
||||
|
||||
import ai.djl.ModelException;
|
||||
import ai.djl.inference.Predictor;
|
||||
import ai.djl.modality.cv.Image;
|
||||
import ai.djl.modality.cv.ImageFactory;
|
||||
import ai.djl.modality.cv.output.BoundingBox;
|
||||
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.translate.TranslateException;
|
||||
import me.calvin.aias.FireSmokeDetect;
|
||||
import me.calvin.aias.util.ImageUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 烟火检测例子
|
||||
*
|
||||
* 目录:http://aias.top/
|
||||
*
|
||||
* @author Calvin
|
||||
*/
|
||||
public final class FireSmokeDetectExample {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(FireSmokeDetectExample.class);
|
||||
|
||||
private FireSmokeDetectExample() {}
|
||||
|
||||
public static void main(String[] args) throws IOException, ModelException, TranslateException {
|
||||
Path imageFile = Paths.get("src/test/resources/fire_smoke.png");
|
||||
Image image = ImageFactory.getInstance().fromFile(imageFile);
|
||||
|
||||
Criteria<Image, DetectedObjects> criteria = new FireSmokeDetect().criteria();
|
||||
|
||||
try (ZooModel model = ModelZoo.loadModel(criteria);
|
||||
Predictor<Image, DetectedObjects> predictor = model.newPredictor()) {
|
||||
DetectedObjects detections = predictor.predict(image);
|
||||
List<DetectedObjects.DetectedObject> items = detections.items();
|
||||
|
||||
List<String> names = new ArrayList<>();
|
||||
List<Double> prob = new ArrayList<>();
|
||||
List<BoundingBox> boxes = new ArrayList<>();
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
DetectedObjects.DetectedObject item = items.get(i);
|
||||
if (item.getProbability() < 0.3f) {
|
||||
continue;
|
||||
}
|
||||
names.add(item.getClassName() + " " + item.getProbability());
|
||||
prob.add(item.getProbability());
|
||||
boxes.add(item.getBoundingBox());
|
||||
}
|
||||
|
||||
detections = new DetectedObjects(names, prob, boxes);
|
||||
ImageUtils.saveBoundingBoxImage(image, detections, "fire_detect_result.png", "build/output");
|
||||
|
||||
logger.info("{}", detections);
|
||||
}
|
||||
}
|
||||
}
|
17
sec_sdks/fire_smoke_sdk_cpu/src/main/resources/log4j2.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<Console name="console" target="SYSTEM_OUT">
|
||||
<PatternLayout
|
||||
pattern="[%-5level] - %msg%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="info" additivity="false">
|
||||
<AppenderRef ref="console"/>
|
||||
</Root>
|
||||
<Logger name="me.calvin" level="${sys:me.calvin.logging.level:-info}" additivity="false">
|
||||
<AppenderRef ref="console"/>
|
||||
</Logger>
|
||||
</Loggers>
|
||||
</Configuration>
|
BIN
sec_sdks/fire_smoke_sdk_cpu/src/test/resources/fire_smoke.png
Normal file
After Width: | Height: | Size: 1.5 MiB |
24
sec_sdks/reflective_vest_sdk_cpu/README.md
Normal file
@ -0,0 +1,24 @@
|
||||
# 反光衣检测SDK
|
||||
实现施工区域或者危险区域人员穿戴检测.
|
||||
|
||||
|
||||
### SDK功能
|
||||
- 反光衣检测,给出检测框和置信度
|
||||
|
||||
## 运行例子 - ReflectiveVestDetectExample
|
||||
- 测试图片
|
||||
![pedestrian](https://djl-model.oss-cn-hongkong.aliyuncs.com/AIAS/sec_sdks/images/reflective_detect_result.png)
|
||||
|
||||
运行成功后,命令行应该看到下面的信息:
|
||||
```text
|
||||
[INFO ] - [
|
||||
class: "safe 0.936024010181427", probability: 0.93602, bounds: [x=0.316, y=0.628, width=0.259, height=0.370]
|
||||
class: "safe 0.9202641248703003", probability: 0.92026, bounds: [x=0.000, y=0.106, width=0.176, height=0.341]
|
||||
class: "safe 0.9085375070571899", probability: 0.90853, bounds: [x=0.578, y=0.501, width=0.221, height=0.485]
|
||||
class: "safe 0.8891122937202454", probability: 0.88911, bounds: [x=0.802, y=0.465, width=0.197, height=0.532]
|
||||
class: "unsafe 0.781899094581604", probability: 0.78189, bounds: [x=0.177, y=0.432, width=0.190, height=0.416]
|
||||
]
|
||||
```
|
||||
|
||||
### 帮助
|
||||
添加依赖库:lib/aias-reflective-vest-lib-0.1.0.jar
|
After Width: | Height: | Size: 836 KiB |
After Width: | Height: | Size: 78 KiB |
118
sec_sdks/reflective_vest_sdk_cpu/pom.xml
Normal file
@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one
|
||||
~ or more contributor license agreements. See the NOTICE file
|
||||
~ distributed with this work for additional information
|
||||
~ regarding copyright ownership. The ASF licenses this file
|
||||
~ to you under the Apache License, Version 2.0 (the
|
||||
~ "License"); you may not use this file except in compliance
|
||||
~ with the License. You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
-->
|
||||
|
||||
<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>
|
||||
|
||||
<groupId>calvin</groupId>
|
||||
<artifactId>reflective-vest-sdk</artifactId>
|
||||
<version>0.1</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<djl.version>0.12.0</djl.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
<version>3.8.1</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.30</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
<artifactId>commons-cli</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.12.1</version>
|
||||
</dependency>
|
||||
<!-- 服务器端推理引擎 -->
|
||||
<dependency>
|
||||
<groupId>ai.djl</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>${djl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ai.djl</groupId>
|
||||
<artifactId>basicdataset</artifactId>
|
||||
<version>${djl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ai.djl</groupId>
|
||||
<artifactId>model-zoo</artifactId>
|
||||
<version>${djl.version}</version>
|
||||
</dependency>
|
||||
<!-- Pytorch -->
|
||||
<dependency>
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-engine</artifactId>
|
||||
<version>${djl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-model-zoo</artifactId>
|
||||
<version>${djl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ai.djl.pytorch</groupId>
|
||||
<artifactId>pytorch-native-auto</artifactId>
|
||||
<version>1.8.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.18</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>6.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
44
sec_sdks/reflective_vest_sdk_cpu/reflective_vest_sdk_cpu.iml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="CheckStyle-IDEA-Module">
|
||||
<option name="configuration">
|
||||
<map />
|
||||
</option>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="aias-reflective-vest-lib-0.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-cli:commons-cli:1.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-slf4j-impl:2.12.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.12.1" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.logging.log4j:log4j-core:2.12.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl:api:0.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.java.dev.jna:jna:5.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.20" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl:basicdataset:0.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-csv:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl:model-zoo:0.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl.pytorch:pytorch-engine:0.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl.pytorch:pytorch-model-zoo:0.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl.pytorch:pytorch-native-auto:1.8.1" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.18" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.testng:testng:6.8.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.10" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.beanshell:bsh:2.0b4" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: com.beust:jcommander:1.27" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.yaml:snakeyaml:1.6" level="project" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,65 @@
|
||||
package me.calvin.example;
|
||||
|
||||
import ai.djl.ModelException;
|
||||
import ai.djl.inference.Predictor;
|
||||
import ai.djl.modality.cv.Image;
|
||||
import ai.djl.modality.cv.ImageFactory;
|
||||
import ai.djl.modality.cv.output.BoundingBox;
|
||||
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.translate.TranslateException;
|
||||
import me.calvin.aias.ReflectiveVest;
|
||||
import me.calvin.aias.util.ImageUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 行人检测例子 http://aias.top/
|
||||
*
|
||||
* @author Calvin
|
||||
*/
|
||||
public final class ReflectiveVestDetectExample {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ReflectiveVestDetectExample.class);
|
||||
|
||||
private ReflectiveVestDetectExample() {}
|
||||
|
||||
public static void main(String[] args) throws IOException, ModelException, TranslateException {
|
||||
Path imageFile = Paths.get("src/test/resources/vest.jpg");
|
||||
Image image = ImageFactory.getInstance().fromFile(imageFile);
|
||||
|
||||
Criteria<Image, DetectedObjects> criteria = new ReflectiveVest().criteria();
|
||||
|
||||
try (ZooModel model = ModelZoo.loadModel(criteria);
|
||||
Predictor<Image, DetectedObjects> predictor = model.newPredictor()) {
|
||||
DetectedObjects detections = predictor.predict(image);
|
||||
List<DetectedObjects.DetectedObject> items = detections.items();
|
||||
|
||||
List<String> names = new ArrayList<>();
|
||||
List<Double> prob = new ArrayList<>();
|
||||
List<BoundingBox> boxes = new ArrayList<>();
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
DetectedObjects.DetectedObject item = items.get(i);
|
||||
if (item.getProbability() < 0.5f) {
|
||||
continue;
|
||||
}
|
||||
names.add(item.getClassName() + " " + item.getProbability());
|
||||
prob.add(item.getProbability());
|
||||
boxes.add(item.getBoundingBox());
|
||||
}
|
||||
|
||||
detections = new DetectedObjects(names, prob, boxes);
|
||||
ImageUtils.saveBoundingBoxImage(image, detections, "reflective_detect_result.png", "build/output");
|
||||
|
||||
logger.info("{}", detections);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<Console name="console" target="SYSTEM_OUT">
|
||||
<PatternLayout
|
||||
pattern="[%-5level] - %msg%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="info" additivity="false">
|
||||
<AppenderRef ref="console"/>
|
||||
</Root>
|
||||
<Logger name="me.calvin" level="${sys:me.calvin.logging.level:-info}" additivity="false">
|
||||
<AppenderRef ref="console"/>
|
||||
</Logger>
|
||||
</Loggers>
|
||||
</Configuration>
|
BIN
sec_sdks/reflective_vest_sdk_cpu/src/test/resources/vest.jpg
Normal file
After Width: | Height: | Size: 302 KiB |
39
sec_sdks/safety_helmet_sdk_cpu/README.md
Normal file
@ -0,0 +1,39 @@
|
||||
# 安全帽检测SDK
|
||||
安全帽检测。
|
||||
- 支持类别:
|
||||
- safe
|
||||
- unsafe
|
||||
|
||||
### SDK功能
|
||||
- 安全帽检测,给出检测框和置信度
|
||||
- 三个模型:
|
||||
- 小模型(mobilenet0.25)
|
||||
- 中模型(mobilenet1.0)
|
||||
- 大模型(darknet53)
|
||||
|
||||
## 运行小模型例子 - SmallSafetyHelmetDetectExample
|
||||
- 测试图片
|
||||
![small](https://djl-model.oss-cn-hongkong.aliyuncs.com/AIAS/sec_sdks/images/safety_helmet_result_s.png)
|
||||
|
||||
## 运行中模型例子 - MediumSafetyHelmetDetectExample
|
||||
- 测试图片
|
||||
![medium](https://djl-model.oss-cn-hongkong.aliyuncs.com/AIAS/sec_sdks/images/safety_helmet_result_m.png)
|
||||
|
||||
## 运行大模型例子 - LargeSafetyHelmetDetectExample
|
||||
- 测试图片
|
||||
![large](https://djl-model.oss-cn-hongkong.aliyuncs.com/AIAS/sec_sdks/images/safety_helmet_result_l.png)
|
||||
|
||||
|
||||
运行成功后,命令行应该看到下面的信息:
|
||||
```text
|
||||
[INFO ] - [
|
||||
class: "safe 0.9983590245246887", probability: 0.99835, bounds: [x=0.244, y=0.000, width=0.086, height=0.150]
|
||||
class: "unsafe 0.998088538646698", probability: 0.99808, bounds: [x=0.226, y=0.204, width=0.115, height=0.263]
|
||||
class: "safe 0.997364342212677", probability: 0.99736, bounds: [x=0.584, y=0.247, width=0.162, height=0.302]
|
||||
class: "safe 0.9963852167129517", probability: 0.99638, bounds: [x=0.319, y=0.000, width=0.076, height=0.133]
|
||||
class: "safe 0.9952006936073303", probability: 0.99520, bounds: [x=0.757, y=0.262, width=0.111, height=0.264]
|
||||
]
|
||||
```
|
||||
|
||||
### 帮助
|
||||
添加依赖库:lib/aias-safety-helmet-lib-0.1.0.jar
|
After Width: | Height: | Size: 800 KiB |
After Width: | Height: | Size: 804 KiB |
After Width: | Height: | Size: 812 KiB |
After Width: | Height: | Size: 82 KiB |
After Width: | Height: | Size: 75 KiB |
After Width: | Height: | Size: 75 KiB |
118
sec_sdks/safety_helmet_sdk_cpu/pom.xml
Normal file
@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one
|
||||
~ or more contributor license agreements. See the NOTICE file
|
||||
~ distributed with this work for additional information
|
||||
~ regarding copyright ownership. The ASF licenses this file
|
||||
~ to you under the Apache License, Version 2.0 (the
|
||||
~ "License"); you may not use this file except in compliance
|
||||
~ with the License. You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
-->
|
||||
|
||||
<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>
|
||||
|
||||
<groupId>calvin</groupId>
|
||||
<artifactId>safety-helmet-sdk</artifactId>
|
||||
<version>0.1</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<djl.version>0.12.0</djl.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
<version>3.8.1</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.30</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
<artifactId>commons-cli</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.12.1</version>
|
||||
</dependency>
|
||||
<!-- 服务器端推理引擎 -->
|
||||
<dependency>
|
||||
<groupId>ai.djl</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>${djl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ai.djl</groupId>
|
||||
<artifactId>basicdataset</artifactId>
|
||||
<version>${djl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ai.djl</groupId>
|
||||
<artifactId>model-zoo</artifactId>
|
||||
<version>${djl.version}</version>
|
||||
</dependency>
|
||||
<!-- MXNet -->
|
||||
<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.8.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.18</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>6.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
44
sec_sdks/safety_helmet_sdk_cpu/safety_helmet_sdk_cpu.iml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="CheckStyle-IDEA-Module">
|
||||
<option name="configuration">
|
||||
<map />
|
||||
</option>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="aias-safety-helmet-lib-0.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-cli:commons-cli:1.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-slf4j-impl:2.12.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.12.1" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.logging.log4j:log4j-core:2.12.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl:api:0.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.java.dev.jna:jna:5.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.20" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl:basicdataset:0.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-csv:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl:model-zoo:0.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl.mxnet:mxnet-model-zoo:0.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl.mxnet:mxnet-engine:0.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: ai.djl.mxnet:mxnet-native-auto:1.8.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.18" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.testng:testng:6.8.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.10" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.beanshell:bsh:2.0b4" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: com.beust:jcommander:1.27" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.yaml:snakeyaml:1.6" level="project" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,67 @@
|
||||
package me.calvin.example;
|
||||
|
||||
import ai.djl.ModelException;
|
||||
import ai.djl.inference.Predictor;
|
||||
import ai.djl.modality.cv.Image;
|
||||
import ai.djl.modality.cv.ImageFactory;
|
||||
import ai.djl.modality.cv.output.BoundingBox;
|
||||
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.translate.TranslateException;
|
||||
import me.calvin.aias.LargeSafetyHelmetDetect;
|
||||
import me.calvin.aias.util.ImageUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 安全帽检测例子
|
||||
*
|
||||
* 目录:http://aias.top/
|
||||
*
|
||||
* @author Calvin
|
||||
*/
|
||||
public final class LargeSafetyHelmetDetectExample {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(LargeSafetyHelmetDetectExample.class);
|
||||
|
||||
private LargeSafetyHelmetDetectExample() {}
|
||||
|
||||
public static void main(String[] args) throws IOException, ModelException, TranslateException {
|
||||
Path imageFile = Paths.get("src/test/resources/safety_helmet.jpg");
|
||||
Image image = ImageFactory.getInstance().fromFile(imageFile);
|
||||
|
||||
Criteria<Image, DetectedObjects> criteria = new LargeSafetyHelmetDetect().criteria(image);
|
||||
|
||||
try (ZooModel model = ModelZoo.loadModel(criteria);
|
||||
Predictor<Image, DetectedObjects> predictor = model.newPredictor()) {
|
||||
DetectedObjects detections = predictor.predict(image);
|
||||
List<DetectedObjects.DetectedObject> items = detections.items();
|
||||
|
||||
List<String> names = new ArrayList<>();
|
||||
List<Double> prob = new ArrayList<>();
|
||||
List<BoundingBox> boxes = new ArrayList<>();
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
DetectedObjects.DetectedObject item = items.get(i);
|
||||
if (item.getProbability() < 0.3f) {
|
||||
continue;
|
||||
}
|
||||
names.add(item.getClassName() + " " + item.getProbability());
|
||||
prob.add(item.getProbability());
|
||||
boxes.add(item.getBoundingBox());
|
||||
}
|
||||
|
||||
detections = new DetectedObjects(names, prob, boxes);
|
||||
ImageUtils.saveBoundingBoxImage(image, detections, "safety_helmet_result_l.png", "build/output");
|
||||
|
||||
logger.info("{}", detections);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package me.calvin.example;
|
||||
|
||||
import ai.djl.ModelException;
|
||||
import ai.djl.inference.Predictor;
|
||||
import ai.djl.modality.cv.Image;
|
||||
import ai.djl.modality.cv.ImageFactory;
|
||||
import ai.djl.modality.cv.output.BoundingBox;
|
||||
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.translate.TranslateException;
|
||||
import me.calvin.aias.MediumSafetyHelmetDetect;
|
||||
import me.calvin.aias.util.ImageUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 安全帽检测例子
|
||||
*
|
||||
* 目录:http://aias.top/
|
||||
*
|
||||
* @author Calvin
|
||||
*/
|
||||
public final class MediumSafetyHelmetDetectExample {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MediumSafetyHelmetDetectExample.class);
|
||||
|
||||
private MediumSafetyHelmetDetectExample() {}
|
||||
|
||||
public static void main(String[] args) throws IOException, ModelException, TranslateException {
|
||||
Path imageFile = Paths.get("src/test/resources/safety_helmet.jpg");
|
||||
Image image = ImageFactory.getInstance().fromFile(imageFile);
|
||||
|
||||
Criteria<Image, DetectedObjects> criteria = new MediumSafetyHelmetDetect().criteria(image);
|
||||
|
||||
try (ZooModel model = ModelZoo.loadModel(criteria);
|
||||
Predictor<Image, DetectedObjects> predictor = model.newPredictor()) {
|
||||
DetectedObjects detections = predictor.predict(image);
|
||||
List<DetectedObjects.DetectedObject> items = detections.items();
|
||||
|
||||
List<String> names = new ArrayList<>();
|
||||
List<Double> prob = new ArrayList<>();
|
||||
List<BoundingBox> boxes = new ArrayList<>();
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
DetectedObjects.DetectedObject item = items.get(i);
|
||||
if (item.getProbability() < 0.3f) {
|
||||
continue;
|
||||
}
|
||||
names.add(item.getClassName() + " " + item.getProbability());
|
||||
prob.add(item.getProbability());
|
||||
boxes.add(item.getBoundingBox());
|
||||
}
|
||||
|
||||
detections = new DetectedObjects(names, prob, boxes);
|
||||
ImageUtils.saveBoundingBoxImage(image, detections, "safety_helmet_result_m.png", "build/output");
|
||||
|
||||
logger.info("{}", detections);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package me.calvin.example;
|
||||
|
||||
import ai.djl.ModelException;
|
||||
import ai.djl.inference.Predictor;
|
||||
import ai.djl.modality.cv.Image;
|
||||
import ai.djl.modality.cv.ImageFactory;
|
||||
import ai.djl.modality.cv.output.BoundingBox;
|
||||
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.translate.TranslateException;
|
||||
import me.calvin.aias.SmallSafetyHelmetDetect;
|
||||
import me.calvin.aias.util.ImageUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 安全帽检测例子
|
||||
*
|
||||
* 目录:http://aias.top/
|
||||
*
|
||||
* @author Calvin
|
||||
*/
|
||||
public final class SmallSafetyHelmetDetectExample {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SmallSafetyHelmetDetectExample.class);
|
||||
|
||||
private SmallSafetyHelmetDetectExample() {}
|
||||
|
||||
public static void main(String[] args) throws IOException, ModelException, TranslateException {
|
||||
Path imageFile = Paths.get("src/test/resources/safety_helmet.jpg");
|
||||
Image image = ImageFactory.getInstance().fromFile(imageFile);
|
||||
|
||||
Criteria<Image, DetectedObjects> criteria = new SmallSafetyHelmetDetect().criteria(image);
|
||||
|
||||
try (ZooModel model = ModelZoo.loadModel(criteria);
|
||||
Predictor<Image, DetectedObjects> predictor = model.newPredictor()) {
|
||||
DetectedObjects detections = predictor.predict(image);
|
||||
List<DetectedObjects.DetectedObject> items = detections.items();
|
||||
|
||||
List<String> names = new ArrayList<>();
|
||||
List<Double> prob = new ArrayList<>();
|
||||
List<BoundingBox> boxes = new ArrayList<>();
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
DetectedObjects.DetectedObject item = items.get(i);
|
||||
if (item.getProbability() < 0.3f) {
|
||||
continue;
|
||||
}
|
||||
names.add(item.getClassName() + " " + item.getProbability());
|
||||
prob.add(item.getProbability());
|
||||
boxes.add(item.getBoundingBox());
|
||||
}
|
||||
|
||||
detections = new DetectedObjects(names, prob, boxes);
|
||||
ImageUtils.saveBoundingBoxImage(image, detections, "safety_helmet_result_s.png", "build/output");
|
||||
|
||||
logger.info("{}", detections);
|
||||
}
|
||||
}
|
||||
}
|
17
sec_sdks/safety_helmet_sdk_cpu/src/main/resources/log4j2.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<Console name="console" target="SYSTEM_OUT">
|
||||
<PatternLayout
|
||||
pattern="[%-5level] - %msg%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="info" additivity="false">
|
||||
<AppenderRef ref="console"/>
|
||||
</Root>
|
||||
<Logger name="me.calvin" level="${sys:me.calvin.logging.level:-info}" additivity="false">
|
||||
<AppenderRef ref="console"/>
|
||||
</Logger>
|
||||
</Loggers>
|
||||
</Configuration>
|
After Width: | Height: | Size: 302 KiB |