def _placeholdes_from_input_spec()

in source/python/neuropod/utils/randomify.py [0:0]


def _placeholdes_from_input_spec(input_spec, input_prefix="INPUT_API"):
    """Creates tf.placeholder for each of the entries in the input_spec. Returns a dictionary with the
    mapping neuropod input name to the fully qualified tensorflow tensor name"""
    node_name_mapping = dict()
    with tf.name_scope(input_prefix):
        for tensor_spec in input_spec:
            name = tensor_spec["name"]

            symbolic_shape = tensor_spec["shape"]
            # When a shape is defined by a string symbol, it means it's a variable intput.
            shape = tuple(
                (None if isinstance(d, string_types) else d for d in symbolic_shape)
            )

            # Translate string name to numpy type and the to TF dtype
            numpy_dtype = tensor_spec["dtype"]
            tf_dtype = tf.as_dtype(get_dtype(numpy_dtype))

            placeholder = tf.placeholder(tf_dtype, name=name, shape=shape)

            node_name_mapping[name] = placeholder.name

    return node_name_mapping