Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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
Esempio n. 4
0
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)
Esempio n. 5
0
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)
Esempio n. 6
0
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)
Esempio n. 7
0
def test_duplicate_keywords_2():
    """
    Tests whether duplicate keywords as independent parameters works fine.
    """
    initialize()
    yamlfile = """{
             "model": !obj:pylearn2.models.rbm.GaussianBinaryRBM {

                 "vis_space" : &vis_space !obj:pylearn2.space.Conv2DSpace {
                    "shape" : [32,32],
                    "num_channels" : 3
                },
                "hid_space" : &hid_space !obj:pylearn2.space.Conv2DSpace {
                    "shape" : [27,27],
                    "num_channels" : 10
                },
                "transformer" :
                        !obj:pylearn2.linear.conv2d.make_random_conv2D {
                    "irange" : .05,
                    "input_space" : *vis_space,
                    "output_space" : *hid_space,
                    "kernel_shape" : [6,6],
                    "batch_size" : &batch_size 5
                },
                "energy_function_class" :
                     !obj:pylearn2.energy_functions.rbm_energy.grbm_type_1 {},
                "learn_sigma" : True,
                "init_sigma" : .3333,
                "init_bias_hid" : -2.,
                "mean_vis" : False,
                "sigma_lr_scale" : 1e-3

             }
    }"""

    loaded = load(yamlfile)
Esempio n. 8
0
def test_parse_null_as_none():
    """
    Tests whether None may be passed via yaml kwarg null.
    """ 
    initialize()
    yamlfile = """{