本文整理汇总了Python中pylearn2.config.yaml_parse.load函数的典型用法代码示例。如果您正苦于以下问题:Python load函数的具体用法?Python load怎么用?Python load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main(args=None):
"""
Execute the main body of the script.
Parameters
----------
args : list, optional
Command-line arguments. If unspecified, `sys.argv[1:]` is used.
"""
parser = argparse.ArgumentParser(description='Load a YAML file without '
'performing any training.')
parser.add_argument('yaml_file', type=argparse.FileType('r'),
help='The YAML file to load.')
parser.add_argument('-N', '--no-instantiate',
action='store_const', default=False, const=True,
help='Only verify that the YAML parses correctly '
'but do not attempt to instantiate the objects. '
'This might be used as a quick sanity check if '
'checking a file that requires a GPU in an '
'environment that lacks one (e.g. a cluster '
'head node)')
args = parser.parse_args(args=args)
name = args.yaml_file.name
initialize()
if args.no_instantiate:
yaml_load(args.yaml_file)
print("Successfully parsed %s (but objects not instantiated)." % name)
else:
load(args.yaml_file)
print("Successfully parsed and loaded %s." % name)
开发者ID:123fengye741,项目名称:pylearn2,代码行数:30,代码来源:yaml_dryrun.py
示例2: test_which_set
def test_which_set():
"""Test which_set selector."""
skip_if_no_sklearn()
# one label
this_yaml = test_yaml_which_set % {'which_set': 'train'}
trainer = yaml_parse.load(this_yaml)
trainer.main_loop()
# multiple labels
this_yaml = test_yaml_which_set % {'which_set': ['train', 'test']}
trainer = yaml_parse.load(this_yaml)
trainer.main_loop()
# improper label (iterator only returns 'train' and 'test' subsets)
this_yaml = test_yaml_which_set % {'which_set': 'valid'}
try:
trainer = yaml_parse.load(this_yaml)
trainer.main_loop()
raise AssertionError
except ValueError:
pass
# bogus label (not in approved list)
this_yaml = test_yaml_which_set % {'which_set': 'bogus'}
try:
yaml_parse.load(this_yaml)
raise AssertionError
except ValueError:
pass
开发者ID:JollyRoger183,项目名称:pylearn2,代码行数:30,代码来源:test_cross_validation.py
示例3: test_duplicate_keywords
def test_duplicate_keywords():
"""
Tests whether there are doublicate keywords in the yaml
"""
initialize()
yamlfile = """{
"model": !obj:pylearn2.models.mlp.MLP {
"layers": [
!obj:pylearn2.models.mlp.Sigmoid {
"layer_name": 'h0',
"dim": 20,
"sparse_init": 15,
}],
"nvis": 784,
"nvis": 384,
}
}"""
try:
load(yamlfile)
except yaml.constructor.ConstructorError as e:
message = str(e)
assert message.endswith("found duplicate key (nvis)")
pass
except Exception as e:
error_msg = "Got the unexpected error: %s" % (e)
raise TypeError(error_msg)
开发者ID:MarCnu,项目名称:pylearn2,代码行数:27,代码来源:test_yaml_parse.py
示例4: get_representations_for_joint_layer
def get_representations_for_joint_layer(yaml_file_path, save_path, batch_size):
"""
The purpose of doing this is to test the compatibility of DBM with StackBlocks and TransformerDatasets
Of course one can instead take use the "get_represenations.py" for data preparation for the next step.
"""
hyper_params = {'save_path':save_path}
yaml = open("{0}/stacked_image_unimodaliy.yaml".format(yaml_file_path), 'r').read()
yaml = yaml % (hyper_params)
image_stacked_blocks = yaml_parse.load(yaml)
yaml = open("{0}/stacked_text_unimodaliy.yaml".format(yaml_file_path), 'r').read()
yaml = yaml % (hyper_params)
text_stacked_blocks = yaml_parse.load(yaml)
image_raw = Flickr_Image_Toronto(which_cat = 'unlabelled',which_sub='nnz', using_statisfile = True)
image_rep = TransformerDataset( raw = image_raw, transformer = image_stacked_blocks )
m, n = image_raw.get_data().shape()
dw = data_writer.DataWriter(['image_h2_rep'], save_path + 'image/', '10G', [n], m)
image_iterator = image_rep.iterator(batch_size= batch_size)
for data in image_iterator:
dw.Submit(data)
dw.Commit()
text_raw = Flickr_Text_Toronto(which_cat='unlabelled')
text_rep = TransformerDataset( raw = text_raw, transformer = text_stacked_blocks )
m, n = text_raw.get_data().shape()
dw = data_writer.DataWriter(['text_h2_rep'], save_path + 'text/', '10G', [n], m)
text_iterator = text_rep.iterator(batch_size= batch_size)
for data in text_iterator:
dw.Submit(data)
dw.Commit()
开发者ID:airingzhang,项目名称:pylearn2,代码行数:32,代码来源:test_multimodal_dbn.py
示例5: main
def main(argv):
try:
opts, args = getopt.getopt(argv, '')
student_yaml = args[0]
except getopt.GetoptError:
usage()
sys.exit(2)
#
# TRAIN WITH TARGETS
#
# Load student
with open(student_yaml, "r") as sty:
student = yaml_parse.load(sty)
# Remove teacher decay over epoch if there is one
for ext in range(len(student.extensions)):
if isinstance(student.extensions[ext],TeacherDecayOverEpoch):
del student.extensions[ext]
student.algorithm.cost = MethodCost(method='cost_from_X')
# Change save paths
for ext in range(len(student.extensions)):
if isinstance(student.extensions[ext],MonitorBasedSaveBest):
student.extensions[ext].save_path = student.save_path[0:-4] + "_noteacher_best.pkl"
student.save_path = student.save_path[0:-4] + "_noteacher.pkl"
student.main_loop()
#
# TRAIN WITH TEACHER (TOP LAYER)
#
# Load student
with open(student_yaml, "r") as sty:
student = yaml_parse.load(sty)
# Change save paths
for ext in range(len(student.extensions)):
if isinstance(student.extensions[ext],MonitorBasedSaveBest):
student.extensions[ext].save_path = student.save_path[0:-4] + "_toplayer_best.pkl"
student.save_path = student.save_path[0:-4] + "_toplayer.pkl"
student.main_loop()
#
# TRAIN WITH HINTS
#
hints.main([student_yaml, 'conv'])
开发者ID:ballasn,项目名称:facedet,代码行数:54,代码来源:run_all.py
示例6: test_multi_constructor_obj
def test_multi_constructor_obj():
"""
Tests whether multi_constructor_obj throws an exception when
the keys in mapping are None.
"""
try:
load("a: !obj:decimal.Decimal { 1 }")
except TypeError as e:
assert str(e) == "Received non string object (1) as key in mapping."
pass
except Exception as e:
error_msg = "Got the unexpected error: %s" % (e)
reraise_as(ValueError(error_msg))
开发者ID:MarCnu,项目名称:pylearn2,代码行数:13,代码来源:test_yaml_parse.py
示例7: get_dataset_timitVowels20ms9Frames_MFCC
def get_dataset_timitVowels20ms9Frames_MFCC():
print('loading timitVowels20ms9Frames_MFCC dataset...')
template = \
"""!obj:pylearn2.datasets.timitVowels20ms9Frames_MFCC.timit.TIMIT {
classes_number: 32,
which_set: %s,
}"""
trainset = yaml_parse.load(template % "train")
validset = yaml_parse.load(template % "valid")
# testset = yaml_parse.load(template % "test")
print('...done loading timitVowels20ms9Frames_MFCC.')
return trainset, validset
开发者ID:giogix2,项目名称:TIMIT-Speech-Recognition,代码行数:15,代码来源:run_deep_trainer.py
示例8: test_convolutional_network
def test_convolutional_network():
"""Test smaller version of convolutional_network.ipynb"""
skip.skip_if_no_data()
yaml_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..'))
save_path = os.path.dirname(os.path.realpath(__file__))
# Escape potential backslashes in Windows filenames, since
# they will be processed when the YAML parser will read it
# as a string
save_path.replace('\\', r'\\')
yaml = open("{0}/conv.yaml".format(yaml_file_path), 'r').read()
hyper_params = {'train_stop': 50,
'valid_stop': 50050,
'test_stop': 50,
'batch_size': 50,
'output_channels_h2': 4,
'output_channels_h3': 4,
'max_epochs': 1,
'save_path': save_path}
yaml = yaml % (hyper_params)
train = yaml_parse.load(yaml)
train.main_loop()
try:
os.remove("{}/convolutional_network_best.pkl".format(save_path))
except OSError:
pass
开发者ID:123fengye741,项目名称:pylearn2,代码行数:28,代码来源:test_convnet.py
示例9: main
def main(args):
dataset_name = args.dataset_name
logger.info("Getting dataset info for %s" % dataset_name)
data_path = serial.preprocess("${PYLEARN2_NI_PATH}/" + dataset_name)
mask_file = path.join(data_path, "mask.npy")
mask = np.load(mask_file)
input_dim = (mask == 1).sum()
user = path.expandvars("$USER")
save_path = serial.preprocess("/export/mialab/users/%s/pylearn2_outs/%s"
% (user, "rbm_simple_test"))
# File parameters are path specific ones (not model specific).
file_params = {"save_path": save_path,
}
yaml_template = open(yaml_file).read()
hyperparams = expand(flatten(experiment.default_hyperparams(input_dim=input_dim)),
dict_type=ydict)
# Set additional hyperparams from command line args
if args.learning_rate is not None:
hyperparams["learning_rate"] = args.learning_rate
if args.batch_size is not None:
hyperparams["batch_size"] = args.batch_size
for param in file_params:
yaml_template = yaml_template.replace("%%(%s)s" % param, file_params[param])
yaml = yaml_template % hyperparams
logger.info("Training")
train = yaml_parse.load(yaml)
train.main_loop()
开发者ID:ecastrow,项目名称:pl2mind,代码行数:35,代码来源:simple_train.py
示例10: main
def main():
parser = make_parser()
args = parser.parse_args()
model = cPickle.load(args.model)
src = model.dataset_yaml_src
test = yaml_parse.load(src)
test = test.get_test_set()
assert test.X.shape[0] == 10000
test.X = test.X.astype('float32')
test.y = test.y.astype('float32')
X = test.X
y = test.y
Xb = model.get_input_space().make_batch_theano()
Xb.name = 'Xb'
yb = model.get_output_space().make_batch_theano()
yb.name = 'yb'
# W/2 network
fn = make_error_fn(Xb, model.fprop(Xb), yb)
mf_test_error = measure_test_error(fn, X, y, batch_size=args.batch_size)
print "Test error: %f" % mf_test_error
num_masks = range(args.low_samples, args.high_samples, args.step_samples)
results = np.empty((args.repeats, len(num_masks)), dtype='float64')
for i, n_masks in enumerate(num_masks):
print "Gathering results for n_masks = %d..." % n_masks
out = sampled_dropout_average(model, Xb, n_masks,
per_example=args.per_example,
input_include_probs={'h0': args.h0_prob},
input_scales={'h0': args.h0_scale})
f = make_error_fn(Xb, out, yb)
for rep in xrange(args.repeats):
print "Repeat %d" % (rep + 1)
results[rep, i] = measure_test_error(f, X, y,
batch_size=args.batch_size)
print "Done."
np.save(args.outfile, results)
开发者ID:dwf,项目名称:dropout-paper,代码行数:35,代码来源:gather_ensemble_test_errors.py
示例11: train_one_stage
def train_one_stage(model_yaml, dataset=None, max_epochs=500):
"""
Train a stage of the cascade
Return the path to the best model.
----------------------------------
model_yaml : YAML file defining the model
dataset : dataset object to train on
model_file : target of save
max_epochs : number of training epochs
"""
with open(model_yaml, "r") as m_y:
model = yaml_parse.load(m_y)
print "Loaded YAML"
# Define the length of training
model.algorithm.termination_criterion._max_epochs = max_epochs
if dataset is not None:
# We use the specified dataset
model.dataset = dataset
# Train model
model.main_loop()
# Return the path to the best model obtained
best_model_file = model.extensions[0].save_path
return best_model_file
开发者ID:ballasn,项目名称:facedet,代码行数:27,代码来源:train_cascade.py
示例12: test_parse_null_as_none
def test_parse_null_as_none():
"""
Tests whether None may be passed via yaml kwarg null.
"""
initialize()
yamlfile = """{
"model": !obj:pylearn2.models.autoencoder.Autoencoder {
"nvis" : 1024,
"nhid" : 64,
"act_enc" : Null,
"act_dec" : null
}
}"""
load(yamlfile)
开发者ID:MarCnu,项目名称:pylearn2,代码行数:16,代码来源:test_yaml_parse.py
示例13: train_layer3
def train_layer3(patient_id, leave_one_out_seizure, data_path, yaml_file_path, save_model_path):
"""
Script to pre-train the softmax layers.
Parameter settings are specified in yaml files.
Parameters
----------
patient_id : int
Patient ID.
leave_one_out_seizure : int
Index of the withheld seizure.
data_path : string
Path to the directory of the database.
yaml_file_path : string
Path to the directory of the yaml files.
save_model_path : string
Path to the directory to save the trained model.
"""
yaml = open("{0}/sdae_l3.yaml".format(yaml_file_path), 'r').read()
hyper_params = {'patient_id': patient_id,
'leave_one_out_seizure': leave_one_out_seizure,
'window_size': 256,
'batch_size': 20,
'monitoring_batches': 5,
'nvis': 500,
'n_classes': 2,
'max_epochs': 20,
'data_path': data_path,
'save_path': save_model_path}
yaml = yaml % (hyper_params)
train = yaml_parse.load(yaml)
train.main_loop()
开发者ID:akaraspt,项目名称:epilepsy-system,代码行数:35,代码来源:sdae_train_epilepsiae.py
示例14: Transform
def Transform():
"""Test smaller version of convolutional_network.ipynb"""
which_experiment = "S100"
skip.skip_if_no_data()
yaml_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
data_dir = string_utils.preprocess("${PYLEARN2_DATA_PATH}")
save_path = os.path.join(data_dir, "cifar10", "experiment_" + string.lower(which_experiment))
base_save_path = os.path.join(data_dir, "cifar10")
# Escape potential backslashes in Windows filenames, since
# they will be processed when the YAML parser will read it
# as a string
# save_path.replace('\\', r'\\')
yaml = open("{0}/experiment_base_transform.yaml".format(yaml_file_path), "r").read()
hyper_params = {
"batch_size": 64,
"output_channels_h1": 64,
"output_channels_h2": 128,
"output_channels_h3": 600,
"max_epochs": 100,
"save_path": save_path,
"base_save_path": base_save_path,
}
yaml = yaml % (hyper_params)
train = yaml_parse.load(yaml)
train.main_loop()
开发者ID:CKehl,项目名称:pylearn2,代码行数:26,代码来源:train_experiment_base.py
示例15: test_train_example
def test_train_example():
# path definition
train_path = cwd = os.getcwd()
data_path = os.path.join(train_path, '..', '..', '..', '..', 'datasets', 'gtsrb', 'preprocessed')
grbm_path = os.path.join(train_path, '..', 'grbm', 'grbm_gtsrb.pkl')
grbm = serial.load(grbm_path)
NVIS = grbm.nhid
try:
os.chdir(train_path)
# load and train first layer
if DROPOUT:
train_yaml_path = os.path.join(train_path, 'mlp_gtsrb_dropout.yaml')
else:
train_yaml_path = os.path.join(train_path, 'mlp_gtsrb.yaml')
layer1_yaml = open(train_yaml_path, 'r').read()
hyper_params_l1 = {'batch_size': 100,
'nvis': NVIS,
'n_h0': N_HIDDEN_0,
'n_h1': N_HIDDEN_1,
'max_epochs': MAX_EPOCHS,
'data_path' : data_path,
'grbm_path' : grbm_path,
}
layer1_yaml = layer1_yaml % (hyper_params_l1)
train = yaml_parse.load(layer1_yaml)
print '\nTraining...\n'
train.main_loop()
finally:
os.chdir(cwd)
开发者ID:carloderamo,项目名称:DBM-GTSRB,代码行数:35,代码来源:test_mlp_gtsrb.py
示例16: test_convolutional_network
def test_convolutional_network():
"""Test smaller version of convolutional_network.ipynb"""
# skip.skip_if_no_data()
print "hi"
yaml_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
save_path = os.path.dirname(os.path.realpath(__file__))
# Escape potential backslashes in Windows filenames, since
# they will be processed when the YAML parser will read it
# as a string
save_path.replace("\\", r"\\")
yaml = open("{0}/conv.yaml".format(yaml_file_path), "r").read()
hyper_params = {
"train_stop": 50,
"valid_stop": 50050,
"test_stop": 50,
"batch_size": 50,
"output_channels_h2": 4,
"output_channels_h3": 4,
"max_epochs": 1,
"save_path": save_path,
}
yaml = yaml % (hyper_params)
train = yaml_parse.load(yaml)
train.main_loop()
try:
os.remove("{}/convolutional_network_best.pkl".format(save_path))
except OSError:
pass
开发者ID:idocoh,项目名称:ISH_Lasagne,代码行数:30,代码来源:test_convnet.py
示例17: mlpwd_train_850
def mlpwd_train_850(filename,
dim_v=850,
dim_h=1700,
wd=.0005,
foldi=1):
save_path = save_path_tmp.format("-" + str(dim_h), "", "", wd, filename)
dim_h1 = dim_h0 = dim_h
yaml_path = "mlp_tutorial_part_4.yaml"
with open(yaml_path, 'r') as f:
train_2 = f.read()
hyper_params = {'foldi': foldi,
'nvis': dim_v,
'dim_h0': dim_h0,
'dim_h1': dim_h1,
# 'sparse_init_h1': 15,
'max_epochs': MAX_EPOCHS,
'save_path': save_path}
train_2 = train_2 % (hyper_params)
train_2 = yaml_parse.load(train_2)
print "save to {}".format(save_path)
train_2.main_loop()
return save_path
开发者ID:jackal092927,项目名称:pylearn2_med,代码行数:25,代码来源:mlp_train.py
示例18: experiment
def experiment(state, channel):
"""
Experiment function.
Used by jobman to run jobs. Must be loaded externally.
Parameters
----------
state: WRITEME
channel: WRITEME
"""
yaml_template = open(yaml_file).read()
hyper_parameters = expand(flatten(state.hyper_parameters), dict_type=ydict)
file_params = expand(flatten(state.file_parameters), dict_type=ydict)
# Hack to fill in file parameter strings first
for param in file_params:
yaml_template = yaml_template.replace("%%(%s)s" % param, file_params[param])
yaml = yaml_template % hyper_parameters
train_object = yaml_parse.load(yaml)
state.pid = os.getpid()
channel.save()
train_object.main_loop()
state.results = extract_results(train_object.model)
return channel.COMPLETE
开发者ID:ecastrow,项目名称:pl2mind,代码行数:28,代码来源:nice_experiment_normalization.py
示例19: show_negative_chains
def show_negative_chains(model_path):
"""
Display negative chains.
Parameters
----------
model_path: str
The path to the model pickle file
"""
model = serial.load(model_path)
try:
control.push_load_data(False)
dataset = yaml_parse.load(model.dataset_yaml_src)
finally:
control.pop_load_data()
try:
layer_to_chains = model.layer_to_chains
except AttributeError:
print("This model doesn't have negative chains.")
quit(-1)
vis_chains = get_vis_chains(layer_to_chains, model, dataset)
m = vis_chains.shape[0]
grid_shape = get_grid_shape(m)
return create_patch_viewer(grid_shape, vis_chains, m)
开发者ID:123fengye741,项目名称:pylearn2,代码行数:29,代码来源:show_negative_chains.py
示例20: test
def test():
skip_if_no_data()
dirname = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
with open(os.path.join(dirname, 'sr_dataset.yaml'), 'r') as f:
dataset = f.read()
hyper_params = {'train_stop': 50}
dataset = dataset % (hyper_params)
with open(os.path.join(dirname, 'sr_model.yaml'), 'r') as f:
model = f.read()
with open(os.path.join(dirname, 'sr_algorithm.yaml'), 'r') as f:
algorithm = f.read()
hyper_params = {'batch_size': 10,
'valid_stop': 50050}
algorithm = algorithm % (hyper_params)
with open(os.path.join(dirname, 'sr_train.yaml'), 'r') as f:
train = f.read()
train = train % locals()
train = yaml_parse.load(train)
train.main_loop()
开发者ID:bobchennan,项目名称:pylearn2,代码行数:28,代码来源:test_softmaxreg.py
注:本文中的pylearn2.config.yaml_parse.load函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论