用法:
mxnet.contrib.autograd.grad(func, argnum=None)
- func:(
a python function
) - 前向(損失)函數。 - argnum:(
an int
or
a list of int
) - 計算梯度的參數索引。
- func:(
grad_func:- 一個計算參數梯度的函數。
一個python函數
參數:
返回:
返回類型:
返回計算參數梯度的函數。
例子:
>>> # autograd supports dynamic graph which is changed >>> # every instance >>> def func(x): >>> r = random.randint(0, 1) >>> if r % 2: >>> return x**2 >>> else: >>> return x/3 >>> # use `grad(func)` to get the gradient function >>> for x in range(10): >>> grad_func = grad(func) >>> inputs = nd.array([[1, 2, 3], [4, 5, 6]]) >>> grad_vals = grad_func(inputs)
相關用法
- Python mxnet.contrib.ndarray.index_copy用法及代碼示例
- Python mxnet.contrib.symbol.SparseEmbedding用法及代碼示例
- Python mxnet.contrib.symbol.edge_id用法及代碼示例
- Python mxnet.contrib.symbol.dgl_graph_compact用法及代碼示例
- Python mxnet.contrib.symbol.dgl_adjacency用法及代碼示例
- Python mxnet.contrib.ndarray.hawkesll用法及代碼示例
- Python mxnet.contrib.ndarray.SparseEmbedding用法及代碼示例
- Python mxnet.contrib.ndarray.ifft用法及代碼示例
- Python mxnet.contrib.ndarray.group_adagrad_update用法及代碼示例
- Python mxnet.contrib.ndarray.fft用法及代碼示例
- Python mxnet.contrib.ndarray.boolean_mask用法及代碼示例
- Python mxnet.contrib.symbol.dgl_csr_neighbor_non_uniform_sample用法及代碼示例
- Python mxnet.contrib.ndarray.dgl_subgraph用法及代碼示例
- Python mxnet.contrib.tensorboard.LogMetricsCallback用法及代碼示例
- Python mxnet.contrib.io.DataLoaderIter用法及代碼示例
- Python mxnet.contrib.symbol.ifft用法及代碼示例
- Python mxnet.contrib.symbol.count_sketch用法及代碼示例
- Python mxnet.contrib.symbol.fft用法及代碼示例
- Python mxnet.contrib.symbol.ModulatedDeformableConvolution用法及代碼示例
- Python mxnet.contrib.ndarray.edge_id用法及代碼示例
注:本文由純淨天空篩選整理自apache.org大神的英文原創作品 mxnet.contrib.autograd.grad。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。