in tensorflow_hub/feature_column.py [0:0]
def _check_module_is_image_embedding(module_spec, check_image_size):
"""Raises ValueError if `module_spec` is not usable as image embedding.
Args:
module_spec: A `_ModuleSpec` to test.
check_image_size: Whether to check for compatibility with
get_expected_image_size.
Raises:
ValueError: if `module_spec` default signature is not compatible with
mappingan "images" input to a Tensor(float32, shape=(_,K)).
"""
issues = []
# Find issues with "default" signature inputs. The common signatures for
# image models prescribe a specific name; we trust it if we find it
# and if we can do the necessary inference of input shapes from it.
input_info_dict = module_spec.get_input_info_dict()
if (list(input_info_dict.keys()) != ["images"] or
input_info_dict["images"].dtype != tf.float32):
issues.append("Module 'default' signature must require a single input, "
"which must have type float32 and name 'images'.")
else:
try:
if check_image_size:
image_util.get_expected_image_size(module_spec)
except ValueError as e:
issues.append("Module does not support hub.get_expected_image_size(); "
"original error was:\n" + str(e)) # Raised again below.
# Find issues with "default" signature outputs. We test that the dtype and
# shape is appropriate for use in input_layer().
output_info_dict = module_spec.get_output_info_dict()
if "default" not in output_info_dict:
issues.append("Module 'default' signature must have a 'default' output.")
else:
output_type = output_info_dict["default"].dtype
output_shape = output_info_dict["default"].get_shape()
if not (output_type == tf.float32 and output_shape.ndims == 2 and
output_shape.dims[1].value):
issues.append("Module 'default' signature must have a 'default' output "
"of tf.Tensor(shape=(_,K), dtype=float32).")
if issues:
raise ValueError("Module is not usable as image embedding: %r" % issues)