class_docstr: Class for testing GRU layer
class_docstr_tok: ["Class","for","testing","GRU","layer"]
code: def _test_gru_layer(self, keras_major_version, limit=None):
      i = 0
      numerical_err_models = []
      shape_err_models = []
      params = list(
          itertools.product(
              self.base_layer_params, self.gru_layer_params
          )
      )
      np.random.shuffle(params)
      params = [
          param
          for param in params
          if valid_params(dict(zip(self.params_dict.keys(), param[0])))
      ]
      for base_params, gru_params in params[:limit]:
          base_params = dict(zip(self.params_dict.keys(), base_params))
          gru_params = dict(
              zip(self.gru_params_dict.keys(), gru_params)
          )
          input_data = generate_input(
              base_params["input_dims"][0],
              base_params["input_dims"][1],
              base_params["input_dims"][2],
          )
          model = Sequential()
          settings = dict(
              activation=base_params["activation"],
              return_sequences=base_params["return_sequences"],
              go_backwards=base_params["go_backwards"],
              unroll=base_params["unroll"],
          )
          if keras_major_version == 2:
              model.add(
                  GRU(
                      base_params["output_dim"],
                      input_shape=base_params["input_dims"][1:],
                      recurrent_dropout=gru_params["dropout"][
                          "dropout_U"
                      ],
                      dropout=gru_params["dropout"]["dropout_W"],
                      kernel_regularizer=gru_params["regularizer"][
                          "W_regularizer"
                      ],
                      recurrent_regularizer=gru_params["regularizer"][
                          "U_regularizer"
                      ],
                      bias_regularizer=gru_params["regularizer"][
                          "b_regularizer"
                      ],
                      **settings,
                  )
              )
          else:
              model.add(
                  GRU(
                      base_params["output_dim"],
                      input_length=base_params["input_dims"][1],
                      input_dim=base_params["input_dims"][2],
                      dropout_U=gru_params["dropout"]["dropout_U"],
                      dropout_W=gru_params["dropout"]["dropout_W"],
                      W_regularizer=gru_params["regularizer"][
                          "W_regularizer"
                      ],
                      U_regularizer=gru_params["regularizer"][
                          "U_regularizer"
                      ],
                      b_regularizer=gru_params["regularizer"][
                          "b_regularizer"
                      ],
                      **settings,
                  )
              )
          model_dir = tempfile.mkdtemp()
          keras_model_path = os.path.join(model_dir, "keras.h5")
          coreml_model_path = os.path.join(model_dir, "keras.mlmodel")
          model.save_weights(keras_model_path)
          mlkitmodel = _get_mlkit_model_from_path(
              model, coreml_model_path
          )
          if _is_macos() and _macos_version() >= (10, 13):
              keras_preds = model.predict(input_data).flatten()
              input_data = np.transpose(input_data, [1, 0, 2])
              coreml_preds = mlkitmodel.predict({"data": input_data})[
                  "output"
              ].flatten()
              try:
                  self.assertEquals(
                      coreml_preds.shape, keras_preds.shape
                  )
              except AssertionError:
                  print(
                      "Shape error:\nbase_params: {}\nkeras_preds.shape: {}\ncoreml_preds.shape: {}".format(
                          base_params,
                          keras_preds.shape,
                          coreml_preds.shape,
                      )
                  )
                  shape_err_models.append(base_params)
                  shutil.rmtree(model_dir)
                  i += 1
                  continue
              try:
                  for idx in range(0, len(coreml_preds)):
                      relative_error = (
                          coreml_preds[idx] - keras_preds[idx]
                      ) / coreml_preds[idx]
                      self.assertAlmostEqual(
                          relative_error, 0, places=2
                      )
              except AssertionError:
                  print(
                      "Assertion error:\nbase_params: {}\nkeras_preds: {}\ncoreml_preds: {}".format(
                          base_params, keras_preds, coreml_preds
                      )
                  )
                  numerical_err_models.append(base_params)
          shutil.rmtree(model_dir)
          i += 1
  
      self.assertEquals(
          shape_err_models,
          [],
          msg="Shape error models {}".format(shape_err_models),
      )
      self.assertEquals(
          numerical_err_models,
          [],
          msg="Numerical error models {}".format(numerical_err_models),
      )
  
imports: import unittest
  import numpy
  import os
  import shutil
  import tempfile
  import itertools
  import coremltools
  from coremltools._deps import _HAS_KERAS_TF, _HAS_KERAS2_TF
  from coremltools.models.utils import _macos_version, _is_macos
  import pytest
label_desc: Use image node_id 2 for calling the GRULayer obj's underlying member method code with example usage: obj._test_gru_layer(keras_major_version, limit) without return types