Skip to content

Commit

Permalink
Add soft quantizing and tri section initialization methods
Browse files Browse the repository at this point in the history
  • Loading branch information
anson0910 committed Dec 8, 2015
1 parent c0e8232 commit 4e60ec6
Show file tree
Hide file tree
Showing 8 changed files with 672 additions and 236 deletions.
282 changes: 167 additions & 115 deletions face_net_surgery/.idea/workspace.xml

Large diffs are not rendered by default.

20 changes: 15 additions & 5 deletions face_net_surgery/face_12_surgery.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
sys.path.insert(0, caffe_root + 'python')
import caffe

softQuantize = True
quantizeBitNum = 2

# ================== load face_12c ======================================
# Set the right path to your model definition file, pretrained model weights,
# and the image you would like to classify.
MODEL_FILE = '/home/anson/caffe-master/models/face_12c/deploy.prototxt'
PRETRAINED = '/home/anson/caffe-master/models/face_12c/face_12c_train_iter_400000.caffemodel'
if softQuantize:
PRETRAINED = '/home/anson/caffe-master/models/face_12c/face_12c_soft_quantize_2.caffemodel'
else:
PRETRAINED = '/home/anson/caffe-master/models/face_12c/face_12c_train_iter_400000.caffemodel'
caffe.set_mode_gpu()
net = caffe.Net(MODEL_FILE, PRETRAINED, caffe.TEST)

Expand All @@ -32,7 +36,10 @@

# Load the fully convolutional network to transplant the parameters.
MODEL_FILE = '/home/anson/caffe-master/models/face_12c/face12c_full_conv.prototxt'
PRETRAINED = '/home/anson/caffe-master/models/face_12c/face_12c_train_iter_400000.caffemodel'
if softQuantize:
PRETRAINED = '/home/anson/caffe-master/models/face_12c/face_12c_soft_quantize_2.caffemodel'
else:
PRETRAINED = '/home/anson/caffe-master/models/face_12c/face_12c_train_iter_400000.caffemodel'
net_full_conv = caffe.Net(MODEL_FILE, PRETRAINED, caffe.TEST)
params_full_conv = ['fc2-conv', 'fc3-conv']
# conv_params = {name: (weights, biases)}
Expand All @@ -46,4 +53,7 @@
conv_params[pr_conv][0].flat = fc_params[pr][0].flat # flat unrolls the arrays
conv_params[pr_conv][1][...] = fc_params[pr][1]

net_full_conv.save('/home/anson/caffe-master/models/face_12c/face12c_full_conv.caffemodel')
if softQuantize:
net_full_conv.save('/home/anson/caffe-master/models/face_12c/face12c_full_conv_soft_quantize_2.caffemodel')
else:
net_full_conv.save('/home/anson/caffe-master/models/face_12c/face12c_full_conv.caffemodel')
4 changes: 3 additions & 1 deletion face_net_surgery/face_weight_bias_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,6 @@
print ("Shape of " + k + " weight params : " + str(filters_weights.shape))
print ("Max : " + str(filters_weights.max()) + " min : " + str(filters_weights.min()))
print ("Shape of " + k + " bias params: " + str(filters_bias.shape))
print ("Max : " + str(filters_bias.max()) + " min : " + str(filters_bias.min()))
print ("Max : " + str(filters_bias.max()) + " min : " + str(filters_bias.min()))

file_write.close()
86 changes: 43 additions & 43 deletions face_net_surgery/full_conv_blobs_ranges.txt
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@

======= net_12c_full_conv =======
('data', (1, 3, 23, 14))
Max : 150.993 min : -122.679
('conv1', (1, 16, 21, 12))
('data', (1, 3, 23, 14)) a = 8
Max : 150.993 min : -122.679
('conv1', (1, 16, 21, 12)) a = 8
Max : 184.8 min : -198.697
('pool1', (1, 16, 10, 6))
Max : 184.8 min : 0
('fc2-conv', (1, 16, 6, 2))
('pool1', (1, 16, 10, 6)) a = 8
Max : 184.8 min : 0
('fc2-conv', (1, 16, 6, 2)) a = 8
Max : 105.485 min : 0
('fc3-conv', (1, 2, 6, 2))
('fc3-conv', (1, 2, 6, 2)) a = 6
Max : 36.3772 min : -36.3772
('prob', (1, 2, 6, 2))
('prob', (1, 2, 6, 2)) a = 1
Max : 1.0 min : 0

======= net_12_cal =======
('data', (10, 3, 12, 12))
('data', (10, 3, 12, 12)) a = 8
Max : 150.993 min : -122.679
('conv1', (10, 16, 10, 10))
('conv1', (10, 16, 10, 10)) a = 10
Max : 418.805 min : -387.641
('pool1', (10, 16, 5, 5))
('pool1', (10, 16, 5, 5)) a = 10
Max : 418.805 min : 0
('fc2', (10, 128))
('fc2', (10, 128)) a = 8
Max : 145.942 min : 0
('fc3', (10, 45))
('fc3', (10, 45)) a = 5
Max : 15.2421 min : -8.62884
('prob', (10, 45))
('prob', (10, 45)) a = 1
Max : 0.713056 min : 0

======= net_24c =======
('data', (10, 3, 24, 24))
('data', (10, 3, 24, 24)) a = 8
Max : 150.993 min : -122.679
('conv1', (10, 64, 20, 20))
('conv1', (10, 64, 20, 20)) a = 9
Max : 239.752 min : -242.662
('pool1', (10, 64, 10, 10))
('pool1', (10, 64, 10, 10)) a = 9
Max : 239.752 min : 0
('fc2', (10, 128))
('fc2', (10, 128)) a = 7
Max : 60.3139 min : 0
('fc3', (10, 2))
('fc3', (10, 2)) a = 4
Max : 6.59934 min : -6.59934
('prob', (10, 2))
('prob', (10, 2)) a = 1
Max : 0.999998 min : 0

======= net_24_cal =======
('data', (10, 3, 24, 24))
('data', (10, 3, 24, 24)) a = 8
Max : 150.993 min : -122.679
('conv1', (10, 32, 20, 20))
('conv1', (10, 32, 20, 20)) a = 10
Max : 455.734 min : -473.304
('pool1', (10, 32, 10, 10))
('pool1', (10, 32, 10, 10)) a = 10
Max : 455.734 min : 0
('fc2', (10, 64))
('fc2', (10, 64)) a = 9
Max : 201.905 min : 0
('fc3', (10, 45))
Max : 16.2613 min : -13.3718
('prob', (10, 45))
('fc3', (10, 45)) a = 5
Max : 16.2613 min : -13.3718
('prob', (10, 45)) a = 1
Max : 0.865981 min : 0

======= net_48c =======
('data', (10, 3, 48, 48))
('data', (10, 3, 48, 48)) a = 8
Max : 150.993 min : -122.679
('conv1', (10, 64, 44, 44))
('conv1', (10, 64, 44, 44)) a = 10
Max : 436.075 min : -440.724
('pool1', (10, 64, 22, 22))
('pool1', (10, 64, 22, 22)) a = 10
Max : 436.075 min : 0
('conv2', (10, 64, 18, 18))
('conv2', (10, 64, 18, 18)) a = 9
Max : 209.685 min : 0
('pool2', (10, 64, 9, 9))
('pool2', (10, 64, 9, 9)) a = 9
Max : 209.685 min : 0
('fc3', (10, 256))
('fc3', (10, 256)) a = 7
Max : 83.6233 min : 0
('fc4', (10, 2))
('fc4', (10, 2)) a = 6
Max : 24.524 min : -24.524
('prob', (10, 2))
('prob', (10, 2)) a = 1
Max : 1.0 min : 0

======= net_48_cal =======
('data', (10, 3, 48, 48))
('data', (10, 3, 48, 48)) a = 8
Max : 150.993 min : -122.679
('conv1', (10, 64, 44, 44))
('conv1', (10, 64, 44, 44)) a = 10
Max : 631.86 min : -652.16
('pool1', (10, 64, 22, 22))
('pool1', (10, 64, 22, 22)) a = 10
Max : 631.86 min : 0
('conv2', (10, 64, 18, 18))
('conv2', (10, 64, 18, 18)) a = 10
Max : 607.271 min : 0
('pool2', (10, 64, 9, 9))
('pool2', (10, 64, 9, 9)) a = 10
Max : 607.271 min : 0
('fc3', (10, 256))
('fc3', (10, 256)) a = 9
Max : 238.21 min : 0
('fc4', (10, 45))
('fc4', (10, 45)) a = 6
Max : 27.1197 min : -18.4789
('prob', (10, 45))
('prob', (10, 45)) a = 1
Max : 0.998986 min : 0
Loading

0 comments on commit 4e60ec6

Please sign in to comment.