pluskid / Mocha.jl

Deep Learning framework for Julia
Other
1.29k stars 254 forks source link

SGD Solver method problem #101

Closed jimixxperez closed 9 years ago

jimixxperez commented 9 years ago

I would to like to apply the presented MNIST example CNN to my own data set. However it sticks at the initialization part of the Solver Method, i.e. solver_method=SGD()

_code:

using Mocha 

# -- Build Convolutional Neural Net --
data = HDF5DataLayer(name="data",source="$(hdf5path)/train.txt",tops=[:data, :label],batch_size=100)
conv = ConvolutionLayer(name="conv1",n_filter=10,kernel=(4,4),bottoms=[:data],tops=[:conv])
pool = PoolingLayer(name="pool1", kernel=(2,2),stride=(2,2),bottoms=[:conv],tops=[:pool])
conv2 = ConvolutionLayer(name="conv2",n_filter=50,kernel=(5,5),bottoms=[:pool],tops=[:conv2])
pool2 = PoolingLayer(name="pool2",kernel=(2,2),stride=(2,2),bottoms=[:conv2],tops=[:pool2])
fc1   = InnerProductLayer(name="ip1",output_dim=500,neuron=Neurons.ReLU(),bottoms=[:pool2],
                          tops=[:ip1])
fc2   = InnerProductLayer(name="ip2",output_dim=10,bottoms=[:ip1],tops=[:ip2])
loss  = SoftmaxLossLayer(name="loss",bottoms=[:ip2,:label])

backend = CPUBackend()
init(backend)

common_layers = [conv, pool, conv2, pool2, fc1, fc2]

net = Net("MNIST-train", backend, [data, common_layers..., loss])

exp_dir = hdf5path
solver_method = SGD()
params = make_solver_parameters(solver_method, max_iter=10000, regu_coef=0.0005,
    mom_policy=MomPolicy.Fixed(0.9),
    lr_policy=LRPolicy.Inv(0.01, 0.0001, 0.75),
    load_from=exp_dir)
solver = Solver(solver_method, params)

setup_coffee_lounge(solver, save_into="$(exp_dir)/statistics.jld", every_n_iter=1000)

# report training progress every 100 iterations
add_coffee_break(solver, TrainingSummary(), every_n_iter=100)

# save snapshots every 5000 iterations
add_coffee_break(solver, Snapshot(exp_dir), every_n_iter=5000)

# show performance on test data every 1000 iterations
#data_test = HDF5DataLayer(name="test-data",source="test-data-list.txt",batch_size=100)
#accuracy = AccuracyLayer(name="test-accuracy",bottoms=[:ip2, :label])
#test_net = Net("MNIST-test", backend, [data_test, common_layers..., accuracy])
#add_coffee_break(solver, ValidationPerformance(test_net), every_n_iter=1000)

#solve(solver, net)

destroy(net)
#destroy(test_net)
shutdown(backend)
'''

_the error message is:

10-Sep 13:16:39:INFO:root:Constructing net MNIST-train on CPUBackend...
10-Sep 13:16:39:INFO:root:Topological sorting 8 layers...
10-Sep 13:16:39:INFO:root:Setup layers...
10-Sep 13:16:39:INFO:root:Network constructed!
`SGD` has no method matching SGD()
while loading In[6], in expression starting on line 22

I don't really know what to do. Can someone please tell what I'm missing?

Cheers 
benmoran commented 9 years ago

@jimixxperez the solver interface is changed in my patch merged by @pluskid yesterday. The snippet you give above should be correct for the new code. Is the rest of your checkout fully updated from Git? I'll try a fresh checkout and see if it behaves for me.

pluskid commented 9 years ago

@jimixxperez the online doc has been updated to a new solver API incompatible with the old API. I suggest reading the document with v0.0.9 instead of latest, at here: http://mochajl.readthedocs.org/en/v0.0.9/tutorial/mnist.html

For example code of MNIST. Please refer to the locally installed version, usually at ~/.julia/v0.3/Mocha/examples/mnist.

AurelienDecelle commented 9 years ago

Hi,

I had the same problem and looked at the new tutorial. Now I have a problem with the

params = SolverParameters(max_iter=10000, regu_coef=0.0005, mom_policy=MomPolicy.Fixed(0.9), lr_policy=LRPolicy.Inv(0.01,0.0001,0.75), load_from=exp_dir)

it gives the error message : "function Dict does not accept keyword arguments"

Any clue ? (my Julia version is 0.3.11)

A.

benmoran commented 9 years ago

@AurelienDecelle the new tutorial at "latest" http://mochajl.readthedocs.org/en/latest/tutorial/mnist.html suggests a different way of building the parameters:

method = SGD()
params = make_solver_parameters(method, max_iter=10000, regu_coef=0.0005,
  mom_policy=MomPolicy.Fixed(0.9),
  lr_policy=LRPolicy.Inv(0.01, 0.0001, 0.75),
  load_from=exp_dir)

which should work with the latest code on master. The SolverParameters version is the older syntax for the 0.0.9 release.

AurelienDecelle commented 9 years ago

indeed it works, thanx