用法:
torch.nn.utils.prune.custom_from_mask(module, name, mask)
module(torch.nn.Module) -包含要修剪的张量的模块
name(str) -
module
中的参数名称,将对其进行修剪。mask(Tensor) -要应用于参数的二进制掩码。
输入模块的修改(即修剪)版本
模块(nn.Module)
通过在
mask
中应用预先计算的掩码,修剪与module
中名为name
的参数对应的张量。通过以下方式修改模块(并返回修改后的模块):添加一个名为
name+'_mask'
的命名缓冲区,该缓冲区对应于通过修剪方法应用于参数name
的二进制掩码。将参数
name
替换为其修剪版本,而原始(未修剪)参数存储在名为name+'_orig'
的新参数中。
例子
>>> m = prune.custom_from_mask( nn.Linear(5, 3), name='bias', mask=torch.tensor([0, 1, 0]) ) >>> print(m.bias_mask) tensor([0., 1., 0.])
参数:
返回:
返回类型:
相关用法
- Python torch.nn.utils.prune.random_structured用法及代码示例
- Python torch.nn.utils.prune.is_pruned用法及代码示例
- Python torch.nn.utils.prune.random_unstructured用法及代码示例
- Python torch.nn.utils.prune.global_unstructured用法及代码示例
- Python torch.nn.utils.prune.l1_unstructured用法及代码示例
- Python torch.nn.utils.prune.identity用法及代码示例
- Python torch.nn.utils.prune.remove用法及代码示例
- Python torch.nn.utils.prune.ln_structured用法及代码示例
- Python torch.nn.utils.parametrize.register_parametrization用法及代码示例
- Python torch.nn.utils.parametrizations.orthogonal用法及代码示例
- Python torch.nn.utils.parametrize.cached用法及代码示例
- Python torch.nn.utils.parametrizations.spectral_norm用法及代码示例
- Python torch.nn.utils.spectral_norm用法及代码示例
- Python torch.nn.utils.rnn.pad_sequence用法及代码示例
- Python torch.nn.utils.remove_spectral_norm用法及代码示例
- Python torch.nn.utils.rnn.pad_packed_sequence用法及代码示例
- Python torch.nn.utils.skip_init用法及代码示例
- Python torch.nn.utils.rnn.pack_sequence用法及代码示例
- Python torch.nn.utils.remove_weight_norm用法及代码示例
- Python torch.nn.utils.weight_norm用法及代码示例
注:本文由纯净天空筛选整理自pytorch.org大神的英文原创作品 torch.nn.utils.prune.custom_from_mask。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。