[5d8f6c]: / CaraNet / lib / conv_layer.py

Download this file

44 lines (31 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 10 17:12:46 2021
@author: angelou
"""
import torch
import torch.nn as nn
import torch.nn.functional as F
class Conv(nn.Module):
def __init__(self, nIn, nOut, kSize, stride, padding, dilation=(1, 1), groups=1, bn_acti=False, bias=False):
super().__init__()
self.bn_acti = bn_acti
self.conv = nn.Conv2d(nIn, nOut, kernel_size = kSize,
stride=stride, padding=padding,
dilation=dilation,groups=groups,bias=bias)
if self.bn_acti:
self.bn_relu = BNPReLU(nOut)
def forward(self, input):
output = self.conv(input)
if self.bn_acti:
output = self.bn_relu(output)
return output
class BNPReLU(nn.Module):
def __init__(self, nIn):
super().__init__()
self.bn = nn.BatchNorm2d(nIn, eps=1e-3)
self.acti = nn.PReLU(nIn)
def forward(self, input):
output = self.bn(input)
output = self.acti(output)
return output