Esempio n. 1
0
def trainModel(params):
    
    drop_ids = params.drop_id.split(',')
    dropIdList = []
    for dids in drop_ids:
        dropIdList.append(int(dids))

    import processdata as poseDataset

    '''Loads H3.6m dataset'''
    sys.path.insert(0,'CRFProblems/H3.6m')
    poseDataset.T = params.sequence_length
    poseDataset.delta_shift = params.sequence_length - params.sequence_overlap
    poseDataset.num_forecast_examples = 24
    poseDataset.copy_state = params.copy_state
    poseDataset.full_skeleton = params.full_skeleton
    poseDataset.train_for = params.train_for
    poseDataset.temporal_features = params.temporal_features
    poseDataset.crf_file = './CRFProblems/H3.6m/crf' + params.crf
    poseDataset.dataset_prefix = params.dataset_prefix
    poseDataset.drop_features = params.drop_features
    poseDataset.drop_id = dropIdList
    poseDataset.subsample_data = params.subsample_data
    poseDataset.runall()
    if poseDataset.copy_state:
        params.batch_size = poseDataset.minibatch_size

    path_to_dump = '../dump/'
    [nodeNames,nodeList,nodeFeatureLength,nodeConnections,edgeList,edgeListComplete,edgeFeatures,nodeToEdgeConnections,trX,trY,trX_validation,trY_validation,trX_forecasting,trY_forecasting,trX_forecast_nodeFeatures,adjacency] = graph.readCRFgraph(poseDataset)
    print '**** H3.6m Loaded ****'

    nodeNames = nodeNames.keys()
    
    new_idx = poseDataset.new_idx
    featureRange = poseDataset.nodeFeaturesRanges

    if params.use_pretrained == 1:
        print 'Loading pre-trained model with iter={0}'.format(params.iter_to_load)
        params.checkpoint_path = '/users/btech/siddsax/'
        model = loadModel(params.checkpoint_path+'checkpoint.'+str(params.iter_to_load))
        print 'DRA model loaded successfully'
    else:
        params.iter_to_load = 0
        model = defineGCN(params, nodeNames, nodeList, edgeList, edgeListComplete, edgeFeatures, nodeFeatureLength, nodeToEdgeConnections, new_idx, featureRange,adjacency)

    thefile = open('logger.txt', 'w')

    logModel(params, thefile, nodeNames, model, poseDataset)


    model.fitModel(trX, trY, snapshot_rate=params.snapshot_rate, path=params.checkpoint_path, pathD=path_to_dump, epochs=params.epochs, batch_size=params.batch_size,
        decay_after=params.decay_after, learning_rate=params.initial_lr, learning_rate_decay=params.learning_rate_decay, trX_validation=trX_validation,
        trY_validation=trY_validation, trX_forecasting=trX_forecasting, trY_forecasting=trY_forecasting,trX_forecast_nodeFeatures=trX_forecast_nodeFeatures, iter_start=params.iter_to_load,
        decay_type=params.decay_type, decay_schedule=params.decay_schedule, decay_rate_schedule=params.decay_rate_schedule,
        use_noise=params.use_noise, noise_schedule=params.noise_schedule, noise_rate_schedule=params.noise_rate_schedule,
               new_idx=new_idx, featureRange=featureRange, poseDataset=poseDataset, graph=graph, maxiter=params.maxiter, ssh_f=len(params.remoteBase), log=True, num_batches= params.curriculum)
Esempio n. 2
0
'''Loads H3.6m dataset'''
sys.path.insert(0,'CRFProblems/H3.6m')
import processdata as poseDataset
poseDataset.T = args.sequence_length
poseDataset.delta_shift = args.sequence_length - args.sequence_overlap
poseDataset.num_forecast_examples = 24
poseDataset.copy_state = args.copy_state
poseDataset.full_skeleton = args.full_skeleton
poseDataset.train_for = args.train_for
poseDataset.temporal_features = args.temporal_features
poseDataset.crf_file = './CRFProblems/H3.6m/crf' + args.crf
poseDataset.dataset_prefix = args.dataset_prefix
poseDataset.drop_features = args.drop_features
poseDataset.drop_id = drop_id
poseDataset.subsample_data = args.subsample_data
poseDataset.runall()
if poseDataset.copy_state:
	args.batch_size = poseDataset.minibatch_size

print '**** H3.6m Loaded ****'

def saveForecastedMotion(forecast,path,prefix='ground_truth_forecast_N_'):
	T = forecast.shape[0]
	N = forecast.shape[1]
	D = forecast.shape[2]
	for j in range(N):
		motion = forecast[:,j,:]
		f = open('{0}{2}{1}'.format(path,j,prefix),'w')
		for i in range(T):
			st = ''
			for k in range(D):
print 'Loading H3.6m'
sys.path.insert(0, 'CRFProblems/H3.6m')
import processdata as poseDataset
poseDataset.T = 150
poseDataset.delta_shift = 100
poseDataset.num_forecast_examples = 24
poseDataset.motion_prefix = args.motion_prefix
poseDataset.motion_suffix = args.motion_suffix
poseDataset.temporal_features = args.temporal_features
poseDataset.full_skeleton = args.full_skeleton
poseDataset.dataset_prefix = args.dataset_prefix
poseDataset.crf_file = './CRFProblems/H3.6m/crf'
poseDataset.train_for = args.train_for
poseDataset.drop_features = args.drop_features
poseDataset.drop_id = [args.drop_id]
poseDataset.runall()
print '**** H3.6m Loaded ****'

new_idx = poseDataset.new_idx
featureRange = poseDataset.nodeFeaturesRanges
base_dir = '.'
# path = '{0}/{1}/'.format(base_dir,args.checkpoint)
path = '..'
if not os.path.exists(path):
    print 'Checkpoint path does not exist. Exiting!!'
    sys.exit()

crf_file = './CRFProblems/H3.6m/crf'


def convertToSingleVec(X, new_idx, featureRange):