Skip to content

Commit

Permalink
fix bug of cython
Browse files Browse the repository at this point in the history
  • Loading branch information
liang committed Sep 26, 2017
1 parent cc9ccf5 commit 874c16c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
38 changes: 29 additions & 9 deletions TrainWeight.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ def fit(self, train_data, num_epoch, batch_size, carg_params=None, begin_epoch=0
('heatweight', (batch_size, numofparts, 46, 46)),
('vecweight', (batch_size, numoflinks*2, 46, 46))])

self.init_params(arg_params = carg_params, aux_params={},
allow_missing=True)

# self.init_params(mx.initializer.Xavier(rnd_type='uniform', factor_type='avg', magnitude=1))
# mx.initializer.Uniform(scale=0.07),
# mx.initializer.Uniform(scale=0.01)
self.init_params(mx.initializer.Xavier(rnd_type='uniform', factor_type='avg', magnitude=0.01),arg_params = carg_params, aux_params={},allow_missing = True)
#self.set_params(arg_params = carg_params, aux_params={},
# allow_missing = True)
self.init_optimizer(optimizer='sgd', optimizer_params=(('learning_rate', 0.00004), ))

for epoch in range(begin_epoch, num_epoch):
Expand Down Expand Up @@ -127,16 +132,25 @@ def fit(self, train_data, num_epoch, batch_size, carg_params=None, begin_epoch=0
numpixel +=lossiter.shape[0]
'''
lossiter = prediction[1].asnumpy()
cls_loss = np.sum(lossiter)/batch_size
sumerror = sumerror + cls_loss
print 'start heat: ', cls_loss

lossiter = prediction[0].asnumpy()
cls_loss = np.sum(lossiter)/batch_size
sumerror = sumerror + cls_loss
print 'start paf: ', cls_loss

lossiter = prediction[-1].asnumpy()
cls_loss = np.sum(lossiter)/batch_size
print 'paf: ', cls_loss
sumerror = sumerror + cls_loss
print 'end heat: ', cls_loss

lossiter = prediction[-2].asnumpy()
cls_loss = np.sum(lossiter)/batch_size
print 'heat: ', cls_loss

sumerror = sumerror + cls_loss
print 'end paf: ', cls_loss

if i%100==0:
print i
Expand Down Expand Up @@ -164,14 +178,15 @@ def fit(self, train_data, num_epoch, batch_size, carg_params=None, begin_epoch=0
sym = ''
if config.TRAIN.head == 'vgg':
sym = CPMModel()

## Load parameters from vgg
warmupModel = '/data/guest_users/liangdong/liangdong/practice_demo/mxnet_CPM/model/vgg19'
testsym, arg_params, aux_params = mx.model.load_checkpoint(warmupModel, 0)
newargs = {}
for ikey in config.TRAIN.vggparams:
newargs[ikey] = arg_params[ikey]

batch_size = 2
batch_size = 5
aidata = AIChallengerIterweightBatch('pose_io/AI_data_val.json', # 'pose_io/COCO_data.json',
'data', (batch_size, 3, 368, 368),
['heatmaplabel','partaffinityglabel','heatweight','vecweight'],
Expand All @@ -180,16 +195,21 @@ def fit(self, train_data, num_epoch, batch_size, carg_params=None, begin_epoch=0
(batch_size, numofparts, 46, 46),
(batch_size, numoflinks*2, 46, 46)])

cmodel = poseModule(symbol=sym, context=mx.gpu(3),
cmodel = poseModule(symbol=sym, context=mx.gpu(0),
label_names=['heatmaplabel',
'partaffinityglabel',
'heatweight',
'vecweight'])
starttime = time.time()

iteration = 1
'''
start_prefix = 1
output_prefix = config.TRAIN.output_model
testsym, newargs, aux_params = mx.model.load_checkpoint(output_prefix, start_prefix)
'''
iteration = 2
cmodel.fit(aidata, num_epoch = iteration, batch_size = batch_size, carg_params = newargs)
cmodel.save_checkpoint(config.TRAIN.output_model, iteration)
cmodel.save_checkpoint(config.TRAIN.output_model, start_prefix + iteration)
endtime = time.time()

print 'cost time: ', (endtime-starttime)/60
Expand Down
3 changes: 3 additions & 0 deletions cython/pafmap.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def putVecMaps(np.ndarray[DTYPE_t, ndim = 2] entryX, np.ndarray[DTYPE_t, ndim =
cdef DTYPE_t norm_bc = np.sqrt(bc_x * bc_x + bc_y * bc_y)
if norm_bc == 0:
return

bc_x = bc_x/norm_bc
bc_y = bc_y/norm_bc

cdef DTYPE_t ba_x, ba_y
cdef DTYPE_t dist
Expand Down

0 comments on commit 874c16c

Please sign in to comment.