def __init__(self):
init = {
'initialW': initializers.LeCunUniform(),
'initial_bias': initializers.Zero(),
}
super(VGG16Extractor300, self).__init__()
with self.init_scope():
self.conv8_1 = L.Convolution2D(256, 1, **init)
self.conv8_2 = L.Convolution2D(512, 3, stride=2, pad=1, **init)
self.conv9_1 = L.Convolution2D(128, 1, **init)
self.conv9_2 = L.Convolution2D(256, 3, stride=2, pad=1, **init)
self.conv10_1 = L.Convolution2D(128, 1, **init)
self.conv10_2 = L.Convolution2D(256, 3, **init)
self.conv11_1 = L.Convolution2D(128, 1, **init)
self.conv11_2 = L.Convolution2D(256, 3, **init)
python类Convolution2D()的实例源码
def __init__(self):
init = {
'initialW': initializers.LeCunUniform(),
'initial_bias': initializers.Zero(),
}
super(VGG16Extractor512, self).__init__()
with self.init_scope():
self.conv8_1 = L.Convolution2D(256, 1, **init)
self.conv8_2 = L.Convolution2D(512, 3, stride=2, pad=1, **init)
self.conv9_1 = L.Convolution2D(128, 1, **init)
self.conv9_2 = L.Convolution2D(256, 3, stride=2, pad=1, **init)
self.conv10_1 = L.Convolution2D(128, 1, **init)
self.conv10_2 = L.Convolution2D(256, 3, stride=2, pad=1, **init)
self.conv11_1 = L.Convolution2D(128, 1, **init)
self.conv11_2 = L.Convolution2D(256, 3, stride=2, pad=1, **init)
self.conv12_1 = L.Convolution2D(128, 1, **init)
self.conv12_2 = L.Convolution2D(256, 4, pad=1, **init)
def __init__(
self, n_class, aspect_ratios,
initialW=None, initial_bias=None):
self.n_class = n_class
self.aspect_ratios = aspect_ratios
super(Multibox, self).__init__()
with self.init_scope():
self.loc = chainer.ChainList()
self.conf = chainer.ChainList()
if initialW is None:
initialW = initializers.LeCunUniform()
if initial_bias is None:
initial_bias = initializers.Zero()
init = {'initialW': initialW, 'initial_bias': initial_bias}
for ar in aspect_ratios:
n = (len(ar) + 1) * 2
self.loc.add_link(L.Convolution2D(n * 4, 3, pad=1, **init))
self.conf.add_link(L.Convolution2D(
n * self.n_class, 3, pad=1, **init))
def __init__(self):
super(GoogLeNet, self).__init__(
conv1=L.Convolution2D(3, 64, 7, stride=2, pad=3),
conv2_reduce=L.Convolution2D(64, 64, 1),
conv2=L.Convolution2D(64, 192, 3, stride=1, pad=1),
inc3a=L.Inception(192, 64, 96, 128, 16, 32, 32),
inc3b=L.Inception(256, 128, 128, 192, 32, 96, 64),
inc4a=L.Inception(480, 192, 96, 208, 16, 48, 64),
inc4b=L.Inception(512, 160, 112, 224, 24, 64, 64),
inc4c=L.Inception(512, 128, 128, 256, 24, 64, 64),
inc4d=L.Inception(512, 112, 144, 288, 32, 64, 64),
inc4e=L.Inception(528, 256, 160, 320, 32, 128, 128),
inc5a=L.Inception(832, 256, 160, 320, 32, 128, 128),
inc5b=L.Inception(832, 384, 192, 384, 48, 128, 128),
loss3_fc=L.Linear(1024, 1000),
loss1_conv=L.Convolution2D(512, 128, 1),
loss1_fc1=L.Linear(4 * 4 * 128, 1024),
loss1_fc2=L.Linear(1024, 1000),
loss2_conv=L.Convolution2D(528, 128, 1),
loss2_fc1=L.Linear(4 * 4 * 128, 1024),
loss2_fc2=L.Linear(1024, 1000)
)
self.train = True
def __init__(self, in_size, ch, out_size, stride=2):
super(BottleNeckA, self).__init__()
initialW = initializers.HeNormal()
with self.init_scope():
self.conv1 = L.Convolution2D(
in_size, ch, 1, stride, 0, initialW=initialW, nobias=True)
self.bn1 = L.BatchNormalization(ch)
self.conv2 = L.Convolution2D(
ch, ch, 3, 1, 1, initialW=initialW, nobias=True)
self.bn2 = L.BatchNormalization(ch)
self.conv3 = L.Convolution2D(
ch, out_size, 1, 1, 0, initialW=initialW, nobias=True)
self.bn3 = L.BatchNormalization(out_size)
self.conv4 = L.Convolution2D(
in_size, out_size, 1, stride, 0,
initialW=initialW, nobias=True)
self.bn4 = L.BatchNormalization(out_size)
def __init__(self):
super(GoogLeNet, self).__init__()
with self.init_scope():
self.conv1 = L.Convolution2D(None, 64, 7, stride=2, pad=3)
self.conv2_reduce = L.Convolution2D(None, 64, 1)
self.conv2 = L.Convolution2D(None, 192, 3, stride=1, pad=1)
self.inc3a = L.Inception(None, 64, 96, 128, 16, 32, 32)
self.inc3b = L.Inception(None, 128, 128, 192, 32, 96, 64)
self.inc4a = L.Inception(None, 192, 96, 208, 16, 48, 64)
self.inc4b = L.Inception(None, 160, 112, 224, 24, 64, 64)
self.inc4c = L.Inception(None, 128, 128, 256, 24, 64, 64)
self.inc4d = L.Inception(None, 112, 144, 288, 32, 64, 64)
self.inc4e = L.Inception(None, 256, 160, 320, 32, 128, 128)
self.inc5a = L.Inception(None, 256, 160, 320, 32, 128, 128)
self.inc5b = L.Inception(None, 384, 192, 384, 48, 128, 128)
self.loss3_fc = L.Linear(None, 1000)
self.loss1_conv = L.Convolution2D(None, 128, 1)
self.loss1_fc1 = L.Linear(None, 1024)
self.loss1_fc2 = L.Linear(None, 1000)
self.loss2_conv = L.Convolution2D(None, 128, 1)
self.loss2_fc1 = L.Linear(None, 1024)
self.loss2_fc2 = L.Linear(None, 1000)
def __init__(self):
super(GoogLeNet, self).__init__(
conv1=L.Convolution2D(None, 64, 7, stride=2, pad=3),
conv2_reduce=L.Convolution2D(None, 64, 1),
conv2=L.Convolution2D(None, 192, 3, stride=1, pad=1),
inc3a=L.Inception(None, 64, 96, 128, 16, 32, 32),
inc3b=L.Inception(None, 128, 128, 192, 32, 96, 64),
inc4a=L.Inception(None, 192, 96, 208, 16, 48, 64),
inc4b=L.Inception(None, 160, 112, 224, 24, 64, 64),
inc4c=L.Inception(None, 128, 128, 256, 24, 64, 64),
inc4d=L.Inception(None, 112, 144, 288, 32, 64, 64),
inc4e=L.Inception(None, 256, 160, 320, 32, 128, 128),
inc5a=L.Inception(None, 256, 160, 320, 32, 128, 128),
inc5b=L.Inception(None, 384, 192, 384, 48, 128, 128),
loss3_fc=L.Linear(None, 1000),
loss1_conv=L.Convolution2D(None, 128, 1),
loss1_fc1=L.Linear(None, 1024),
loss1_fc2=L.Linear(None, 1000),
loss2_conv=L.Convolution2D(None, 128, 1),
loss2_fc1=L.Linear(None, 1024),
loss2_fc2=L.Linear(None, 1000)
)
self.train = True
def __init__(self):
self.dtype = np.float16
W = initializers.HeNormal(1 / np.sqrt(2), self.dtype)
bias = initializers.Zero(self.dtype)
chainer.Chain.__init__(
self,
conv1=L.Convolution2D(None, 96, 11,
stride=4, initialW=W, bias=bias),
conv2=L.Convolution2D(None, 256, 5, pad=2, initialW=W, bias=bias),
conv3=L.Convolution2D(None, 384, 3, pad=1, initialW=W, bias=bias),
conv4=L.Convolution2D(None, 384, 3, pad=1, initialW=W, bias=bias),
conv5=L.Convolution2D(None, 256, 3, pad=1, initialW=W, bias=bias),
fc6=L.Linear(None, 4096, initialW=W, bias=bias),
fc7=L.Linear(None, 4096, initialW=W, bias=bias),
fc8=L.Linear(None, 1000, initialW=W, bias=bias),
)
self.train = True
def __init__(self, bottom_width=4, ch=512, wscale=0.02):
w = chainer.initializers.Normal(wscale)
super(Discriminator, self).__init__()
with self.init_scope():
self.c0_0 = L.Convolution2D(3, ch // 8, 3, 1, 1, initialW=w)
self.c0_1 = L.Convolution2D(ch // 8, ch // 4, 4, 2, 1, initialW=w)
self.c1_0 = L.Convolution2D(ch // 4, ch // 4, 3, 1, 1, initialW=w)
self.c1_1 = L.Convolution2D(ch // 4, ch // 2, 4, 2, 1, initialW=w)
self.c2_0 = L.Convolution2D(ch // 2, ch // 2, 3, 1, 1, initialW=w)
self.c2_1 = L.Convolution2D(ch // 2, ch // 1, 4, 2, 1, initialW=w)
self.c3_0 = L.Convolution2D(ch // 1, ch // 1, 3, 1, 1, initialW=w)
self.l4 = L.Linear(bottom_width * bottom_width * ch, 1, initialW=w)
self.bn0_1 = L.BatchNormalization(ch // 4, use_gamma=False)
self.bn1_0 = L.BatchNormalization(ch // 4, use_gamma=False)
self.bn1_1 = L.BatchNormalization(ch // 2, use_gamma=False)
self.bn2_0 = L.BatchNormalization(ch // 2, use_gamma=False)
self.bn2_1 = L.BatchNormalization(ch // 1, use_gamma=False)
self.bn3_0 = L.BatchNormalization(ch // 1, use_gamma=False)
def __init__(self, n_class, in_ch, n_layer=12, growth_rate=12,
dropout_ratio=0.2, block=3):
in_chs = [in_ch + n_layer * growth_rate * i
for i in moves.range(block + 1)]
super(DenseBlock, self).__init__()
self.add_link(
'conv1', L.Convolution2D(3, in_ch, 3, 1, 1, wscale=np.sqrt(2))
)
for i in moves.range(block):
self.add_link('dense%d' % (i+2),
DenseBlock(in_chs[i], growth_rate, n_layer))
if not i == block - 1:
self.add_link('trans%d' % (i+2), Transition(in_chs[i+1]))
self.add_link(
'bn%d' % (block+1), L.BatchNormalization(in_chs[block])
)
self.add_link('fc%d' % (block+2), L.Linear(in_chs[block], n_class))
self.train = True
self.dropout_ratio = dropout_ratio
self.block = block
def __init__(self, in_size, ch, out_size, stride=2):
super(BottleNeckA, self).__init__()
w = initializers.HeNormal()
with self.init_scope():
self.conv1 = L.Convolution2D(in_size, ch, 1, stride, 0,
initialW=w, nobias=True)
self.conv2 = L.Convolution2D(ch, ch, 3, 1, 1,
initialW=w, nobias=True)
self.conv3 = L.Convolution2D(ch, out_size, 1, 1, 0,
initialW=w, nobias=True)
self.conv4 = L.Convolution2D(in_size, out_size, 1, stride, 0,
initialW=w, nobias=True)
self.bn1 = L.BatchNormalization(ch)
self.bn2 = L.BatchNormalization(ch)
self.bn3 = L.BatchNormalization(out_size)
self.bn4 = L.BatchNormalization(out_size)
def __init__(self, in_size, ch, out_size, stride=2):
super(BottleNeckA, self).__init__()
w = initializers.HeNormal()
with self.init_scope():
self.conv1 = L.Convolution2D(in_size, ch, 1, stride, 0,
initialW=w, nobias=True)
self.conv2 = L.Convolution2D(ch, ch, 3, 1, 1,
initialW=w, nobias=True)
self.conv3 = L.Convolution2D(ch, out_size, 1, 1, 0,
initialW=w, nobias=True)
self.conv4 = L.Convolution2D(in_size, out_size, 1, stride, 0,
initialW=2, nobias=True)
self.bn1 = L.BatchNormalization(ch)
self.bn2 = L.BatchNormalization(ch)
self.bn3 = L.BatchNormalization(out_size)
self.bn4 = L.BatchNormalization(out_size)
def __init__(self, in_size, ch, out_size, stride=2):
super(BottleNeckA, self).__init__()
w = initializers.HeNormal()
with self.init_scope():
self.conv1 = L.Convolution2D(in_size, ch, 1, stride, 0,
initialW=w, nobias=True)
self.conv2 = L.Convolution2D(ch, ch, 3, 1, 1,
initialW=w, nobias=True)
self.conv3 = L.Convolution2D(ch, out_size, 1, 1, 0,
initialW=w, nobias=True)
self.conv4 = L.Convolution2D(in_size, out_size, 1, stride, 0,
initialW=w, nobias=True)
self.bn1 = L.BatchNormalization(ch)
self.bn2 = L.BatchNormalization(ch)
self.bn3 = L.BatchNormalization(out_size)
self.bn4 = L.BatchNormalization(out_size)
def __init__(self, num_class, train=True):
super(VGG16Net, self).__init__()
with self.init_scope():
self.conv1=L.Convolution2D(None, 64, 3, stride=1, pad=1)
self.conv2=L.Convolution2D(None, 64, 3, stride=1, pad=1)
self.conv3=L.Convolution2D(None, 128, 3, stride=1, pad=1)
self.conv4=L.Convolution2D(None, 128, 3, stride=1, pad=1)
self.conv5=L.Convolution2D(None, 256, 3, stride=1, pad=1)
self.conv6=L.Convolution2D(None, 256, 3, stride=1, pad=1)
self.conv7=L.Convolution2D(None, 256, 3, stride=1, pad=1)
self.conv8=L.Convolution2D(None, 512, 3, stride=1, pad=1)
self.conv9=L.Convolution2D(None, 512, 3, stride=1, pad=1)
self.conv10=L.Convolution2D(None, 512, 3, stride=1, pad=1)
self.conv11=L.Convolution2D(None, 512, 3, stride=1, pad=1)
self.conv12=L.Convolution2D(None, 512, 3, stride=1, pad=1)
self.conv13=L.Convolution2D(None, 512, 3, stride=1, pad=1)
self.fc14=L.Linear(None, 4096)
self.fc15=L.Linear(None, 4096)
self.fc16=L.Linear(None, num_class)
def __init__(self, bottom_width=4, ch=512, wscale=0.02):
w = chainer.initializers.Normal(wscale)
super(Discriminator, self).__init__()
with self.init_scope():
self.c0_0 = L.Convolution2D(3, ch//8, 3, 1, 1, initialW=w)
self.c0_1 = L.Convolution2D(ch//8, ch//4, 4, 2, 1, initialW=w)
self.c1_0 = L.Convolution2D(ch//4, ch//4, 3, 1, 1, initialW=w)
self.c1_1 = L.Convolution2D(ch//4, ch//2, 4, 2, 1, initialW=w)
self.c2_0 = L.Convolution2D(ch//2, ch//2, 3, 1, 1, initialW=w)
self.c2_1 = L.Convolution2D(ch//2, ch//1, 4, 2, 1, initialW=w)
self.c3_0 = L.Convolution2D(ch//1, ch//1, 3, 1, 1, initialW=w)
self.l4 = L.Linear(bottom_width*bottom_width*ch, 1, initialW=w)
self.bn0_1 = L.BatchNormalization(ch // 4, use_gamma=False)
self.bn1_0 = L.BatchNormalization(ch // 4, use_gamma=False)
self.bn1_1 = L.BatchNormalization(ch // 2, use_gamma=False)
self.bn2_0 = L.BatchNormalization(ch // 2, use_gamma=False)
self.bn2_1 = L.BatchNormalization(ch // 1, use_gamma=False)
self.bn3_0 = L.BatchNormalization(ch // 1, use_gamma=False)
def __init__(self, size=64, ch=512, wscale=0.005, use_gamma=True):
assert (size % 16 == 0)
initial_size = size // 16
w = chainer.initializers.Normal(wscale)
super(Discriminator, self).__init__(
c0_0=L.Convolution2D(3, ch // 8, 3, 1, 1, initialW=w),
c0_1=L.Convolution2D(ch // 8, ch // 4, 4, 2, 1, initialW=w),
c1_1=L.Convolution2D(ch // 4, ch // 2, 4, 2, 1, initialW=w),
c2_1=L.Convolution2D(ch // 2, ch // 1, 4, 2, 1, initialW=w),
c3_0=L.Convolution2D(ch // 1, ch // 1, 4, 2, 1, initialW=w),
l4=L.Linear(initial_size * initial_size * ch, 1, initialW=w),
bn0_1=L.BatchNormalization(ch // 4, use_gamma=use_gamma),
bn1_1=L.BatchNormalization(ch // 2, use_gamma=use_gamma),
bn2_1=L.BatchNormalization(ch // 1, use_gamma=use_gamma),
bn3_0=L.BatchNormalization(ch // 1, use_gamma=use_gamma),
)
def __init__(self, size=64, ch=512, wscale=0.005):
assert (size % 16 == 0)
initial_size = size // 16
w = chainer.initializers.Normal(wscale)
super(Discriminator2, self).__init__(
c0_0=L.Convolution2D(3, ch // 8, 3, 1, 1, initialW=w),
c0_1=L.Convolution2D(ch // 8, ch // 4, 4, 2, 1, initialW=w),
c1_1=L.Convolution2D(ch // 4, ch // 2, 4, 2, 1, initialW=w),
c2_1=L.Convolution2D(ch // 2, ch // 1, 4, 2, 1, initialW=w),
c3_0=L.Convolution2D(ch // 1, ch // 1, 4, 2, 1, initialW=w),
l4=L.Linear(initial_size * initial_size * ch, 1, initialW=w),
bn0_1=L.BatchNormalization(ch // 4, use_gamma=False),
bn1_1=L.BatchNormalization(ch // 2, use_gamma=False),
bn2_1=L.BatchNormalization(ch // 1, use_gamma=False),
bn3_0=L.BatchNormalization(ch // 1, use_gamma=False),
)
def __init__(self, bottom_width=8, ch=512, wscale=0.005):
w = chainer.initializers.Normal(wscale)
super(DiscriminatorPFN, self).__init__(
c0_0=L.Convolution2D(3, ch // 8, 3, 1, 1, initialW=w),
c0_1=L.Convolution2D(ch // 8, ch // 4, 4, 2, 1, initialW=w),
c1_0=L.Convolution2D(ch // 4, ch // 4, 3, 1, 1, initialW=w),
c1_1=L.Convolution2D(ch // 4, ch // 2, 4, 2, 1, initialW=w),
c2_0=L.Convolution2D(ch // 2, ch // 2, 3, 1, 1, initialW=w),
c2_1=L.Convolution2D(ch // 2, ch // 1, 4, 2, 1, initialW=w),
c3_0=L.Convolution2D(ch // 1, ch // 1, 3, 1, 1, initialW=w),
l4=L.Linear(bottom_width * bottom_width * ch, 1, initialW=w),
bn0_1=L.BatchNormalization(ch // 4, use_gamma=False),
bn1_0=L.BatchNormalization(ch // 4, use_gamma=False),
bn1_1=L.BatchNormalization(ch // 2, use_gamma=False),
bn2_0=L.BatchNormalization(ch // 2, use_gamma=False),
bn2_1=L.BatchNormalization(ch // 1, use_gamma=False),
bn3_0=L.BatchNormalization(ch // 1, use_gamma=False),
)
def __init__(self, size=64, ch=512, wscale=0.005):
assert (size % 8 == 0)
initial_size = size // 8
w = chainer.initializers.Normal(wscale)
super(Discriminator, self).__init__(
c0_0=L.Convolution2D(3, ch // 8, 3, 1, 1, initialW=w),
c0_1=L.Convolution2D(ch // 8, ch // 4, 4, 2, 1, initialW=w),
c1_0=L.Convolution2D(ch // 4, ch // 4, 3, 1, 1, initialW=w),
c1_1=L.Convolution2D(ch // 4, ch // 2, 4, 2, 1, initialW=w),
c2_0=L.Convolution2D(ch // 2, ch // 2, 3, 1, 1, initialW=w),
c2_1=L.Convolution2D(ch // 2, ch // 1, 4, 2, 1, initialW=w),
c3_0=L.Convolution2D(ch // 1, ch // 1, 3, 1, 1, initialW=w),
l4=L.Linear(initial_size * initial_size * ch, 1, initialW=w),
)
# noinspection PyCallingNonCallable,PyUnresolvedReferences
def __init__(self, density=1, size=64, latent_size=128, channel=3):
assert (size % 16 == 0)
initial_size = size / 16
super(Encoder, self).__init__(
enc1=L.Convolution2D(channel, 64 * density, 4, stride=2, pad=1,
wscale=0.02 * math.sqrt(4 * 4 * channel * density)),
norm1=L.BatchNormalization(64 * density),
enc2=L.Convolution2D(64 * density, 128 * density, 4, stride=2, pad=1,
wscale=0.02 * math.sqrt(4 * 4 * 64 * density)),
norm2=L.BatchNormalization(128 * density),
enc3=L.Convolution2D(128 * density, 128 * density, 4, stride=2, pad=1,
wscale=0.02 * math.sqrt(4 * 4 * 128 * density)),
norm3=L.BatchNormalization(128 * density),
enc4=L.Convolution2D(128 * density, 256 * density, 4, stride=2, pad=1,
wscale=0.02 * math.sqrt(4 * 4 * 128 * density)),
norm4=L.BatchNormalization(256 * density),
mean=L.Linear(initial_size * initial_size * 256 * density, latent_size,
wscale=0.02 * math.sqrt(initial_size * initial_size * 256 * density)),
ln_var=L.Linear(initial_size * initial_size * 256 * density, latent_size,
wscale=0.02 * math.sqrt(initial_size * initial_size * 256 * density)),
)