def placeholder(shape=None, ndim=None, dtype=_FLOATX, name=None):
'''Instantiate an input data placeholder variable.
'''
if shape is None and ndim is None:
raise Exception('Specify either a shape or ndim value.')
if shape is not None:
ndim = len(shape)
broadcast = (False,) * ndim
# ====== Modify add name prefix ====== #
global _PLACEHOLDER_ID
name_prefix = 'ID.%02d.' % _PLACEHOLDER_ID
_PLACEHOLDER_ID += 1
if name is None:
name = ''
name = name_prefix + name
placeholder = T.TensorType(dtype, broadcast)(name)
# store the predefined shape of placeholder
_PLACEHOLDER_SHAPE[name] = \
[None for _ in range(ndim)] if shape is None else shape
return placeholder
评论列表
文章目录