def testConvertTensors(self): a = tf.placeholder(tf.int32, [None]) protomap = _make_signature({"a": a}, {}).inputs targets = tensor_info.parse_tensor_info_map(protomap) # convert constant in0 = [1, 2, 3] output = tensor_info.convert_dict_to_compatible_tensor({"a": in0}, targets) self.assertEquals(output["a"].dtype, a.dtype) # check sparsity in1 = tf.sparse_placeholder(tf.int32, []) with self.assertRaisesRegexp(TypeError, "dense"): tensor_info.convert_dict_to_compatible_tensor({"a": in1}, targets)
def _convert_dict_inputs(inputs, tensor_info_map): """Converts from inputs into dict of input tensors. This handles: - putting inputs into a dict, per _prepare_dict_inputs(), - converting all input values into tensors compatible with the expected input tensor (dtype, shape). - check sparse/non-sparse tensor types. Args: inputs: inputs fed to Module.__call__(). tensor_info_map: A map from string to `tensor_info.ParsedTensorInfo` describing the signature inputs. Returns: A dict of tensors to feed to the signature instantiation. Raises: TypeError: If it fails to convert the input values into a dict of tensors to feed to the signature instantiation. """ dict_inputs = _prepare_dict_inputs(inputs, tensor_info_map) return tensor_info.convert_dict_to_compatible_tensor( dict_inputs, tensor_info_map)