Last active
August 31, 2017 09:08
-
-
Save crcrpar/f685612b6e22bf640c9622677d6ef0db to your computer and use it in GitHub Desktop.
a wrapper of chainer VGG16Layers w/o fully connected layers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import collections | |
import os | |
import numpy as np | |
import chainer | |
import chainer.functions as F | |
import chainer.links as L | |
class VGG16(L.VGG16Layers): | |
def __init__(self, no_top=True, pretrained_model='auto'): | |
import gc | |
self.no_top = no_top | |
super(VGG16, self).__init__(pretrained_model=pretrained_model) | |
del self.fc6 | |
del self.fc7 | |
del self.fc8 | |
gc.collect() | |
@property | |
def functions(self): | |
return collections.OrderedDict([ | |
('conv1_1', [self.conv1_1, F.relu]), | |
('conv1_2', [self.conv1_2, F.relu]), | |
('pool1', [_max_pooling_2d]), | |
('conv2_1', [self.conv2_1, F.relu]), | |
('conv2_2', [self.conv2_2, F.relu]), | |
('pool2', [_max_pooling_2d]), | |
('conv3_1', [self.conv3_1, F.relu]), | |
('conv3_2', [self.conv3_2, F.relu]), | |
('conv3_3', [self.conv3_3, F.relu]), | |
('pool3', [_max_pooling_2d]), | |
('conv4_1', [self.conv4_1, F.relu]), | |
('conv4_2', [self.conv4_2, F.relu]), | |
('conv4_3', [self.conv4_3, F.relu]), | |
('pool4', [_max_pooling_2d]), | |
('conv5_1', [self.conv5_1, F.relu]), | |
('conv5_2', [self.conv5_2, F.relu]), | |
('conv5_3', [self.conv5_3, F.relu]), | |
('pool5', [_max_pooling_2d]), | |
]) | |
def _max_pooling_2d(x): | |
return F.max_pooling_2d(x, ksize=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment