tensorflow_backend.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:keras 作者: GeekLiB 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号