Skip to content

Commit bbd74bb

Browse files
authored
Fix validateTags() bug (#133)
empty string array is a valid tag. TF 1.x model does not have any tags
1 parent a4f32dc commit bbd74bb

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/SavedModelBundle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ opts, runOpts, new BytePointer(exportDir), new PointerPointer(tags),
429429
}
430430

431431
private static void validateTags(String[] tags) {
432-
if (tags == null || tags.length == 0 || Arrays.stream(tags).anyMatch(t -> t == null || t.isEmpty())) {
432+
if (tags == null || Arrays.stream(tags).anyMatch(t -> t == null || t.isEmpty())) {
433433
throw new IllegalArgumentException("Invalid tags: " + Arrays.toString(tags));
434434
}
435435
}

tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/SavedModelBundleTest.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,7 @@ public void cannotExportMultipleFunctionsWithSameSignatureKey() throws IOExcepti
262262
@Test
263263
public void cannotExportOrImportInvalidTags() {
264264
assertThrows(IllegalArgumentException.class, () ->
265-
SavedModelBundle.loader("/").withTags()
266-
);
267-
assertThrows(IllegalArgumentException.class, () ->
268-
SavedModelBundle.loader("/").withTags(new String[]{})
265+
SavedModelBundle.loader("/").withTags(null)
269266
);
270267
assertThrows(IllegalArgumentException.class, () ->
271268
SavedModelBundle.loader("/").withTags(new String[]{"tag", null})
@@ -274,10 +271,7 @@ public void cannotExportOrImportInvalidTags() {
274271
SavedModelBundle.loader("/").withTags(new String[]{"tag", ""})
275272
);
276273
assertThrows(IllegalArgumentException.class, () ->
277-
SavedModelBundle.exporter("/").withTags()
278-
);
279-
assertThrows(IllegalArgumentException.class, () ->
280-
SavedModelBundle.exporter("/").withTags(new String[]{})
274+
SavedModelBundle.exporter("/").withTags(null)
281275
);
282276
assertThrows(IllegalArgumentException.class, () ->
283277
SavedModelBundle.exporter("/").withTags(new String[]{"tag", null})

0 commit comments

Comments
 (0)