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)
예제 #2
0
def test_sampled_dropout_average():
    # This is only a smoke test: verifies that it compiles and runs,
    # not any particular value.
    inp = theano.tensor.matrix()
    mlp = MLP(nvis=2, layers=[Linear(2, 'h0', irange=0.8),
                              Linear(2, 'h1', irange=0.8),
                              Softmax(3, 'out', irange=0.8)])
    out = sampled_dropout_average(mlp, inp, 5)
    f = theano.function([inp], out, allow_input_downcast=True)
    f([[2.3, 4.9]])
예제 #3
0
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)