use of ai.djl.repository.Artifact in project djl by deepjavalibrary.
the class HdfsRepositoryTest method testAccessDeny.
@Test
public void testAccessDeny() throws IOException {
int port = miniDfs.getNameNodePort();
Repository repo = Repository.newInstance("hdfs", "hdfs://localhost:" + port + "/non-exists");
List<MRL> list = repo.getResources();
Assert.assertTrue(list.isEmpty());
MRL mrl = repo.model(Application.UNDEFINED, "ai.djl.localmodelzoo", "mlp");
Artifact artifact = repo.resolve(mrl, null);
Assert.assertNull(artifact);
}
use of ai.djl.repository.Artifact in project djl by deepjavalibrary.
the class TextClassificationModelLoader method loadModel.
/**
* {@inheritDoc}
*/
@Override
public <I, O> ZooModel<I, O> loadModel(Criteria<I, O> criteria) throws ModelNotFoundException, IOException, MalformedModelException {
Artifact artifact = mrl.match(criteria.getFilters());
if (artifact == null) {
throw new ModelNotFoundException("No matching filter found");
}
Progress progress = criteria.getProgress();
mrl.prepare(artifact, progress);
if (progress != null) {
progress.reset("Loading", 2);
progress.update(1);
}
String modelName = criteria.getModelName();
if (modelName == null) {
modelName = artifact.getName();
}
Model model = new FtModel(modelName);
Path modelPath = mrl.getRepository().getResourceDirectory(artifact);
model.load(modelPath, modelName, criteria.getOptions());
return new ZooModel<>(model, new PassthroughTranslator<>());
}
use of ai.djl.repository.Artifact in project djl by deepjavalibrary.
the class AmesRandomAccess method prepare.
/**
* {@inheritDoc}
*/
@Override
public void prepare(Progress progress) throws IOException {
if (prepared) {
return;
}
Artifact artifact = mrl.getDefaultArtifact();
mrl.prepare(artifact, progress);
Path dir = mrl.getRepository().getResourceDirectory(artifact);
Path root = dir.resolve("house-prices-advanced-regression-techniques");
Path csvFile;
switch(usage) {
case TRAIN:
csvFile = root.resolve("train.csv");
break;
case TEST:
csvFile = root.resolve("test.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 PikachuDetection 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 usagePath;
switch(usage) {
case TRAIN:
usagePath = Paths.get("train");
break;
case TEST:
usagePath = Paths.get("test");
break;
case VALIDATION:
default:
throw new UnsupportedOperationException("Validation data not available.");
}
usagePath = root.resolve(usagePath);
Path indexFile = usagePath.resolve("index.file");
try (Reader reader = Files.newBufferedReader(indexFile)) {
Type mapType = new TypeToken<Map<String, List<Float>>>() {
}.getType();
Map<String, List<Float>> metadata = JsonUtils.GSON.fromJson(reader, mapType);
for (Map.Entry<String, List<Float>> entry : metadata.entrySet()) {
String imgName = entry.getKey();
imagePaths.add(usagePath.resolve(imgName));
List<Float> label = entry.getValue();
long objectClass = label.get(4).longValue();
Rectangle objectLocation = new Rectangle(new Point(label.get(5), label.get(6)), label.get(7), label.get(8));
labels.add(objectClass, objectLocation);
}
}
prepared = true;
}
use of ai.djl.repository.Artifact in project djl by deepjavalibrary.
the class RepositoryTest method testSimpleRepositoryArchive.
@Test
public void testSimpleRepositoryArchive() throws IOException {
Repository repo = Repository.newInstance("archive", "build/models/test_model.zip");
List<MRL> resources = repo.getResources();
Assert.assertEquals(resources.size(), 1);
Metadata metadata = repo.locate(resources.get(0));
Assert.assertEquals(metadata.getApplication(), Application.UNDEFINED);
Assert.assertEquals(metadata.getGroupId(), DefaultModelZoo.GROUP_ID);
Assert.assertEquals(metadata.getArtifactId(), "test_model");
List<Artifact> artifacts = metadata.getArtifacts();
Assert.assertEquals(artifacts.size(), 1);
Artifact artifact = artifacts.get(0);
Assert.assertEquals(artifact.getName(), "test_model");
Map<String, Artifact.Item> files = artifact.getFiles();
Assert.assertEquals(files.size(), 1);
Artifact.Item item = files.get("test_model");
repo.prepare(artifact);
Path modelPath = repo.getResourceDirectory(artifact);
Assert.assertTrue(Files.exists(modelPath));
String[] list = repo.listDirectory(item, "test_dir");
Assert.assertEquals(list[0], "test_file.txt");
List<String> classes = Utils.readLines(repo.openStream(item, "synset.txt"));
Assert.assertEquals(classes.size(), 1);
Utils.deleteQuietly(modelPath);
}
Aggregations