Skip to content

Commit 4c7aeb0

Browse files
abatterytensorflower-gardener
authored andcommitted
Fix crashing on unknown rank tensors at creating protobuf for converter backend
PiperOrigin-RevId: 341981639 Change-Id: I50b229d622beefca1abcfe6db6d9e77f0591902d
1 parent 4fee5e9 commit 4c7aeb0

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

tensorflow/lite/python/convert.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,16 @@ def build_toco_convert_protos(input_tensors,
492492
else:
493493
shape = input_shapes[idx]
494494

495-
# Create shapes with -1 for unknown dimensions.
496-
dims = []
497-
for dim in shape:
498-
if (dim is None or
499-
(isinstance(dim, tensor_shape.Dimension) and dim.value is None)):
500-
dims.append(-1)
501-
else:
502-
dims.append(int(dim))
503-
input_array.shape.dims.extend(dims)
495+
if shape.rank is not None:
496+
# Create shapes with -1 for unknown dimensions.
497+
dims = []
498+
for dim in shape:
499+
if (dim is None or
500+
(isinstance(dim, tensor_shape.Dimension) and dim.value is None)):
501+
dims.append(-1)
502+
else:
503+
dims.append(int(dim))
504+
input_array.shape.dims.extend(dims)
504505

505506
for output_tensor in output_tensors:
506507
if saved_model_dir:

0 commit comments

Comments
 (0)