-
Notifications
You must be signed in to change notification settings - Fork 654
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Organize BasicDatasets into folders (#518)
This divides them into the folders: - cv - cv.classification - nlp - tabular Change-Id: Ic925c69caae628d95d33f010e62c14bdb5ae6d17
- Loading branch information
Showing
60 changed files
with
234 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...taset/src/main/java/ai/djl/basicdataset/cv/classification/ImageClassificationDataset.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance | ||
* with the License. A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0/ | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions | ||
* and limitations under the License. | ||
*/ | ||
package ai.djl.basicdataset.cv.classification; | ||
|
||
import ai.djl.modality.cv.Image; | ||
import ai.djl.ndarray.NDList; | ||
import ai.djl.ndarray.NDManager; | ||
import ai.djl.training.dataset.RandomAccessDataset; | ||
import ai.djl.training.dataset.Record; | ||
import java.io.IOException; | ||
|
||
/** | ||
* A helper to create {@link ai.djl.training.dataset.Dataset}s for {@link | ||
* ai.djl.Application.CV#IMAGE_CLASSIFICATION}. | ||
*/ | ||
public abstract class ImageClassificationDataset extends RandomAccessDataset { | ||
|
||
Image.Flag flag; | ||
|
||
/** | ||
* Creates a new instance of {@link RandomAccessDataset} with the given necessary | ||
* configurations. | ||
* | ||
* @param builder a builder with the necessary configurations | ||
*/ | ||
public ImageClassificationDataset(BaseBuilder<?> builder) { | ||
super(builder); | ||
this.flag = builder.flag; | ||
} | ||
|
||
/** | ||
* Returns the image at the given index in the dataset. | ||
* | ||
* @param index the index (if the dataset is a list of data items) | ||
* @return the image | ||
* @throws IOException if the image could not be loaded | ||
*/ | ||
protected abstract Image getImage(long index) throws IOException; | ||
|
||
/** | ||
* Returns the class of the data item at the given index. | ||
* | ||
* @param index the index (if the dataset is a list of data items) | ||
* @return the class number or the index into the list of classes of the desired class name | ||
* @throws IOException if the data could not be loaded | ||
*/ | ||
protected abstract long getClassNumber(long index) throws IOException; | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public Record get(NDManager manager, long index) throws IOException { | ||
NDList data = new NDList(getImage(index).toNDArray(manager, flag)); | ||
NDList label = new NDList(manager.create(getClassNumber(index))); | ||
return new Record(data, label); | ||
} | ||
|
||
/** | ||
* Used to build an {@link ImageClassificationDataset}. | ||
* | ||
* @param <T> the builder type | ||
*/ | ||
@SuppressWarnings("rawtypes") | ||
public abstract static class BaseBuilder<T extends BaseBuilder<T>> | ||
extends RandomAccessDataset.BaseBuilder<T> { | ||
|
||
Image.Flag flag; | ||
|
||
protected BaseBuilder() { | ||
flag = Image.Flag.COLOR; | ||
} | ||
|
||
/** | ||
* Sets the optional color mode flag. | ||
* | ||
* @param flag the color mode flag | ||
* @return this builder | ||
*/ | ||
public T optFlag(Image.Flag flag) { | ||
this.flag = flag; | ||
return self(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
basicdataset/src/main/java/ai/djl/basicdataset/cv/classification/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance | ||
* with the License. A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0/ | ||
* | ||
* or in the "license" file accompanying this file. This file 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. | ||
*/ | ||
|
||
/** | ||
* Contains a library of built-in datasets for {@link ai.djl.Application.CV#IMAGE_CLASSIFICATION}. | ||
*/ | ||
package ai.djl.basicdataset.cv.classification; |
15 changes: 15 additions & 0 deletions
15
basicdataset/src/main/java/ai/djl/basicdataset/cv/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance | ||
* with the License. A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0/ | ||
* | ||
* or in the "license" file accompanying this file. This file 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. | ||
*/ | ||
|
||
/** Contains a library of built-in datasets for {@link ai.djl.Application.CV}. */ | ||
package ai.djl.basicdataset.cv; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
basicdataset/src/main/java/ai/djl/basicdataset/nlp/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance | ||
* with the License. A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0/ | ||
* | ||
* or in the "license" file accompanying this file. This file 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. | ||
*/ | ||
|
||
/** Contains a library of built-in datasets for {@link ai.djl.Application.NLP}. */ | ||
package ai.djl.basicdataset.nlp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.