Skip to content

Fix for empty SavedModelBundle tags #611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,25 @@ public void export() throws IOException {
private final Map<String, SessionFunction> functions = new LinkedHashMap<>();
}

/**
* Load a saved model from an export directory. The model that is being loaded should be created
* using the <a href="https://www.tensorflow.org/api_docs/python/tf/saved_model">Saved Model
* API</a>.
*
* <p>This method is a shorthand for:
*
* <pre>{@code
* SavedModelBundle.loader().load();
* }</pre>
*
* @param exportDir the directory path containing a saved model.
* @return a bundle containing the graph and associated session.
*/
public static SavedModelBundle load(String exportDir) {
Loader loader = loader(exportDir);
return loader.load();
}

/**
* Load a saved model from an export directory. The model that is being loaded should be created
* using the <a href="https://www.tensorflow.org/api_docs/python/tf/saved_model">Saved Model
Expand All @@ -329,9 +348,7 @@ public void export() throws IOException {
*/
public static SavedModelBundle load(String exportDir, String... tags) {
Loader loader = loader(exportDir);
if (tags != null && tags.length > 0) {
loader.withTags(tags);
}
loader.withTags(tags);
return loader.load();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public class SavedModelBundleTest {

@Test
public void load() {
try (SavedModelBundle bundle = SavedModelBundle.load(SAVED_MODEL_PATH)) {
assertNotNull(bundle.session());
assertNotNull(bundle.graph());
assertNotNull(bundle.metaGraphDef());
}
try (SavedModelBundle bundle = SavedModelBundle.load(SAVED_MODEL_PATH, "serve")) {
assertNotNull(bundle.session());
assertNotNull(bundle.graph());
Expand Down
Loading