code: def test_pickle(
      art_warning, get_default_mnist_subset, image_dl_estimator
  ):
      try:
          (x_train_mnist, y_train_mnist), (
              x_test_mnist,
              y_test_mnist,
          ) = get_default_mnist_subset
  
          from art import config
  
          full_path = os.path.join(
              config.ART_DATA_PATH, "my_classifier"
          )
          folder = os.path.split(full_path)[0]
          if not os.path.exists(folder):
              os.makedirs(folder)
  
          # The model used within the common ART pytorch get_image_classifier_list does not support pickling
          model = Model()
          loss_fn = nn.CrossEntropyLoss()
          optimizer = optim.Adam(model.parameters(), lr=0.01)
          myclassifier_2 = PyTorchClassifier(
              model=model,
              clip_values=(0, 1),
              loss=loss_fn,
              optimizer=optimizer,
              input_shape=(1, 28, 28),
              nb_classes=10,
          )
          myclassifier_2.fit(
              x_train_mnist, y_train_mnist, batch_size=100, nb_epochs=1
          )
  
          pickle.dump(myclassifier_2, open(full_path, "wb"))
  
          with open(full_path, "rb") as f:
              loaded_model = pickle.load(f)
              np.testing.assert_equal(
                  myclassifier_2._clip_values, loaded_model._clip_values
              )
              assert (
                  myclassifier_2._channels_first
                  == loaded_model._channels_first
              )
              assert set(myclassifier_2.__dict__.keys()) == set(
                  loaded_model.__dict__.keys()
              )
  
          # Test predict
          predictions_1 = myclassifier_2.predict(x_test_mnist)
          accuracy_1 = (
              np.sum(
                  np.argmax(predictions_1, axis=1)
                  == np.argmax(y_test_mnist, axis=1)
              )
              / y_test_mnist.shape[0]
          )
          predictions_2 = loaded_model.predict(x_test_mnist)
          accuracy_2 = (
              np.sum(
                  np.argmax(predictions_2, axis=1)
                  == np.argmax(y_test_mnist, axis=1)
              )
              / y_test_mnist.shape[0]
          )
          assert accuracy_1 == accuracy_2
      except ARTTestException as e:
          art_warning(e)
  
file_path: adversarial-robustness-toolbox/tests/estimators/classification/test_deeplearning_specific.py
imports: import os
  import logging
  import numpy
  import pytest
  import pickle
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from art.estimators.classification.pytorch import PyTorchClassifier
  from tests.utils import ARTTestException
label_desc: Use image node_id 2 for calling a global function with example usage: test_pickle(art_warning, get_default_mnist_subset, image_dl_estimator) without return types