1 from __future__
import print_function
3 import itertools, pkg_resources, sys
4 from distutils.version
import LooseVersion
5 if LooseVersion(pkg_resources.get_distribution(
"chainer").version) >= LooseVersion(
'7.0.0')
and \
6 sys.version_info.major == 2:
7 print(
'''Please install chainer < 7.0.0: 9 sudo pip install chainer==6.7.0 11 c.f https://github.com/jsk-ros-pkg/jsk_recognition/pull/2485 14 if [p
for p
in list(itertools.chain(*[pkg_resources.find_distributions(_)
for _
in sys.path]))
if "cupy-" in p.project_name ] == []:
15 print(
'''Please install CuPy 17 sudo pip install cupy-cuda[your cuda version] 19 sudo pip install cupy-cuda91 24 import chainer.functions
as F
25 from chainer
import initializers
26 import chainer.links
as L
31 def __init__(self, in_size, ch, out_size, stride=2):
33 initialW = initializers.HeNormal()
36 with self.init_scope():
37 self.
preact = L.BatchNormalization(in_size)
39 in_size, ch, 1, stride, 0, initialW=initialW, nobias=
True)
40 self.
bn1 = L.BatchNormalization(ch)
42 ch, ch, 3, stride, 1, initialW=initialW, nobias=
True)
43 self.
bn2 = L.BatchNormalization(ch)
45 ch, out_size, 1, 1, 0, initialW=initialW, nobias=
False)
47 in_size, out_size, 1, stride, 0,
48 initialW=initialW, nobias=
False)
51 preact = F.relu(self.
preact(x))
52 shortcut = self.
conv4(preact)
53 h = self.
conv1(preact)
54 h = F.relu(self.
bn1(h))
64 initialW = initializers.HeNormal()
67 with self.init_scope():
68 self.
preact = L.BatchNormalization(in_size)
70 in_size, ch, 1, 1, 0, initialW=initialW, nobias=
True)
71 self.
bn1 = L.BatchNormalization(ch)
73 ch, ch, 3, self.
stride, 1, initialW=initialW, nobias=
True)
74 self.
bn2 = L.BatchNormalization(ch)
76 ch, in_size, 1, 1, 0, initialW=initialW, nobias=
False)
79 preact = F.relu(self.
preact(x))
83 shortcut = F.max_pooling_2d(
84 x, 1, stride=self.
stride, cover_all=
False)
85 h = self.
conv1(preact)
86 h = F.relu(self.
bn1(h))
94 def __init__(self, layer, in_size, ch, out_size, stride=2):
96 self.add_link(
BottleNeckA(in_size, ch, out_size, 1))
97 for i
in range(layer - 2):
99 self.add_link(
BottleNeckB(out_size, ch, stride=stride))
102 for f
in self.children():
112 super(ResNet_v2_50, self).
__init__()
113 with self.init_scope():
115 3, 64, 7, 2, 3, initialW=initializers.HeNormal())
124 h = F.max_pooling_2d(h, 3, stride=2)
131 h = F.average_pooling_2d(h, 7, stride=1)
def __init__(self, in_size, ch, out_size, stride=2)
def __init__(self, layer, in_size, ch, out_size, stride=2)
def __init__(self, in_size, ch, stride=2)