Skip to content

Commit

Permalink
[xgb] Add .xgb file extension support (#2810)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfliu committed Apr 26, 2024
1 parent f157d01 commit 7f109c3
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions engines/ml/xgboost/src/main/java/ai/djl/ml/xgboost/XgbModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ private Path findModelFile(String prefix) {
String fileName = file.toFile().getName();
if (fileName.endsWith(".json")) {
modelName = fileName.substring(0, fileName.length() - 5);
} else if (fileName.endsWith(".xgb")) {
modelName = fileName.substring(0, fileName.length() - 4);
} else {
modelName = fileName;
}
Expand All @@ -90,13 +92,22 @@ private Path findModelFile(String prefix) {
}
Path modelFile = modelDir.resolve(prefix);
if (Files.notExists(modelFile) || !Files.isRegularFile(modelFile)) {
if (prefix.endsWith(".json")) {
if (prefix.endsWith(".json") || prefix.endsWith(".xgb")) {
return null;
}
modelFile = modelDir.resolve(prefix + ".json");
if (Files.notExists(modelFile) || !Files.isRegularFile(modelFile)) {
return null;
if (Files.isRegularFile(modelFile)) {
return modelFile;
}
modelFile = modelDir.resolve(prefix + ".xgb");
if (Files.isRegularFile(modelFile)) {
return modelFile;
}
modelFile = modelDir.resolve("model.xgb");
if (Files.isRegularFile(modelFile)) {
return modelFile;
}
return null;
}
return modelFile;
}
Expand Down

0 comments on commit 7f109c3

Please sign in to comment.