code: def build_model(class_num):
      model = Sequential()
      model.add(Reshape([1, 28, 28]))
      model.add(SpatialConvolution(1, 6, 5, 5))
      model.add(Tanh())
      model.add(SpatialMaxPooling(2, 2, 2, 2))
      model.add(SpatialConvolution(6, 12, 5, 5))
      model.add(Tanh())
      model.add(SpatialMaxPooling(2, 2, 2, 2))
      model.add(Reshape([12 * 4 * 4]))
      model.add(Linear(12 * 4 * 4, 100))
      model.add(Tanh())
      model.add(Linear(100, class_num))
      model.add(LogSoftMax())
  
      # To use MKL-DNN backend, the model has to be a graph model with input and output formats set.
      # Sequential model cannot be used in this case, so we convert it to a graph model.
      if get_bigdl_engine_type() == "MklDnn":
          model = model.to_graph()
  
          # The format index of input or output format can be checked
          # in: ${BigDL-core}/native-dnn/src/main/java/com/intel/analytics/bigdl/mkl/Memory.java
          model.set_input_formats([7])  # Set input format to nchw
          model.set_output_formats([4])  # Set output format to nc
  
      return model
  
file_path: BigDL/python/dllib/src/bigdl/dllib/models/lenet/lenet5.py
imports: from optparse import OptionParser
  from bigdl.dllib.models.lenet.utils import *
  from bigdl.dllib.feature.dataset.transformer import *
  from bigdl.dllib.nn.layer import *
  from bigdl.dllib.nn.criterion import *
  from bigdl.dllib.optim.optimizer import *
  from bigdl.dllib.utils.common import *
  from bigdl.dllib.nncontext import *
  from bigdl.dllib.utils.utils import detect_conda_env_name
  import os
  from bigdl.dllib.utils.log4Error import *
label_desc: Use image node_id 1 for calling a global function with example usage: build_model(class_num) and returns: model