in tensorflow_hub/image_util.py [0:0]
def get_expected_image_size(module_or_spec, signature=None, input_name=None):
"""Returns expected [height, width] dimensions of an image input.
TODO(b/139530454): This does not work yet with TF2.
Args:
module_or_spec: a Module or ModuleSpec that accepts image inputs.
signature: a string with the key of the signature in question.
If None, the default signature is used.
input_name: a string with the input name for images. If None, the
conventional input name `images` for the default signature is used.
Returns:
A list if integers `[height, width]`.
Raises:
ValueError: If the size information is missing or malformed.
"""
# First see if an attached ImageModuleInfo provides this information.
image_module_info = get_image_module_info(module_or_spec)
if image_module_info:
size = image_module_info.default_image_size
if size.height and size.width:
return [size.height, size.width]
# Else inspect the input shape in the module signature.
if input_name is None:
input_name = "images"
input_info_dict = module_or_spec.get_input_info_dict(signature)
try:
shape = input_info_dict[input_name].get_shape()
except KeyError:
raise ValueError("Module is missing input '%s' in signature '%s'." %
(input_name, signature or "default"))
try:
_, height, width, _ = shape.as_list()
if not height or not width:
raise ValueError
except ValueError:
raise ValueError(
"Shape of module input is %s, "
"expected [batch_size, height, width, num_channels] "
"with known height and width." % shape)
return [height, width]