diff --git a/third_party/caffe/Dockerfile b/third_party/caffe/Dockerfile index 92f67f23111462928576d99f89fdce1e1c8e7e87..d3df2cf60a67222b97f3e66f01cb3a5f312fbab5 100644 --- a/third_party/caffe/Dockerfile +++ b/third_party/caffe/Dockerfile @@ -30,6 +30,8 @@ WORKDIR $CAFFE_ROOT # FIXME: use ARG instead of ENV once DockerHub supports this # https://github.com/docker/hub-feedback/issues/460 ENV CLONE_TAG=1.0 +# To enable Clip operation in CAFFE during validation, it's needed to set CLONE_TAG=master +# ENV CLONE_TAG=master # ImportError in system pip wrappers after an upgrade. # https://github.com/pypa/pip/issues/5599 diff --git a/third_party/caffe/caffe.proto b/third_party/caffe/caffe.proto index 8be551bdb9031492e2ef51615cfc2aec33f5cd0d..baf388016b8f0ad131342147a5b7f2e2d47be15d 100644 --- a/third_party/caffe/caffe.proto +++ b/third_party/caffe/caffe.proto @@ -437,7 +437,7 @@ message ParamSpec { // NOTE // Update the next available ID when you add a new LayerParameter field. // -// LayerParameter next available layer-specific ID: 147 (last added: recurrent_param) +// LayerParameter next available layer-specific ID: 149 (last added: clip_param) message LayerParameter { optional string name = 1; // the layer name optional string type = 2; // the layer type @@ -494,6 +494,7 @@ message LayerParameter { optional ArgMaxParameter argmax_param = 103; optional BatchNormParameter batch_norm_param = 139; optional BiasParameter bias_param = 141; + optional ClipParameter clip_param = 148; optional ConcatParameter concat_param = 104; optional ContrastiveLossParameter contrastive_loss_param = 105; optional ConvolutionParameter convolution_param = 106; @@ -778,6 +779,12 @@ message ArgMaxParameter { optional int32 axis = 3; } +// Message that stores parameters used by ClipLayer +message ClipParameter { + required float min = 1; + required float max = 2; +} + message ConcatParameter { // The axis along which to concatenate -- may be negative to index from the // end (e.g., -1 for the last axis). Other axes must have the diff --git a/tools/python/transform/caffe_converter.py b/tools/python/transform/caffe_converter.py index 3eb6e42936efd8fef9f6fb1333046b10fd7dfebd..a2482a907f3a6b6ce0185a5ebfe5dd42c2136461 100644 --- a/tools/python/transform/caffe_converter.py +++ b/tools/python/transform/caffe_converter.py @@ -164,6 +164,7 @@ class CaffeConverter(base_converter.ConverterInterface): 'PReLU': ActivationType.PRELU, 'TanH': ActivationType.TANH, 'Sigmoid': ActivationType.SIGMOID, + 'Clip': ActivationType.RELUX, } def __init__(self, option, src_model_file, src_weight_file): @@ -177,6 +178,7 @@ class CaffeConverter(base_converter.ConverterInterface): 'TanH': self.convert_activation, 'Sigmoid': self.convert_activation, 'PReLU': self.convert_activation, + 'Clip': self.convert_activation, 'Pooling': self.convert_pooling, 'Concat': self.convert_concat, 'Slice': self.convert_slice, @@ -506,6 +508,13 @@ class CaffeConverter(base_converter.ConverterInterface): type_arg.s = six.b(ActivationType.LEAKYRELU.name) + if caffe_op.type == 'Clip': + mace_check(caffe_op.layer.clip_param.min == 0, + "Mace only supports min == 0 Clip op") + limit_arg = op.arg.add() + limit_arg.name = MaceKeyword.mace_activation_max_limit_str + limit_arg.f = caffe_op.layer.clip_param.max + def convert_folded_batchnorm(self, caffe_op): op = self.convert_general_op(caffe_op) op.type = MaceOp.BatchNorm.name