class_docstr: Subclass which represents work pieces for adversarial defenses.
docstr: Initializes work pieces from classification batches.
  
  Args:
    class_batches: dict with classification batches, could be obtained
      as ClassificationBatches.data
    num_shards: number of shards to split data into,
      if None then no sharding is done.
code: def init_from_class_batches(self, class_batches, num_shards=None):
      """Initializes work pieces from classification batches.
  
      Args:
        class_batches: dict with classification batches, could be obtained
          as ClassificationBatches.data
        num_shards: number of shards to split data into,
          if None then no sharding is done.
      """
      shards_for_submissions = {}
      shard_idx = 0
      for idx, (batch_id, batch_val) in enumerate(
          iteritems(class_batches)
      ):
          work_id = DEFENSE_WORK_ID_PATTERN.format(idx)
          submission_id = batch_val["submission_id"]
          shard_id = None
          if num_shards:
              shard_id = shards_for_submissions.get(submission_id)
              if shard_id is None:
                  shard_id = shard_idx % num_shards
                  shards_for_submissions[submission_id] = shard_id
                  shard_idx += 1
          # Note: defense also might have following fields populated by worker:
          # stat_correct, stat_error, stat_target_class, stat_num_images
          self.work[work_id] = {
              "claimed_worker_id": None,
              "claimed_worker_start_time": None,
              "is_completed": False,
              "error": None,
              "elapsed_time": None,
              "submission_id": submission_id,
              "shard_id": shard_id,
              "output_classification_batch_id": batch_id,
          }
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from builtins import int
  from io import StringIO
  import pickle
  import random
  import time
  import numpy
  from six import iteritems
  from six import itervalues
  from six import text_type
label_desc: Use image node_id 2 for calling the DefenseWorkPieces obj's underlying member method code with example usage: obj.init_from_class_batches(class_batches, num_shards) without return types