<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 LeNET
Here we define the famous LENET neural network, but you can define any deep neural network of your choice.
Step1:  DeepWater for MXNET
We can use the import functions provided by h2o to import the list of
Step2:  Let's create the lenet model architecture from scratch using the MXNet Python API
Step3:  To import the model inside the DeepWater training engine we need to save the model to a file
Step4:  The model is just the structure of the network expressed as a json dict
Step5:  Importing the LeNET model architecture for training in H2O
We have defined the model and saved the structure to a file. We are ready to start the training procedure.
<ASSISTANT_TASK:>
Python Code:
def lenet(num_classes):
    import mxnet as mx
    data = mx.symbol.Variable('data')
    # first conv
    conv1 = mx.symbol.Convolution(data=data, kernel=(5,5), num_filter=20)
    tanh1 = mx.symbol.Activation(data=conv1, act_type="tanh")
    pool1 = mx.symbol.Pooling(data=tanh1, pool_type="max", kernel=(2,2), stride=(2,2))
    # second conv
    conv2 = mx.symbol.Convolution(data=pool1, kernel=(5,5), num_filter=50)
    tanh2 = mx.symbol.Activation(data=conv2, act_type="tanh")
    pool2 = mx.symbol.Pooling(data=tanh2, pool_type="max", kernel=(2,2), stride=(2,2))
    # first fullc
    flatten = mx.symbol.Flatten(data=pool2)
    fc1 = mx.symbol.FullyConnected(data=flatten, num_hidden=500)
    tanh3 = mx.symbol.Activation(data=fc1, act_type="tanh")
    # second fullc
    fc2 = mx.symbol.FullyConnected(data=tanh3, num_hidden=num_classes)
    # loss
    lenet = mx.symbol.SoftmaxOutput(data=fc2, name='softmax')
    return lenet
Explanation: LeNET
Here we define the famous LENET neural network, but you can define any deep neural network of your choice.
End of explanation
train = h2o.import_file("../../bigdata/laptop/mnist/train.csv.gz")
test = h2o.import_file("../../bigdata/laptop/mnist/test.csv.gz")
predictors = list(range(0,784))
resp = 784
train[resp] = train[resp].asfactor()
test[resp] = test[resp].asfactor()
nclasses = train[resp].nlevels()[0]
Explanation: DeepWater for MXNET
We can use the import functions provided by h2o to import the list of
End of explanation
model = lenet(nclasses)
Explanation: Let's create the lenet model architecture from scratch using the MXNet Python API
End of explanation
model_path = "/tmp/symbol_lenet-py.json"
model.save(model_path)
Explanation: To import the model inside the DeepWater training engine we need to save the model to a file:
End of explanation
#!head "/tmp/symbol_lenet-py.json"
Explanation: The model is just the structure of the network expressed as a json dict
End of explanation
model = H2ODeepWaterEstimator(epochs=100, learning_rate=1e-3, 
                              mini_batch_size=64,
                              network='user', 
                              network_definition_file=model_path,
                              image_shape=[28,28], channels=1)
model.train(x=predictors,y=resp, training_frame=train, validation_frame=test)
model.show()
Explanation: Importing the LeNET model architecture for training in H2O
We have defined the model and saved the structure to a file. We are ready to start the training procedure.
End of explanation
<END_TASK>