@@ -59,25 +59,27 @@ public final class AnimalsClassification {
|
||||
return new Classifications(names, probs);
|
||||
}
|
||||
|
||||
static Criteria<Image, Classifications> criteria;
|
||||
static ZooModel<Image, Classifications> rotateModel;
|
||||
static Predictor<Image, Classifications> classifier;
|
||||
|
||||
public static Classifications classfier(Image img)
|
||||
throws IOException, ModelException, TranslateException {
|
||||
|
||||
Criteria<Image, Classifications> criteria =
|
||||
Criteria.builder()
|
||||
.optEngine("PaddlePaddle")
|
||||
.setTypes(Image.class, Classifications.class)
|
||||
.optModelUrls("https://aias-home.oss-cn-beijing.aliyuncs.com/models/animals.zip")
|
||||
// .optModelUrls("/Users/calvin/model/animals/")
|
||||
.optModelName("inference")
|
||||
.optTranslator(new AnimalTranslator())
|
||||
.optProgress(new ProgressBar())
|
||||
.build();
|
||||
|
||||
try (ZooModel<Image, Classifications> rotateModel = ModelZoo.loadModel(criteria)) {
|
||||
try (Predictor<Image, Classifications> classifier = rotateModel.newPredictor()) {
|
||||
Classifications classifications = classifier.predict(img);
|
||||
return classifications;
|
||||
}
|
||||
}
|
||||
criteria =
|
||||
criteria == null
|
||||
? Criteria.builder()
|
||||
.optEngine("PaddlePaddle")
|
||||
.setTypes(Image.class, Classifications.class)
|
||||
.optModelUrls("https://aias-home.oss-cn-beijing.aliyuncs.com/models/animals.zip")
|
||||
// .optModelUrls("/Users/calvin/model/animals/")
|
||||
.optModelName("inference")
|
||||
.optTranslator(new AnimalTranslator())
|
||||
.optProgress(new ProgressBar())
|
||||
.build()
|
||||
: criteria;
|
||||
rotateModel = rotateModel == null ? ModelZoo.loadModel(criteria) : rotateModel;
|
||||
classifier = classifier == null ? rotateModel.newPredictor() : classifier;
|
||||
return classifier.predict(img);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,9 @@ public final class LightAnimalsClassification {
|
||||
Classifications.Classification item = items.get(i);
|
||||
double prob = item.getProbability();
|
||||
probArr[i] = prob;
|
||||
if (prob > max) max = prob;
|
||||
if (prob > max) {
|
||||
max = prob;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
@@ -69,7 +71,7 @@ public final class LightAnimalsClassification {
|
||||
.optProgress(new ProgressBar())
|
||||
.build();
|
||||
|
||||
try (ZooModel rotateModel = ModelZoo.loadModel(criteria)) {
|
||||
try (ZooModel<Image, Classifications> rotateModel = ModelZoo.loadModel(criteria)) {
|
||||
try (Predictor<Image, Classifications> classifier = rotateModel.newPredictor()) {
|
||||
Classifications classifications = classifier.predict(img);
|
||||
return classifications;
|
||||
|
||||
Reference in New Issue
Block a user