本文簡要介紹python語言中 torch.nn.utils.prune.random_structured 的用法。
- 用法:- torch.nn.utils.prune.random_structured(module, name, amount, dim)
- module(torch.nn.Module) -包含要修剪的張量的模塊 
- name(str) - - module中的參數名稱,將對其進行修剪。
- amount(int或者float) -要修剪的參數數量。如果 - float,應介於 0.0 和 1.0 之間,表示要修剪的參數比例。如果- int,它表示要修剪的參數的絕對數量。
- dim(int) -dim 的索引,我們沿著該索引定義要修剪的通道。 
 
- 輸入模塊的修改(即修剪)版本 
- 模塊(nn.Module) 
- 通過沿隨機選擇的指定 - dim刪除指定的- amount通道(當前未修剪),修剪與- module中名為- name的參數相對應的張量。通過以下方式修改模塊(並返回修改後的模塊):- 添加一個名為 - name+'_mask'的命名緩衝區,該緩衝區對應於通過修剪方法應用於參數- name的二進製掩碼。
- 將參數 - name替換為其修剪版本,而原始(未修剪)參數存儲在名為- name+'_orig'的新參數中。
 - 例子 - >>> m = prune.random_structured( nn.Linear(5, 3), 'weight', amount=3, dim=1 ) >>> columns_pruned = int(sum(torch.sum(m.weight, dim=0) == 0)) >>> print(columns_pruned) 3
參數:
返回:
返回類型:
相關用法
- Python PyTorch random_split用法及代碼示例
- Python PyTorch random_unstructured用法及代碼示例
- Python PyTorch rand_split_train_val用法及代碼示例
- Python PyTorch randn用法及代碼示例
- Python PyTorch rand用法及代碼示例
- Python PyTorch randperm用法及代碼示例
- Python PyTorch randint用法及代碼示例
- Python PyTorch range用法及代碼示例
- Python PyTorch rad2deg用法及代碼示例
- Python PyTorch ravel用法及代碼示例
- Python PyTorch renorm用法及代碼示例
- Python PyTorch rpc_sync用法及代碼示例
- Python PyTorch reshape用法及代碼示例
- Python PyTorch real用法及代碼示例
- Python PyTorch rsqrt用法及代碼示例
- Python PyTorch rfftn用法及代碼示例
- Python PyTorch rpc_async用法及代碼示例
- Python PyTorch repeat_interleave用法及代碼示例
- Python PyTorch remove用法及代碼示例
- Python PyTorch read_vec_flt_ark用法及代碼示例
- Python PyTorch rfft用法及代碼示例
- Python PyTorch register_kl用法及代碼示例
- Python PyTorch read_vec_int_ark用法及代碼示例
- Python PyTorch round用法及代碼示例
- Python PyTorch resolve_neg用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.nn.utils.prune.random_structured。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
