Search in sources :

Example 26 with Artifact

use of ai.djl.repository.Artifact in project djl by deepjavalibrary.

the class CocoDetection method prepare.

/**
 * {@inheritDoc}
 */
@Override
public void prepare(Progress progress) throws IOException {
    if (prepared) {
        return;
    }
    Artifact artifact = mrl.getDefaultArtifact();
    mrl.prepare(artifact, progress);
    Path root = mrl.getRepository().getResourceDirectory(artifact);
    Path jsonFile;
    switch(usage) {
        case TRAIN:
            jsonFile = root.resolve("annotations").resolve("instances_train2017.json");
            break;
        case TEST:
            jsonFile = root.resolve("annotations").resolve("instances_val2017.json");
            break;
        case VALIDATION:
        default:
            throw new UnsupportedOperationException("Validation data not available.");
    }
    CocoUtils coco = new CocoUtils(jsonFile);
    coco.prepare();
    List<Long> imageIds = coco.getImageIds();
    for (long id : imageIds) {
        Path imagePath = root.resolve(coco.getRelativeImagePath(id));
        PairList<Long, Rectangle> labelOfImageId = getLabels(coco, id);
        if (!labelOfImageId.isEmpty()) {
            imagePaths.add(imagePath);
            labels.add(labelOfImageId);
        }
    }
    prepared = true;
}
Also used : Path(java.nio.file.Path) Rectangle(ai.djl.modality.cv.output.Rectangle) Artifact(ai.djl.repository.Artifact)

Example 27 with Artifact

use of ai.djl.repository.Artifact in project djl by deepjavalibrary.

the class TatoebaEnglishFrenchDataset method prepare.

/**
 * {@inheritDoc}
 */
@Override
public void prepare(Progress progress) throws IOException, EmbeddingException {
    if (prepared) {
        return;
    }
    Artifact artifact = mrl.getDefaultArtifact();
    mrl.prepare(artifact, progress);
    Path root = mrl.getRepository().getResourceDirectory(artifact);
    Path usagePath;
    switch(usage) {
        case TRAIN:
            usagePath = Paths.get("fra-eng-train.txt");
            break;
        case TEST:
            usagePath = Paths.get("fra-eng-test.txt");
            break;
        case VALIDATION:
        default:
            throw new UnsupportedOperationException("Validation data not available.");
    }
    usagePath = root.resolve(usagePath);
    List<String> sourceTextData = new ArrayList<>();
    List<String> targetTextData = new ArrayList<>();
    try (BufferedReader reader = Files.newBufferedReader(usagePath)) {
        String row;
        while ((row = reader.readLine()) != null) {
            String[] text = row.split("\t");
            sourceTextData.add(text[0]);
            targetTextData.add(text[1]);
        }
    }
    preprocess(sourceTextData, true);
    preprocess(targetTextData, false);
    prepared = true;
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) Artifact(ai.djl.repository.Artifact)

Example 28 with Artifact

use of ai.djl.repository.Artifact in project djl by deepjavalibrary.

the class AirfoilRandomAccess method prepare.

/**
 * {@inheritDoc}
 */
@Override
public void prepare(Progress progress) throws IOException {
    if (prepared) {
        return;
    }
    Artifact artifact = mrl.getDefaultArtifact();
    mrl.prepare(artifact);
    Path root = mrl.getRepository().getResourceDirectory(artifact);
    Path csvFile;
    switch(usage) {
        case TRAIN:
            csvFile = root.resolve("airfoil_self_noise.dat");
            break;
        case TEST:
            throw new UnsupportedOperationException("Test data not available.");
        case VALIDATION:
        default:
            throw new UnsupportedOperationException("Validation data not available.");
    }
    csvUrl = csvFile.toUri().toURL();
    super.prepare(progress);
    if (normalize) {
        mean = new HashMap<>();
        std = new HashMap<>();
        for (Feature feature : features) {
            calculateMean(feature.getName());
            calculateStd(feature.getName());
        }
        for (Feature feature : labels) {
            calculateMean(feature.getName());
            calculateStd(feature.getName());
        }
    }
    prepared = true;
}
Also used : Path(java.nio.file.Path) Artifact(ai.djl.repository.Artifact)

Example 29 with Artifact

use of ai.djl.repository.Artifact in project djl by deepjavalibrary.

the class CaptchaDataset method prepare.

/**
 * {@inheritDoc}
 */
@Override
public void prepare(Progress progress) throws IOException {
    if (prepared) {
        return;
    }
    Artifact artifact = mrl.getDefaultArtifact();
    mrl.prepare(artifact, progress);
    dataItem = artifact.getFiles().get("data");
    pathPrefix = getUsagePath();
    items = new ArrayList<>();
    for (String filenameWithExtension : mrl.getRepository().listDirectory(dataItem, pathPrefix)) {
        String captchaFilename = filenameWithExtension.substring(0, filenameWithExtension.lastIndexOf('.'));
        items.add(captchaFilename);
    }
    prepared = true;
}
Also used : Artifact(ai.djl.repository.Artifact)

Example 30 with Artifact

use of ai.djl.repository.Artifact in project djl by deepjavalibrary.

the class ModelZooTest method testDownloadModels.

@Test
public void testDownloadModels() throws IOException, ModelException {
    TestRequirements.nightly();
    TestRequirements.notOffline();
    TestRequirements.weekly();
    for (ModelZoo zoo : ModelZoo.listModelZoo()) {
        for (ModelLoader modelLoader : zoo.getModelLoaders()) {
            List<Artifact> artifacts = modelLoader.listModels();
            for (Artifact artifact : artifacts) {
                Criteria<NDList, NDList> criteria = Criteria.builder().setTypes(NDList.class, NDList.class).optFilters(artifact.getProperties()).build();
                Model model = modelLoader.loadModel(criteria);
                model.close();
            }
            Utils.deleteQuietly(Paths.get("build/cache"));
        }
    }
}
Also used : ModelLoader(ai.djl.repository.zoo.ModelLoader) ModelZoo(ai.djl.repository.zoo.ModelZoo) NDList(ai.djl.ndarray.NDList) Model(ai.djl.Model) Artifact(ai.djl.repository.Artifact) Test(org.testng.annotations.Test)

Aggregations

Artifact (ai.djl.repository.Artifact)33 Path (java.nio.file.Path)15 MRL (ai.djl.repository.MRL)10 Test (org.testng.annotations.Test)9 Repository (ai.djl.repository.Repository)8 Metadata (ai.djl.repository.Metadata)7 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 List (java.util.List)4 Application (ai.djl.Application)3 Model (ai.djl.Model)3 Rectangle (ai.djl.modality.cv.output.Rectangle)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Point (ai.djl.modality.cv.output.Point)2 PairList (ai.djl.util.PairList)2 Progress (ai.djl.util.Progress)2 Reader (java.io.Reader)2 Type (java.lang.reflect.Type)2 Map (java.util.Map)2 FtModel (ai.djl.fasttext.FtModel)1