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 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 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);
prepared = true;
}
use of ai.djl.repository.Artifact in project djl by deepjavalibrary.
the class DailyDelhiClimate 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 csvFile;
switch(usage) {
case TRAIN:
csvFile = root.resolve("DailyDelhiClimateTrain.csv");
break;
case TEST:
csvFile = root.resolve("DailyDelhiClimateTest.csv");
break;
case VALIDATION:
default:
throw new UnsupportedOperationException("Validation data not available.");
}
csvUrl = csvFile.toUri().toURL();
super.prepare(progress);
prepared = true;
}
use of ai.djl.repository.Artifact in project djl by deepjavalibrary.
the class Librispeech method prepare.
/**
* Prepares the dataset for use with tracked progress.
*
* @param progress the progress tracker
* @throws IOException for various exceptions depending on the dataset
*/
@Override
public void prepare(Progress progress) throws IOException, TranslateException {
if (prepared) {
return;
}
Artifact artifact = mrl.getDefaultArtifact();
mrl.prepare(artifact, progress);
Artifact.Item item;
String subPath;
switch(usage) {
case TRAIN:
item = artifact.getFiles().get("train");
subPath = "LibriSpeech/test-clean-100";
break;
case TEST:
item = artifact.getFiles().get("test");
subPath = "LibriSpeech/test-clean";
break;
default:
throw new UnsupportedOperationException("Unsupported usage type.");
}
File mainDir = mrl.getRepository().getFile(item, subPath).toFile();
File[] subDirs = mainDir.listFiles();
if (subDirs == null) {
return;
}
List<String> lineArray = new ArrayList<>();
List<String> audioPaths = new ArrayList<>();
for (File subDir : subDirs) {
File[] subSubDirs = subDir.listFiles();
String subDirName = subDir.getName();
if (subSubDirs == null) {
return;
}
for (File subSubDir : subSubDirs) {
String subSubDirName = subSubDir.getName();
File transFile = new File(String.format("%s/%s-%s.trans.txt", subSubDir.getAbsolutePath(), subDirName, subSubDirName));
try (BufferedReader reader = Files.newBufferedReader(transFile.toPath())) {
String row;
while ((row = reader.readLine()) != null) {
if (row.contains(" ")) {
String trans = row.substring(row.indexOf(' ') + 1);
String label = row.substring(0, row.indexOf(' '));
String audioIndex = label.split("-")[2];
String audioPath = String.format("%s/%s-%s-%s.flac", subSubDir.getAbsolutePath(), subDirName, subSubDirName, audioIndex);
audioPaths.add(audioPath);
lineArray.add(trans);
}
}
}
}
}
targetPreprocess(lineArray);
sourcePreprocess(audioPaths);
prepared = true;
}
Aggregations