Slide 22
Slide 22 text
make_layers()の移植
Tensorflow Pytorch
cfg = [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 'M',
512, 512, 512, 'M', 512, 512, 512, 'M']
def make_layers(cfg):
tflayers = []
for v in cfg:
if v == 'M':
tflayers += [layers.MaxPool2D(strides=2)]
else:
tflayers += [layers.Conv2D(v,
kernel_size=3,
padding='same',
activation='relu')]
return tf.keras.Sequential(tflayers)
cfg = [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 'M', 512,
512, 512, 'M', 512, 512, 512, 'M']
def make_layers(cfg):
layers = []
in_channels = 3
for v in cfg:
if v == 'M':
layers += [nn.MaxPool2d(kernel_size=2, stride=2)]
else:
conv2d = nn.Conv2d(in_channels,
v,
kernel_size=3,
padding=1)
layers += [conv2d, nn.ReLU(inplace=True)]
in_channels = v
return nn.Sequential(*layers)
https://github.com/pytorch/vision/blob/m
aster/torchvision/models/vgg.py#L69
実践
Tensorflow/Pytorchの
モデル移植
自前実装