Ejemplo n.º 1
0
    def __init__(self, model_path):
        if not available:
            raise RuntimeError('CaffeFunction is not supported on Python 3')

        net = caffe_pb2.NetParameter()
        with open(model_path, 'rb') as model_file:
            net.MergeFromString(model_file.read())

        self.fs = function_set.FunctionSet()
        self.forwards = {}
        self.split_map = {}
        self.layers = []

        if net.layer:
            for layer in net.layer:
                meth = _type_to_method.get(layer.type)
                if meth:
                    meth(self, layer)
                else:
                    warnings.warn(
                        'Skip the layer "%s", since CaffeFunction does not'
                        'support %s layer' % (layer.name, layer.type))
        else:  # v1 format
            for layer in net.layers:
                meth = _oldname_to_method.get(layer.type)
                if meth:
                    meth(self, layer)
                else:
                    warnings.warn(
                        'Skip the layer "%s", since CaffeFunction does not'
                        'support it' % layer.name)
Ejemplo n.º 2
0
 def __init__(self, in_channels, out1, proj3, out3, proj5, out5, proj_pool):
     self.f = function_set.FunctionSet(
         conv1=convolution_2d.Convolution2D(in_channels, out1, 1),
         proj3=convolution_2d.Convolution2D(in_channels, proj3, 1),
         conv3=convolution_2d.Convolution2D(proj3, out3, 3, pad=1),
         proj5=convolution_2d.Convolution2D(in_channels, proj5, 1),
         conv5=convolution_2d.Convolution2D(proj5, out5, 5, pad=2),
         projp=convolution_2d.Convolution2D(in_channels, proj_pool, 1),
     )
Ejemplo n.º 3
0
    def __init__(self, in_channels, out1, proj3, out3, proj33, out33,
                 pooltype, proj_pool=None, stride=1):
        if out1 > 0:
            assert stride == 1
            assert proj_pool is not None

        self.f = function_set.FunctionSet(
            proj3=convolution_2d.Convolution2D(
                in_channels, proj3, 1, nobias=True),
            conv3=convolution_2d.Convolution2D(
                proj3, out3, 3, pad=1, stride=stride, nobias=True),
            proj33=convolution_2d.Convolution2D(
                in_channels, proj33, 1, nobias=True),
            conv33a=convolution_2d.Convolution2D(
                proj33, out33, 3, pad=1, nobias=True),
            conv33b=convolution_2d.Convolution2D(
                out33, out33, 3, pad=1, stride=stride, nobias=True),
            proj3n=batch_normalization.BatchNormalization(proj3),
            conv3n=batch_normalization.BatchNormalization(out3),
            proj33n=batch_normalization.BatchNormalization(proj33),
            conv33an=batch_normalization.BatchNormalization(out33),
            conv33bn=batch_normalization.BatchNormalization(out33),
        )

        if out1 > 0:
            self.f.conv1 = convolution_2d.Convolution2D(
                in_channels, out1, 1, stride=stride, nobias=True)
            self.f.conv1n = batch_normalization.BatchNormalization(out1)
        self.out1 = out1

        if proj_pool is not None:
            self.f.poolp = convolution_2d.Convolution2D(
                in_channels, proj_pool, 1, nobias=True)
            self.f.poolpn = batch_normalization.BatchNormalization(proj_pool)
        self.proj_pool = proj_pool

        if pooltype == 'max':
            self.f.pool = max_pooling_2d.MaxPooling2D(3, stride=stride, pad=1)
        elif pooltype == 'avg':
            self.f.pool = average_pooling_2d.AveragePooling2D(
                3, stride=stride, pad=1)
        else:
            raise NotImplementedError()