Exemplo n.º 1
0
def test_convsparsenet(lam_sparse=.1,N=16,perc_var=100.):

    from hdl.models import SparseSlowModel
    from hdl.learners import SGD

    whitenpatches = 1000

    #model = ConvWhitenInputModel(imshp=(10,1,32,32),convwhitenfiltershp=(7,7),perc_var=100.)
    model = ConvSparseSlowModel(imshp=(10,1,28,28),convwhitenfiltershp=(7,7),N=N,kshp=(7,7),perc_var=perc_var,lam_sparse=lam_sparse)

    l = SGD(model=model,datasource='vid075-chunks',display_every=1000,save_every=10000,batchsize=model.imshp[0])

    print 'whitenpatches', whitenpatches
    print 'model.imshp', model.imshp
    print 'model.convwhitenfiltershp', model.convwhitenfiltershp

    databatch = l.get_databatch(whitenpatches)
    l.model.learn_whitening(databatch)

    l.model.setup()

    l.learn(iterations=20000)
    l.change_target(.5)
    l.learn(iterations=5000)
    l.change_target(.5)
    l.learn(iterations=5000)

    #l.learn(iterations=160000)
    #l.change_target(.5)
    #l.learn(iterations=20000)
    #l.change_target(.5)
    #l.learn(iterations=20000)

    from hdl.display import display_final
    display_final(l.model)
Exemplo n.º 2
0
def go(l):

    databatch = l.get_databatch(whitenpatches)
    l.model.learn_whitening(databatch)
    l.model.setup()

    l.learn(iterations=350000)
    l.change_target(.5)
    l.learn(iterations=50000)
    l.change_target(.5)
    l.learn(iterations=50000)
    l.change_target(.5)
    l.learn(iterations=50000)

    display_final(l.model)
Exemplo n.º 3
0
def test_convsparsenet_subspace(lam_sparse=1.,lam_slow=1.,N=8,perc_var=100.,stride=(1,1)):

    from hdl.models import ConvSparseSlowModel
    from hdl.learners import SGD

    whitenpatches = 1000
    psz = 48
    ksz = 16
    convwhitenfiltershp=(15,15)

    #model = ConvWhitenInputModel(imshp=(10,1,32,32),convwhitenfiltershp=(7,7),perc_var=100.)
    model = ConvSparseSlowModel(imshp=(4,1,psz,psz),convwhitenfiltershp=convwhitenfiltershp,N=N,kshp=(ksz,ksz),stride=stride,
        sparse_cost='subspacel1',
        perc_var=perc_var,
        lam_sparse=lam_sparse,
        lam_slow=lam_slow,
        mask=True,
        force_subspace_orthogonal=True)

    l = SGD(model=model,datasource='vid075-chunks',display_every=50,save_every=10000,
            eta_target_maxupdate=0.5,
            batchsize=model.imshp[0])

    print 'whitenpatches', whitenpatches
    print 'model.imshp', model.imshp
    print 'model.convwhitenfiltershp', model.convwhitenfiltershp

    databatch = l.get_databatch(whitenpatches)
    l.model.learn_whitening(databatch)

    l.model.setup()

    l.learn(iterations=1000)
    l.model.center_basis_functions=False
    l.learn(iterations=9000)
    l.change_target(.5)
    l.learn(iterations=5000)
    l.change_target(.5)
    l.learn(iterations=5000)

    #l.learn(iterations=160000)
    #l.change_target(.5)
    #l.learn(iterations=20000)
    #l.change_target(.5)
    #l.learn(iterations=20000)

    from hdl.display import display_final
    display_final(l.model)
Exemplo n.º 4
0
def test_convsparsenet(lam_sparse=.1,N=16,perc_var=100.,stride=1,kshp=(7,7),batchsize=4):

    from hdl.learners import SGD

    whitenpatches = 1000
    if isinstance(kshp,int): kshp = (kshp,kshp)
    if isinstance(stride,int): stride = (stride,stride)
    imszr = 5*stride[0] + kshp[0] - 1
    imszc = 5*stride[1] + kshp[1] - 1

    #model = ConvWhitenInputModel(imshp=(10,1,32,32),convwhitenfiltershp=(7,7),perc_var=100.)
    model = ConvSparseSlowModel(imshp=(batchsize,1,imszr,imszc),convwhitenfiltershp=(7,7),N=N,kshp=kshp,stride=stride,
        perc_var=perc_var,lam_sparse=lam_sparse)

    l = SGD(model=model,datasource='vid075-chunks',display_every=50,save_every=10000,batchsize=model.imshp[0])

    print 'whitenpatches', whitenpatches
    print 'model.imshp', model.imshp
    print 'model.convwhitenfiltershp', model.convwhitenfiltershp

    databatch = l.get_databatch(whitenpatches)
    l.model.learn_whitening(databatch)

    l.model.setup()

    l.learn(iterations=5000)
    l.model.center_basis_functions = False
    l.learn(iterations=15000)
    l.change_target(.5)
    l.learn(iterations=5000)
    l.change_target(.5)
    l.learn(iterations=5000)

    #l.learn(iterations=160000)
    #l.change_target(.5)
    #l.learn(iterations=20000)
    #l.change_target(.5)
    #l.learn(iterations=20000)

    from hdl.display import display_final
    display_final(l.model)
Exemplo n.º 5
0
def test_sparsenet_subspace(lam_sparse=1.,lam_slow=1.,N=8,perc_var=100.):

    from hdl.models import SparseSlowModel
    from hdl.learners import SGD

    whitenpatches = 10000
    psz = 16

    #model = ConvWhitenInputModel(imshp=(10,1,32,32),convwhitenfiltershp=(7,7),perc_var=100.)
    model = SparseSlowModel(patch_sz=psz,N=N,
        sparse_cost='subspacel1',
        perc_var=perc_var,
        lam_sparse=lam_sparse,
        lam_slow=lam_slow,T=48)

    l = SGD(model=model,datasource='vid075-chunks',display_every=100,save_every=10000,batchsize=model.T)

    print 'whitenpatches', whitenpatches

    databatch = l.get_databatch(whitenpatches)
    l.model.learn_whitening(databatch)

    l.model.setup()

    l.learn(iterations=5000)
    l.change_target(.5)
    l.learn(iterations=5000)
    l.change_target(.5)
    l.learn(iterations=5000)

    #l.learn(iterations=160000)
    #l.change_target(.5)
    #l.learn(iterations=20000)
    #l.change_target(.5)
    #l.learn(iterations=20000)

    from hdl.display import display_final
    display_final(l.model)
Exemplo n.º 6
0
    l.model.learn_whitening(databatch)

    newA = np.dot(l.model.whitenmatrix,newA)
    newA = l.model.normalize_A(newA)
    l.model.A.set_value(newA.astype(hdl.models.theano.config.floatX))
    l.model.reset_functions()

    return l

initial_target = l.eta_target_maxupdate

databatch = l.get_databatch(whitenpatches)
l.model.learn_whitening(databatch)
l.model.setup()
l.eta_target_maxupdate
iterations = 2000
l = learn_loop(l,iterations=iterations)
display_final(l.model,save_string='doubling_0')

doublings = 4
for doubling in range(doublings):
    iterations *= 2
    l.eta_target_maxupdate = initial_target
    print 'Doubling model...'
    l = double_patch_sz(l)

    display_final(l.model,save_string='doubling_%d_before_learning'%(doubling+1))
    l = learn_loop(l,iterations=iterations)

    display_final(l.model,save_string='doubling_%d_after_learning'%(doubling+1))
Exemplo n.º 7
0
whitenpatches = 400

convwhitenfiltershp=(11,11)
perc_var = 99.
N = 641
kshp = (16,16)
stride = (8,8)
imsz = kshp[0]*6
imshp=(2,1,imsz,imsz)

print 'Init...'
l = SGD(model=ConvSparseSlowModel(imshp=imshp,convwhitenfiltershp=convwhitenfiltershp,perc_var=perc_var,N=N,kshp=kshp,stride=stride,
        sparse_cost='subspacel1mean',slow_cost=None,lam_sparse=1.,center_basis_functions=False),
        datasource='berkeleysegmentation',batchsize=imshp[0],save_every=20000,display_every=1000,
        ipython_profile=profile)

print 'Estimate whitening...'
databatch = l.get_databatch(whitenpatches)
l.model.learn_whitening(databatch)
l.model.setup()

l.learn(iterations=40000)
l.change_target(.5)
l.learn(iterations=5000)
l.change_target(.5)
l.learn(iterations=5000)

from hdl.display import display_final
display_final(l.model)
Exemplo n.º 8
0
    #model_name = 'SparseSlowModel_patchsz064_N2048_NN2048_l2_l1_None_2012-02-05_15-29-08/SparseSlowModel_patchsz064_N2048_NN2048_l2_l1_None.model'

    # faces
    #model_name = 'SparseSlowModel_patchsz032_N512_NN512_l2_l1_None_2012-02-09_11-40-37/SparseSlowModel_patchsz032_N512_NN512_l2_l1_None.model'
    #model_name = 'SparseSlowModel_patchsz064_N1024_NN1024_l2_l1_None_2012-02-09_11-47-43/SparseSlowModel_patchsz064_N1024_NN1024_l2_l1_None.model'
    #model_name = 'SparseSlowModel_patchsz032_N512_NN512_l2_l1_None_2012-02-09_16-38-31/SparseSlowModel_patchsz032_N512_NN512_l2_l1_None.model'
    #model_name = 'SparseSlowModel_patchsz032_N512_NN512_l2_l1_None_2012-02-09_19-05-45/SparseSlowModel_patchsz032_N512_NN512_l2_l1_None.model'
    model_name = 'SparseSlowModel_patchsz048_N768_NN768_l2_l1_None_2012-02-09_19-07-07/SparseSlowModel_patchsz048_N768_NN768_l2_l1_None.model'
    #model_name = 'SparseSlowModel_patchsz064_N1024_NN1024_l2_l1_None_2012-02-09_19-08-50/SparseSlowModel_patchsz064_N1024_NN1024_l2_l1_None.model'
    model_name = 'SparseSlowModel_patchsz048_N1024_NN1024_l2_l1_None_2012-02-10_16-23-20/SparseSlowModel_patchsz048_N1024_NN1024_l2_l1_None.model'
    model_name = 'SparseSlowModel_patchsz048_N1024_NN1024_l2_subspacel1_None_2012-02-10_17-22-55/SparseSlowModel_patchsz048_N1024_NN1024_l2_subspacel1_None.model'
    model_name = 'SparseSlowModel_patchsz048_N4096_NN4096_l2_l1_None_2012-03-01_19-15-33/SparseSlowModel_patchsz048_N4096_NN4096_l2_l1_None.model'
    model_name = 'SparseSlowModel_patchsz048_N512_NN512_l2_subspacel1_None_2012-03-05_11-42-48/SparseSlowModel_patchsz048_N512_NN512_l2_subspacel1_None.model'

    #fname = os.path.join(state_dir,model_name)
    #m = SparseSlowModel()
    #m.load(fname,reset_theano=False)

    model_name = 'BinocColorModel_patchsz016_N512_NN512_l2_subspacel1_dist_2012-03-13_15-24-27/BinocColorModel_patchsz016_N512_NN512_l2_subspacel1_dist.model'
    model_name = 'BinocColorModel_patchsz016_N512_NN512_l2_subspacel1_dist_2012-03-15_15-56-39/BinocColorModel_patchsz016_N512_NN512_l2_subspacel1_dist.model'
    model_name = 'BinocColorModel_patchsz020_N3200_NN3200_l2_subspacel1_dist_2012-03-18_17-35-13/BinocColorModel_patchsz020_N3200_NN3200_l2_subspacel1_dist.model'

    fname = os.path.join(state_dir,model_name)
    m = BinocColorModel()
    m.load(fname,reset_theano=False)

    display_final(m)

    print m