這個卷積名字起得花裡胡哨的,其實總結起來就是輸入通道每個通道乙個卷積得到和輸入通道數相同的特徵圖,然後再使用若干個1*1的卷積聚合每個特徵圖的值得到輸出特徵圖。
假設我們輸入通道是16,輸出特徵圖是32,並且使用3*3的卷積提取特徵,那麼第一步一共需要16*3*3個引數,第二步需要32*16*1*1個引數,一共需要16*3*3+32*16*1*1=656個引數。
使用傳統的方法進行卷積一共需要32*16*3*3=4608個引數。
可見sep conv在計算量上有明顯的優勢,下面就是pytorch實現的sep conv卷積
import torch
import torch.nn as nn
class
sepconv
(nn.module)
:def
__init__
(self, in_channel, out_channel, kernel_size, stride, padding)
:super()
.__init__(
) self.conv1 = nn.conv2d(in_channel, in_channel,kernel_size,stride,padding, groups=in_channel)
self.conv2 = nn.conv2d(in_channel, out_channel, kernel_size=
1,stride=
1,padding=0)
defforward
(self,
input):
x = self.conv1(
input
)print
(self.conv1.weight.data.shape)
x = self.conv2(x)
print
(self.conv2.weight.data.shape)
return x
if __name__ ==
"__main__"
:input
= torch.rand(2,
16,600,
800)
sep = sepconv(16,
32,3,
1,1)
output = sep(
input
)
輸出結果如下
Pytorch 通過pytorch實現線性回歸
linear regression 線性回歸是分析乙個變數與另外乙個 多個 變數之間關係的方法 因變數 y 自變數 x 關係 線性 y wx b 分析 求解w,b 求解步驟 1.確定模型 2.選擇損失函式 3.求解梯度並更新w,b 此題 1.model y wx b 下為 實現 import tor...
pytorch實現分類
完整 實現分類 import torch import torch.nn.functional as f from torch.autograd import variable import matplotlib.pyplot as plt import torch.optim as optim 生...
pytorch 實現多層網路
import torch import torch.nn as nn import torch.nn.init as init import torch.nn.functional as f import math 讀取資料集 pima indians diabetes資料集 import pand...