code: def test_model_serialize(backend_default, data):
      dataset = MNIST(path=data)
      (X_train, y_train), (X_test, y_test), nclass = dataset.load_data()
      train_set = ArrayIterator(
          [X_train, X_train], y_train, nclass=nclass, lshape=(1, 28, 28)
      )
  
      init_norm = Gaussian(loc=0.0, scale=0.01)
  
      # initialize model
      path1 = Sequential(
          [
              Conv(
                  (5, 5, 16),
                  init=init_norm,
                  bias=Constant(0),
                  activation=Rectlin(),
              ),
              Pooling(2),
              Affine(
                  nout=20,
                  init=init_norm,
                  bias=init_norm,
                  activation=Rectlin(),
              ),
          ]
      )
      path2 = Sequential(
          [
              Affine(
                  nout=100,
                  init=init_norm,
                  bias=Constant(0),
                  activation=Rectlin(),
              ),
              Dropout(keep=0.5),
              Affine(
                  nout=20,
                  init=init_norm,
                  bias=init_norm,
                  activation=Rectlin(),
              ),
          ]
      )
      layers = [
          MergeMultistream(layers=[path1, path2], merge="stack"),
          Affine(
              nout=20,
              init=init_norm,
              batch_norm=True,
              activation=Rectlin(),
          ),
          Affine(
              nout=10,
              init=init_norm,
              activation=Logistic(shortcut=True),
          ),
      ]
  
      tmp_save = "test_model_serialize_tmp_save.pickle"
      mlp = Model(layers=layers)
      mlp.optimizer = GradientDescentMomentum(
          learning_rate=0.1, momentum_coef=0.9
      )
      mlp.cost = GeneralizedCost(costfunc=CrossEntropyBinary())
      mlp.initialize(train_set, cost=mlp.cost)
      n_test = 3
      num_epochs = 3
      # Train model for num_epochs and n_test batches
      for epoch in range(num_epochs):
          for i, (x, t) in enumerate(train_set):
              x = mlp.fprop(x)
              delta = mlp.cost.get_errors(x, t)
              mlp.bprop(delta)
              mlp.optimizer.optimize(
                  mlp.layers_to_optimize, epoch=epoch
              )
              if i > n_test:
                  break
  
      # Get expected outputs of n_test batches and states of all layers
      outputs_exp = []
      pdicts_exp = [
          l.get_params_serialize() for l in mlp.layers_to_optimize
      ]
      for i, (x, t) in enumerate(train_set):
          outputs_exp.append(mlp.fprop(x, inference=True))
          if i > n_test:
              break
  
      # Serialize model
      mlp.save_params(tmp_save, keep_states=True)
  
      # Load model
      mlp = Model(tmp_save)
  
      mlp.initialize(train_set)
      outputs = []
      pdicts = [
          l.get_params_serialize() for l in mlp.layers_to_optimize
      ]
      for i, (x, t) in enumerate(train_set):
          outputs.append(mlp.fprop(x, inference=True))
          if i > n_test:
              break
  
      # Check outputs, states, and params are the same
      for output, output_exp in zip(outputs, outputs_exp):
          assert allclose_with_out(output.get(), output_exp.get())
  
      for pd, pd_exp in zip(pdicts, pdicts_exp):
          for s, s_e in zip(pd["states"], pd_exp["states"]):
              if isinstance(s, list):  # this is the batch norm case
                  for _s, _s_e in zip(s, s_e):
                      assert allclose_with_out(_s, _s_e)
              else:
                  assert allclose_with_out(s, s_e)
          for p, p_e in zip(pd["params"], pd_exp["params"]):
              assert type(p) == type(p_e)
              if isinstance(p, list):  # this is the batch norm case
                  for _p, _p_e in zip(p, p_e):
                      assert allclose_with_out(_p, _p_e)
              elif isinstance(p, np.ndarray):
                  assert allclose_with_out(p, p_e)
              else:
                  assert p == p_e
  
      os.remove(tmp_save)
  
file_path: neon/tests/test_model.py
imports: from builtins import zip
  import numpy
  import os
  from neon.backends import gen_backend
  from neon.data import ArrayIterator, MNIST, PTB
  from neon.initializers import Gaussian, Constant
  from neon.layers import GeneralizedCost, Affine, DeepBiRNN, DeepBiLSTM, LSTM, GRU, Dropout, Conv, Pooling, Sequential, MergeMultistream, Recurrent, RecurrentMean
  from neon.models import Model
  from neon.optimizers import GradientDescentMomentum
  from neon.transforms import Rectlin, Logistic, CrossEntropyBinary
  from utils import allclose_with_out
  from neon import NervanaObject
label_desc: Use image node_id 4 for calling a global function with example usage: test_model_serialize(backend_default, data) without return types