def load_dkf(dataset, runme_path, conf_path, weight_path):
    # This is pretty much just copied from train.py. Mostly voodoo.
    params = parse_dkf_args(runme_path, conf_path, weight_path)

    # Add dataset and NADE parameters, which will become part of the model
    for k in ['dim_observations', 'data_type']:
        params[k] = dataset[k]
    if params['use_nade']:
        params['data_type'] = 'real_nade'

    # Remove from params
    removeIfExists('./NOSUCHFILE')
    reloadFile = params.pop('reloadFile')
    pfile = params.pop('paramFile')
    assert os.path.exists(pfile), pfile + ' not found. Need paramfile'
    dkf = DKF(params, paramFile=pfile, reloadFile=reloadFile)

    return dkf
Esempio n. 2
0
mapPrint('Options: ', params)
if params['use_nade']:
    params['data_type'] = 'binary_nade'
"""
import DKF + learn/evaluate functions
"""
start_time = time.time()
from stinfmodel.dkf import DKF
import stinfmodel.learning as DKF_learn
import stinfmodel.evaluate as DKF_evaluate
displayTime('import DKF', start_time, time.time())
dkf = None

#Remove from params
start_time = time.time()
removeIfExists('./NOSUCHFILE')
reloadFile = params.pop('reloadFile')
""" Reload parameters if reloadFile exists otherwise setup model from scratch
and initialize parameters randomly.
"""
if os.path.exists(reloadFile):
    pfile = params.pop('paramFile')
    """ paramFile is set inside the BaseClass in theanomodels 
    to point to the pickle file containing params"""
    assert os.path.exists(pfile), pfile + ' not found. Need paramfile'
    print 'Reloading trained model from : ', reloadFile
    print 'Assuming ', pfile, ' corresponds to model'
    dkf = DKF(params, paramFile=pfile, reloadFile=reloadFile)
else:
    pfile = params['savedir'] + '/' + params['unique_id'] + '-config.pkl'
    print 'Training model from scratch. Parameters in: ', pfile