from tfs.models import LeNet
from tfs.dataset import Mnist
net = LeNet()
dataset = Mnist()

"""
Explanation: Save and Load
In this notebook, we will 
- train a LeNet and save it
- load the model from the file
- test the loaded model
End of explanation
"""


from tfs.core.optimizer import GradientDecentOptimizer
from tfs.core.regularizers import L1

net.optimizer = GradientDecentOptimizer(net)
net.regularizer = L1(net,l1=0.001)

net.build()

net.fit(dataset,batch_size=200,n_epoch=1,max_step=100)

net.save('lenet_epoch_1')

!ls ./

"""
Explanation: modify the network:
L1 regularizer
SGD optimizer
End of explanation
"""


from tfs.network import Network
net2 = Network()
net2.load('lenet_epoch_1')

print net2

print net2.optimizer

print net2.initializer

print net2.losser

print 'accuracy',net2.score(dataset.test)

"""
Explanation: load the model
End of explanation
"""


net2.fit(dataset,batch_size=200,n_epoch=1,max_step=100)

net2.score(dataset.test)

"""
Explanation: fine-tune the loaded model
End of explanation
"""


