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;
}
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;
}
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;
}
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;
}
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"));
}
}
}
Aggregations