Skip to content

Commit

Permalink
edits accepted
Browse files Browse the repository at this point in the history
  • Loading branch information
AWSChris committed Apr 25, 2022
1 parent e4eb955 commit 638bca0
Show file tree
Hide file tree
Showing 26 changed files with 102 additions and 103 deletions.
14 changes: 7 additions & 7 deletions javav2/example_code/lookoutvision/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The Java examples perform AWS operations for the account and AWS Region for whic

Some of these examples perform *destructive* operations on AWS resources. **Be very careful** when running an operation that deletes or modifies AWS resources in your account. It's best to create separate test-only resources when experimenting with these examples.

To run these examples, you can setup your development environment to use Apache Maven or Gradle to configure and build AWS SDK for Java projects. For more information,
To run these examples, you can set up your development environment to use Apache Maven or Gradle to configure and build AWS SDK for Java projects. For more information,
see [Get started with the AWS SDK for Java 2.x](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html).

Before running the examples and unit tests, we recommend that you read the [Amazon Lookout for Vision documentation](https://docs.aws.amazon.com/lookout-for-vision/latest/developer-guide/what-is.html). To help you understand the Amazon Lookout for Vision API, read [Getting started with the AWS SDK](https://docs.aws.amazon.com/lookout-for-vision/latest/developer-guide/getting-started-sdk.html). We provide example images that you can use. For more information, see [Step 8: (Optional) Prepare example images](https://docs.aws.amazon.com/lookout-for-vision/latest/developer-guide/su-prepare-example-images.html).
Expand All @@ -26,7 +26,7 @@ The following files provide utility classes for managing Amazon Lookout for Visi

The following examples use the utility classes to show how to use the Amazon Lookout for Vision API.

- **CreateDataset.java** - Shows how to create an Amazon Lookout for Vision dataset with [CreateDataset](https://docs.aws.amazon.com/lookout-for-vision/latest/APIReference/API_CreateDataset.html). You need a manifest file to train the model. We provide a [script](https://docs.aws.amazon.com/lookout-for-vision/latest/developer-guide/ex-csv-manifest.html) that creates a manifest file from a CSV file. For more information, see [Creating a manifest file](https://docs.aws.amazon.com/lookout-for-vision/latest/developer-guide/manifest-files.html).
- **CreateDataset.java** - Shows how to create an Amazon Lookout for Vision dataset with [CreateDataset](https://docs.aws.amazon.com/lookout-for-vision/latest/APIReference/API_CreateDataset.html). You must have a manifest file to train the model. We provide a [script](https://docs.aws.amazon.com/lookout-for-vision/latest/developer-guide/ex-csv-manifest.html) that creates a manifest file from a .csv file. For more information, see [Creating a manifest file](https://docs.aws.amazon.com/lookout-for-vision/latest/developer-guide/manifest-files.html).
- **CreateModel.java** - Shows how to create an Amazon Lookout for Vision model with [CreateModel](https://docs.aws.amazon.com/lookout-for-vision/latest/APIReference/API_CreateModel.html). You are charged for the amount of time it takes to successfully train a model.
- **CreateProject.java** - Shows how to create an Amazon Lookout for Vision project with [CreateProject](https://docs.aws.amazon.com/lookout-for-vision/latest/APIReference/API_CreateProject.html).
- **DeleteDataset.java** - Shows how to delete an Amazon Lookout for Vision dataset with [DeleteDataset](https://docs.aws.amazon.com/lookout-for-vision/latest/APIReference/API_DeleteDataset.html).
Expand All @@ -47,21 +47,21 @@ The following examples use the utility classes to show how to use the Amazon Loo
- **StopModel.java** - Shows how to stop a hosted Amazon Lookout for Vision model with [StopModel](https://docs.aws.amazon.com/lookout-for-vision/latest/APIReference/API_StopModel.html).
- **TagModel.java** - Shows how to attach a tag to an Amazon Lookout for Vision model with [TagResource](https://docs.aws.amazon.com/lookout-for-vision/latest/APIReference/API_TagResource.html).
- **UntagModel.java** - Shows how to remove a tag from an Amazon Lookout for Vision model with [UntagResource](https://docs.aws.amazon.com/lookout-for-vision/latest/APIReference/API_UntagResource.html).
- **UpdateDatasetEntries.java** - Shows how update Amazon Lookout for Vision dataset with a manifest file with [UpdateDatasetEntries](https://docs.aws.amazon.com/lookout-for-vision/latest/APIReference/API_UpdateDatasetEntries.html).
- **UpdateDatasetEntries.java** - Shows how to update Amazon Lookout for Vision dataset with a manifest file with [UpdateDatasetEntries](https://docs.aws.amazon.com/lookout-for-vision/latest/APIReference/API_UpdateDatasetEntries.html).


## Testing the Amazon Lookout for Vision files

You can test the Java code examples for Amazon Lookout for Vision by running a test file named **LookoutVisionTest**. This file uses JUnit 5 to run the JUnit tests and is located in the **src/test/java** folder. For more information, see [https://junit.org/junit5/](https://junit.org/junit5/).

You can execute the JUnit tests from a Java IDE, such as IntelliJ, or from the command line by using Maven. As each test is run, you can view messages that inform you if the various tests succeed or fail. For example, the following message informs you that Test 3 passed.
You can run the JUnit tests from a Java IDE, such as IntelliJ, or from the command line by using Maven. As each test is run, you can view messages that inform you if the various tests succeed or fail. For example, the following message informs you that Test 3 passed.

Test 3 passed

**WARNING**: _Running these JUnit tests manipulates real Amazon Lookout for Vision models. You are charged for the amount of time it takes to successfully train the test model and for the amount of time the test model is hosted._

### Properties file
Before running the Amazon Lookout for Vision JUnit tests, you must define values in the **config.properties** file located in the **resources** folder. This file contains values that are required to execute the JUnit tests. For example, you define an instance name used for various tests. If you do not define all values, the JUnit tests fail.
Before running the Amazon Lookout for Vision JUnit tests, you must define values in the **config.properties** file located in the **resources** folder. This file contains values that are required to run the JUnit tests. For example, you define an instance name used for various tests. If you do not define all values, the JUnit tests fail.

Define these values to successfully run the JUnit tests:

Expand All @@ -72,9 +72,9 @@ Define these values to successfully run the JUnit tests:
- **modelTrainingOutputFolder** - The folder in modelTrainingOutputBucket in which to place the training results.
- **photo** - The location of an image to analyze with the trained model.
- **manifestFile** - The location of a local manifest file that is used to populate the training dataset. For more information, see [Creating a manifest file](https://docs.aws.amazon.com/lookout-for-vision/latest/developer-guide/manifest-files.html).
- **modelPackageJobJsonFile** - The location of the edge packaging Job request JSON file. We provide a template JSON file for a [target device](./src/main/resources/packaging-job-request-device-template.json) (Jetson Xavier) and a template JSON file for a [target platform](./src/main/resources/packaging-job-request-hardware-template.json). To successfully run the model packaging job test, make sure the value of **ModelVersion** is "1". Each time you run the test, you must change the value of **ComponentVersion** and **JobName**. For information about the package settings that you can make, see [Packaging your model (SDK)](https://docs.aws.amazon.com/lookout-for-vision/latest/developer-guide/package-job-sdk.html).
- **modelPackageJobJsonFile** - The location of the edge packaging Job request JSON file. We provide a template JSON file for a [target device](./src/main/resources/packaging-job-request-device-template.json) (Jetson Xavier) and a template JSON file for a [target platform](./src/main/resources/packaging-job-request-hardware-template.json). To successfully run the model packaging job test, make sure that the value of **ModelVersion** is "1". Each time you run the test, you must change the value of **ComponentVersion** and **JobName**. For information about the package settings that you can make, see [Packaging your model (SDK)](https://docs.aws.amazon.com/lookout-for-vision/latest/developer-guide/package-job-sdk.html).

If you want to use the project, dataset, and model and that testing creates, disable the following tests:
If you want to use the project, dataset, and model that the testing creates, disable the following tests:
- **deleteDataset_thenNotFound()**
- **deleteModel_thenNotFound()**
- **deleteProject_thenNotFound()**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

// Creates an Amazon Lookout for Vision dataset.
// Creates an Amazon Lookout for Vision dataset.
public class CreateDataset {

public static final Logger logger = Logger.getLogger(CreateDataset.class.getName());
Expand All @@ -29,10 +29,10 @@ public static void main(String[] args) {

final String USAGE = "\n" + "Usage: " + "<project_name> <dataset_type> <bucket> <manifest_file>\n\n"
+ "Where:\n"
+ " project_arn - the ARN of the project that you want to add the dataset to.\n\n"
+ " dataset_type - the type of the dataset that you want to create (train or test).\n\n"
+ " bucket - the S3 bucket that contains the manifest file.\n\n"
+ " manifest_file - the location and name of the manifest file within the bucket.\n\n";
+ " project_arn - The ARN of the project that you want to add the dataset to.\n\n"
+ " dataset_type - The type of the dataset that you want to create (train or test).\n\n"
+ " bucket - The S3 bucket that contains the manifest file.\n\n"
+ " manifest_file - The location and name of the manifest file within the bucket.\n\n";

switch (args.length) {
case 2:
Expand All @@ -48,7 +48,7 @@ public static void main(String[] args) {
break;

default:
// invalid number of arguments
// invalid number of arguments.
System.out.println(USAGE);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public static void main(String[] args) {

final String USAGE = "\n" + "Usage: " + "<project_name> <model_version> <bucket> <output_folder>\n\n"
+ "Where:\n"
+ " project_arn - the project in which you want to create a model.\n\n"
+ " description - a description for the model.\n\n"
+ " bucket - the S3 bucket in which the service should store the training results.\n\n"
+ " output_folder - the folder, in the S3 bucket, in which the service should store the training results.\n\n";
+ " project_arn - The project in which you want to create a model.\n\n"
+ " description - A description for the model.\n\n"
+ " bucket - The S3 bucket in which the service should store the training results.\n\n"
+ " output_folder - The S3 bucket folder in which the service should store the training results.\n\n";

if (args.length != 4) {
System.out.println(USAGE);
Expand All @@ -52,7 +52,7 @@ public static void main(String[] args) {
ModelDescription modelDescription = Models.createModel(lfvClient, projectName, description,
bucket, outputFolder);

// Show the model details
// Show the model details.
System.out.println(String.format("Model Project: %s", projectName));
System.out.println(String.format("Version: %s", modelDescription.modelVersion()));
System.out.println(String.format("ARN: %s", modelDescription.modelArn()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void main(String args[]) throws Exception {
"Usage:\n" +
" CreateProject <project_name> \n\n" +
"Where:\n" +
" project_name - the name of the project that you want to create.\n\n";
" project_name - The name of the project that you want to create.\n\n";

try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class Datasets {
* @param lfvClient An Amazon Lookout for Vision client.
* @param projectName The name of the project in which you want to create a
* dataset.
* @param datasetType The type of the dataset that you want to create (train or
* @param datasetType The type of dataset that you want to create (train or
* test).
* @param bucket The S3 bucket that contains the manifest file.
* @param manifestFile The name and location of the manifest file within the S3
Expand Down Expand Up @@ -98,7 +98,7 @@ public static DatasetDescription createDataset(LookoutVisionClient lfvClient,

boolean finished = false;

// Wait until datase is created, or failure occurs.
// Wait until dataset is created, or failure occurs.
while (!finished) {

datasetDescription = describeDataset(lfvClient, projectName, datasetType);
Expand Down Expand Up @@ -302,7 +302,7 @@ public static DatasetStatus updateDatasetEntries(LookoutVisionClient lfvClient,
boolean finished = false;
DatasetStatus status = null;

// Wait until update completes
// Wait until update completes.

do {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public static void main(String args[]) throws Exception {
"Usage:\n" +
" DeleteDataset <project_name> <dataset_type> \n\n" +
"Where:\n" +
" project_name - the name of the project that contains the dataset that you want to delete.\n\n" +
" dataset_type - the type of the dataset that you want to delete.\n\n";
" project_name - The name of the project that contains the dataset that you want to delete.\n\n" +
" dataset_type - The type of the dataset that you want to delete.\n\n";

try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void main(String args[]) throws Exception {
"Usage:\n" +
" DeleteProject <project_name> \n\n" +
"Where:\n" +
" project_name - the name of the project that you want to delete.\n\n";
" project_name - The name of the project that you want to delete.\n\n";

try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public static void main(String[] args) throws Exception {
"Usage:\n" +
" DescribeProject <project_name> <dataset_type> \n\n" +
"Where:\n" +
" project_name - the name of the project that you want to describe.\n" +
" dataset_type - the type (train or test) of the dataset that you want to describe.\n\n";
" project_name - The name of the project that you want to describe.\n" +
" dataset_type - The type of the dataset that you want to describe (train or test).\n\n";

try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public static void main(String[] args) {

final String USAGE = "\n" + "Usage: " + "<project_name> <model_version>\n\n"
+ "Where:\n"
+ " project_arn - the project that contains the model that you want to describe.\n\n"
+ " model_version - the version of the model that you want to describe\n\n";
+ " project_arn - The project that contains the model that you want to describe.\n\n"
+ " model_version - The version of the model that you want to describe\n\n";

if (args.length != 2) {
System.out.println(USAGE);
Expand All @@ -45,7 +45,7 @@ public static void main(String[] args) {
// Get the model description.
ModelDescription modelDescription = Models.describeModel(lfvClient, projectName, modelVersion);

// Show the model details
// Show the model details.
System.out.println(String.format("Model Project: %s", projectName));
System.out.println(String.format("Version: %s", modelDescription.modelVersion()));
System.out.println(String.format("ARN: %s", modelDescription.modelArn()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public static void main(String[] args) {

final String USAGE = "\n" + "Usage: " + "<project_name> <job_name>\n\n"
+ "Where:\n"
+ " project_arn - the project that contains the model packaging job that you want to describe.\n\n"
+ " job_name - the name of the model packaging job that you want to describe.e\n\n";
+ " project_arn - The project that contains the model packaging job that you want to describe.\n\n"
+ " job_name - The name of the model packaging job that you want to describe.\n\n";

if (args.length != 2) {
System.out.println(USAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ public DetectAnomalies(LookoutVisionClient lfvClient, String projectName, String
prediction = "Prediction: Abnormal";
}

// Convert prediction to percentage
// Convert prediction to percentage.
NumberFormat defaultFormat = NumberFormat.getPercentInstance();
defaultFormat.setMinimumFractionDigits(1);
String confidence = String.format("Confidence: %s", defaultFormat.format(result.confidence()));

// Draw file name, prediction, and confidence on image
// Draw file name, prediction, and confidence on image.
String photoPath = "File: " + photo;
String[] imageLines = { photoPath, prediction, confidence };
drawImageInfo(imageLines);
Expand Down Expand Up @@ -174,7 +174,7 @@ private String getImageType(byte[] image) throws IOException {
if (mimeType.equals("image/jpeg") || mimeType.equals("image/png")) {
return mimeType;
}
// not a supported file type.
// Not a supported file type.
logger.log(Level.SEVERE, "Unsupported image type: {0}", mimeType);
throw new IOException(String.format("Wrong image type. %s format isn't supported.", mimeType));
}
Expand All @@ -189,9 +189,9 @@ public static void main(String[] args) throws Exception {
"Usage:\n" +
" DetectAnomalies <project> <version> <image> \n\n" +
"Where:\n" +
" project - the Lookout for Vision project.\n\n" +
" version - the version of the model within the project.\n\n" +
" image - the path and filename of a local image. \n\n";
" project - The Lookout for Vision project.\n\n" +
" version - The version of the model within the project.\n\n" +
" image - The path and filename of a local image. \n\n";

try {

Expand Down
Loading

0 comments on commit 638bca0

Please sign in to comment.