def variable(value, dtype=_FLOATX, name=None):
'''Instantiates a tensor.
# Arguments
value: numpy array, initial value of the tensor.
dtype: tensor type.
name: optional name string for the tensor.
# Returns
Tensor variable instance.
'''
if hasattr(value, 'tocoo'):
sparse_coo = value.tocoo()
indices = np.concatenate((np.expand_dims(sparse_coo.row, 1),
np.expand_dims(sparse_coo.col, 1)), 1)
# SparseTensor doesn't need initialization
v = tf.SparseTensor(indices=indices, values=sparse_coo.data, shape=sparse_coo.shape)
v._dims = len(sparse_coo.shape)
return v
v = tf.Variable(value, dtype=_convert_string_dtype(dtype), name=name)
return v
评论列表
文章目录