Skip to content

Commit

Permalink
Upload artifacts to S3 bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfliu committed Mar 15, 2023
1 parent 4409139 commit 426b056
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
10 changes: 5 additions & 5 deletions examples/docs/mask_detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ To configure your development environment, follow [setup](../../docs/development
## Run mask detection example

### Input image file
You can find the image used in this example in the project test resource folder: `src/test/resources/maksssksksss627.png`.
We use the following image as input:

![dogs](../src/test/resources/face_mask.png)
![mask](https://resources.djl.ai/images/face_mask_detection/face_mask.png)

### Build the project and run
Use the following command to run the project:

```
cd examples
./gradlew run -Dai.djl.default_engine=PyTorch -Dmain=ai.djl.examples.inference.MaskDetectionOnnx
./gradlew run -Dmain=ai.djl.examples.inference.MaskDetection
```

Your output should look like the following:

```text
[INFO ] - Detected objects image has been saved in: /Users/fenkexin/Desktop/djl/examples/build/output/mask-wearing.png
[INFO ] - Detected objects image has been saved in: build/output/face_mask_result.png
[INFO ] - {
"w/o mask": 0.8998132944107056,
"w/ mask": 0.8930246829986572,
Expand All @@ -46,4 +46,4 @@ Your output should look like the following:

An output image with bounding box will be saved as `build/output/detected-mask-wearing.png`:

![detected-dogs](../src/test/resources/face_mask_result.png)
![detected-result](https://resources.djl.ai/images/face_mask_detection/face_mask_result.png)
8 changes: 5 additions & 3 deletions examples/docs/object_detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ An output image with bounding box will be saved as build/output/detected-dog_bik
![detected-dogs](img/detected-dog_bike_car.png)

## Run object detection example with other engines
For objection detection application, other than the default model zoo with the default engine, we can also run it with other engines and model zoo. Here, we demonstrate with a pre-trained *YOLOV5s ONNX* model.
For objection detection application, other than the default model zoo with the default engine,
we can also run it with other engines and model zoo. Here, we demonstrate with a pre-trained *YOLOV5s ONNX* model.

First, the following line needs to be added into the dependencies in `build.gradle`. Otherwise, the ONNX model zoo won't be found.
First, the following line needs to be added into the dependencies in `build.gradle`. Otherwise,
the ONNX model zoo won't be found.
```gradle
runtimeOnly project(":engines:onnxruntime:onnxruntime-engine")
```
Expand All @@ -62,4 +64,4 @@ Then use the following criteria
.optProgress(new ProgressBar())
.build();
```
where the `optFilter` is removed and `optEngine` is specified. The rest would be the same.
where the `optFilter` is removed and `optEngine` is specified. The rest would be the same.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package ai.djl.examples.inference;

import ai.djl.Application;
import ai.djl.ModelException;
import ai.djl.inference.Predictor;
import ai.djl.modality.cv.Image;
Expand All @@ -31,8 +30,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* An example of inference using an object detection model.
Expand All @@ -53,27 +50,23 @@ public static void main(String[] args) throws IOException, ModelException, Trans
}

public static DetectedObjects predict() throws IOException, ModelException, TranslateException {
Path imageFile = Paths.get("src/test/resources/maksssksksss627.png");
Image img = ImageFactory.getInstance().fromFile(imageFile);

String modelPath = "src/test/resources/mask.onnx";
Map<String, Object> arguments = new ConcurrentHashMap<>();
arguments.put("translatorFactory", YoloV5TranslatorFactory.class.getName());
String imageUrl = "https://resources.djl.ai/images/face_mask_detection/face_mask.png";
Image img = ImageFactory.getInstance().fromUrl(imageUrl);

String modelUrl = "https://resources.djl.ai/demo/onnxruntime/face_mask_detection.zip";
Criteria<Image, DetectedObjects> criteria =
Criteria.builder()
.optApplication(Application.CV.OBJECT_DETECTION)
.setTypes(Image.class, DetectedObjects.class)
.optModelUrls(modelPath)
.optModelUrls(modelUrl)
.optEngine("OnnxRuntime")
.optArguments(arguments)
.optTranslatorFactory(new YoloV5TranslatorFactory())
.optProgress(new ProgressBar())
.build();

try (ZooModel<Image, DetectedObjects> model = criteria.loadModel()) {
try (Predictor<Image, DetectedObjects> predictor = model.newPredictor()) {
DetectedObjects detection = predictor.predict(img);
String outputDir = "/Users/fenkexin/Desktop/djl/examples/build/output";
String outputDir = "build/output";
saveBoundingBoxImage(img, detection, outputDir);
return detection;
}
Expand All @@ -87,7 +80,7 @@ private static void saveBoundingBoxImage(Image img, DetectedObjects detection, S

img.drawBoundingBoxes(detection);

Path imagePath = outputPath.resolve("mask-wearing.png");
Path imagePath = outputPath.resolve("face_mask_result.png");
// OpenJDK can't save jpg with alpha channel
img.save(Files.newOutputStream(imagePath), "png");
logger.info("Detected objects image has been saved in: {}", imagePath);
Expand Down

0 comments on commit 426b056

Please sign in to comment.