Permalink
Browse files

[caffe-proto-fix] replace deprecated V1 caffe definition with the lat…

…est one
  • Loading branch information...
1 parent 79db9b6 commit 187f5fa9325a95c31102eb31631c2d8c2a3f6ea1 @jermainewang jermainewang committed Jun 24, 2015
Showing with 51 additions and 36 deletions.
  1. +1 −0 configure.in.example
  2. +28 −14 owl/owl/net/net.py
  3. +21 −21 owl/owl/net/net_helper.py
  4. +1 −1 owl/owl/net/netio.py
@@ -14,6 +14,7 @@ CUDA_ROOT=
# Root path to find cudnn
CUDNN_ROOT=
+CUDNN_VERSION=
# build type: (Release | Debug | RelWithDebInfo)
BUILD_TYPE=Release
View
@@ -162,10 +162,10 @@ class WeightedComputeUnit(ComputeUnitSimple):
:ivar owl.NArray bias: bias tensor
:ivar owl.NArray biasdelta: momentum of bias
:ivar owl.NArray biasgrad: gradient of bias
- :ivar blobs_lr: learning rate specific for this unit; a list of float represents: [weight_lr, bias_lr]
- :vartype blobs_lr: list float
- :ivar weight_decay: weight decay specific for this unit; a list of float represents: [weight_wd, bias_wd]
- :vartype weight_decay: list float
+ :ivar float lr_mult_w: learning rate multiplier for the weight of this unit
+ :ivar float lr_mult_b: bias learning rate multiplier for the bias of this unit
+ :ivar float decay_mult_w: decay multiplier for the weight of this unit
+ :ivar float decay_mult_b: decay multiplier for the bias of this unit
'''
def __init__(self, params):
super(WeightedComputeUnit, self).__init__(params)
@@ -180,12 +180,26 @@ def __init__(self, params):
self.in_shape = None
# blob learning rate and weight decay
- self.blobs_lr = params.blobs_lr
- self.weight_decay = params.weight_decay
- if len(self.blobs_lr) == 0:
- self.blobs_lr = [1,1]
- if len(self.weight_decay) == 0:
- self.weight_decay = [1, 0]
+ if len(params.param) >= 1:
+ self.lr_mult_w = params.param[0].lr_mult
+ self.decay_mult_w = params.param[0].decay_mult
+ else:
+ self.lr_mult_w = 1
+ self.decay_mult_w = 1
+
+ if len(params.param) >= 2:
+ self.lr_mult_b = params.param[1].lr_mult
+ self.decay_mult_b = params.param[1].decay_mult
+ else:
+ self.lr_mult_b = 1
+ self.decay_mult_b = 0
+
+ #self.blobs_lr = params.blobs_lr
+ #self.weight_decay = params.weight_decay
+ #if len(self.blobs_lr) == 0:
+ #self.blobs_lr = [1,1]
+ #if len(self.weight_decay) == 0:
+ #self.weight_decay = [1, 0]
def compute_size(self, from_btm, to_top):
pass
@@ -236,17 +250,17 @@ def weight_update(self, base_lr, base_weight_decay, momentum, batch_size):
self.weightdelta = owl.zeros(self.weightgrad.shape)
self.weightdelta = momentum * self.weightdelta \
- - (base_lr * self.blobs_lr[0] / batch_size) * self.weightgrad \
- - (base_lr * self.blobs_lr[0] * base_weight_decay * self.weight_decay[0]) * self.weight
+ - (base_lr * self.lr_mult_w / batch_size) * self.weightgrad \
+ - (base_lr * self.lr_mult_w * base_weight_decay * self.decay_mult_w) * self.weight
self.weight = self.weight + self.weightdelta
self.weightgrad = None
if self.biasdelta == None:
self.biasdelta = owl.zeros(self.biasgrad.shape)
self.biasdelta = momentum * self.biasdelta \
- - (base_lr * self.blobs_lr[1] / batch_size) * self.biasgrad \
- - (base_lr * self.blobs_lr[1] * base_weight_decay * self.weight_decay[1]) * self.bias
+ - (base_lr * self.lr_mult_b / batch_size) * self.biasgrad \
+ - (base_lr * self.lr_mult_b * base_weight_decay * self.decay_mult_b) * self.bias
self.bias = self.bias + self.biasdelta
self.biasgrad = None
@@ -56,29 +56,29 @@ def build_net(self, owl_net, num_gpu = 1):
owl_net.data_layers = []
# 1. record name and its caffe.V1LayerParameter data in a map
# 2. some layers is stacked into one in caffe's configure format
- for l in self.netconfig.layers:
+ for l in self.netconfig.layer:
owl_struct = self._convert_type(l, num_gpu)
if owl_struct != None:
uid = owl_net.add_unit(owl_struct)
#handle IO. XXX: hard-coded
ty = l.type
- if ty == V1LayerParameter.LayerType.Value('DATA'):
+ if ty == 'Data':
owl_net.data_layers.append(l.name)
if len(l.include) != 0 and l.include[0].phase == Phase.Value('TRAIN'):
owl_net.batch_size = l.data_param.batch_size
- elif ty == V1LayerParameter.LayerType.Value('IMAGE_DATA'):
+ elif ty == 'ImageData':
owl_net.data_layers.append(l.name)
if len(l.include) != 0 and l.include[0].phase == Phase.Value('TRAIN'):
owl_net.batch_size = l.image_data_param.batch_size
- elif ty == V1LayerParameter.LayerType.Value('WINDOW_DATA'):
+ elif ty == 'WindowData':
owl_net.data_layers.append(l.name)
if len(l.include) != 0 and l.include[0].phase == Phase.Value('TRAIN'):
owl_net.batch_size = l.window_data_param.batch_size
- elif ty == V1LayerParameter.LayerType.Value('SOFTMAX_LOSS'):
+ elif ty == 'SoftmaxWithLoss':
owl_net.loss_uids.append(uid)
- elif ty == V1LayerParameter.LayerType.Value('ACCURACY'):
+ elif ty == 'Accuracy':
owl_net.accuracy_uids.append(uid)
# stack issues
@@ -121,36 +121,36 @@ def build_net(self, owl_net, num_gpu = 1):
def _convert_type(self, caffe_layer, num_gpu):
ty = caffe_layer.type
- if ty == V1LayerParameter.LayerType.Value('DATA'):
+ if ty == 'Data':
return net.LMDBDataUnit(caffe_layer, num_gpu)
- elif ty == V1LayerParameter.LayerType.Value('IMAGE_DATA'):
+ elif ty == 'ImageData':
return net.ImageDataUnit(caffe_layer, num_gpu)
- elif ty == V1LayerParameter.LayerType.Value('WINDOW_DATA'):
+ elif ty == 'WindowData':
return net.ImageWindowDataUnit(caffe_layer, num_gpu)
- elif ty == V1LayerParameter.LayerType.Value('INNER_PRODUCT'):
+ elif ty == 'InnerProduct':
return net.FullyConnection(caffe_layer)
- elif ty == V1LayerParameter.LayerType.Value('CONVOLUTION'):
+ elif ty == 'Convolution':
return net.ConvConnection(caffe_layer)
- elif ty == V1LayerParameter.LayerType.Value('POOLING'):
+ elif ty == 'Pooling':
return net.PoolingUnit(caffe_layer)
- elif ty == V1LayerParameter.LayerType.Value('RELU'):
+ elif ty == 'ReLU':
return net.ReluUnit(caffe_layer)
- elif ty == V1LayerParameter.LayerType.Value('SIGMOID'):
+ elif ty == 'Sigmoid':
return net.SigmoidUnit(caffe_layer)
- elif ty == V1LayerParameter.LayerType.Value('SOFTMAX_LOSS'):
+ elif ty == 'SoftmaxWithLoss':
return net.SoftmaxUnit(caffe_layer)
- elif ty == V1LayerParameter.LayerType.Value('TANH'):
+ elif ty == 'TanH':
return net.TanhUnit(caffe_layer)
- elif ty == V1LayerParameter.LayerType.Value('DROPOUT'):
+ elif ty == 'Dropout':
return net.DropoutUnit(caffe_layer)
- elif ty == V1LayerParameter.LayerType.Value('LRN'):
+ elif ty == 'LRN':
return net.LRNUnit(caffe_layer)
- elif ty == V1LayerParameter.LayerType.Value('CONCAT'):
+ elif ty == 'Concat':
return net.ConcatUnit(caffe_layer)
- elif ty == V1LayerParameter.LayerType.Value('ACCURACY'):
+ elif ty == 'Accuracy':
return net.AccuracyUnit(caffe_layer)
else:
- print "Not implemented type:", V1LayerParameter.LayerType.Name(caffe_layer.type)
+ print "Not implemented type:", ty
return None
def init_net_from_file(self, owl_net, weightpath, snapshotidx):
@@ -272,7 +272,7 @@ def __init__(self, data_param, transform_param, mm_batch_num):
self.mean_data[0] = transform_param.mean_value[0]
self.mean_data[1] = transform_param.mean_value[1]
self.mean_data[2] = transform_param.mean_value[2]
- else:
+ else:
with open(transform_param.mean_file, 'rb') as f:
bp.ParseFromString(f.read())
mean_narray = np.array(bp.data, dtype=np.float32)

1 comment on commit 187f5fa

@jermainewang
Member

@sneakerkg Please help me check the change. I have replaced all the deprecated protobuf definition with the latest one. Please run following tests:

  1. Run alexnet training for several hours (including testing). Your old caffe proto file could be upgraded using this program
  2. Run other tools only to check whether it runs or not.

-Minjie

Please sign in to comment.