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,
      }
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.