def setUpTestData(cls):
        batch_num = 0
        section_num = 0
        voter_num = 0
        party_num = 0
        position_num = 0
        candidate_num = 0
        num_elections = 2
        voters = list()
        positions = dict()
        for i in range(num_elections):
            election = Election.objects.create(name='Election {}'.format(i))
            positions[str(election.name)] = list()

            num_batches = 2
            for j in range(num_batches):
                batch = Batch.objects.create(year=batch_num, election=election)
                batch_num += 1

                num_sections = 2 if j == 0 else 1
                for k in range(num_sections):
                    section = Section.objects.create(
                        section_name=str(section_num)
                    )
                    section_num += 1

                    num_students = 2
                    for l in range(num_students):
                        voter = User.objects.create(
                            username='user{}'.format(voter_num),
                            first_name=str(voter_num),
                            last_name=str(voter_num),
                            type=UserType.VOTER
                        )
                        voter.set_password('voter')
                        voter.save()
                        voter_num += 1

                        VoterProfile.objects.create(
                            user=voter,
                            batch=batch,
                            section=section
                        )

                        voters.append(voter)

            num_positions = 3
            for i in range(num_positions):
                position = CandidatePosition.objects.create(
                    position_name='Position {}'.format(position_num),
                    election=election
                )

                positions[str(election.name)].append(position)

                position_num += 1

            num_parties = 3
            for j in range(num_parties):
                party = CandidateParty.objects.create(
                    party_name='Party {}'.format(party_num),
                    election=election
                )
                party_num += 1

                if j != 2:  # Let every third party have no candidates.
                    num_positions = 3
                    for k in range(num_positions):
                        position = positions[str(election.name)][k]

                        candidate = Candidate.objects.create(
                            user=voters[candidate_num],
                            party=party,
                            position=position,
                            election=election
                        )

                        Vote.objects.create(
                            user=voters[candidate_num],
                            candidate=candidate,
                            election=election
                        )

                        candidate_num += 1

        # Let's give one candidate an additional vote to really make sure that
        # we all got the correct number of votes.
        Vote.objects.create(
            user=voters[0],
            # NOTE: The voter in voter[1] is a Position 1 candidate of
            #       Party 1, where the voter in voter[0] is a member.
            candidate=Candidate.objects.get(user=voters[1]),
            election=Election.objects.get(name='Election 0')
        )

        _admin = User.objects.create(username='admin', type=UserType.ADMIN)
        _admin.set_password('root')
        _admin.save()
def __call__(self, inputs, training):
    """Add operations to classify a batch of input images.

    Args:
      inputs: A Tensor representing a batch of input images.
      training: A boolean. Set to True to add operations required only when
        training the classifier.

    Returns:
      A logits Tensor with shape [<batch_size>, self.num_classes].
    """

    with self._model_variable_scope():
      if self.data_format == 'channels_first':
        # Convert the inputs from channels_last (NHWC) to channels_first (NCHW).
        # This provides a large performance boost on GPU. See
        # https://www.tensorflow.org/performance/performance_guide#data_formats
        inputs = tf.transpose(a=inputs, perm=[0, 3, 1, 2])

      inputs = conv2d_fixed_padding(
          inputs=inputs,
          filters=self.num_filters,
          kernel_size=self.kernel_size,
          strides=self.conv_stride,
          data_format=self.data_format,
          name='initial_input')
      inputs = tf.identity(inputs, 'initial_conv')

      # We do not include batch normalization or activation functions in V2
      # for the initial conv1 because the first ResNet unit will perform these
      # for both the shortcut and non-shortcut paths as part of the first
      # block's projection. Cf. Appendix of [2].
      if self.resnet_version == 1:
        inputs = batch_norm(inputs, training, self.data_format)
        inputs = tf.nn.relu(inputs)

      if self.first_pool_size:
        inputs = tf.compat.v1.layers.max_pooling2d(
            inputs=inputs,
            pool_size=self.first_pool_size,
            strides=self.first_pool_stride,
            padding='SAME',
            data_format=self.data_format)
        inputs = tf.identity(inputs, 'initial_max_pool')

      for i, num_blocks in enumerate(self.block_sizes):
        # We now have 4 block layers, but the last does not
        # double the number of filters.
        # We also skip the projection shortcut in the first block layer.
        num_filters = self.num_filters * min((2**i), 4)
        shortcut = i != 0
        inputs = block_layer(
            inputs=inputs,
            filters=num_filters,
            bottleneck=self.bottleneck,
            block_fn=self.block_fn,
            blocks=num_blocks,
            strides=self.block_strides[i],
            training=training,
            name='block_layer{}'.format(i + 1),
            data_format=self.data_format,
            shortcut=shortcut)

      # Skip the last BN+relu.
      # Only apply the BN and ReLU for model that does pre_activation in each
      # building/bottleneck block, eg resnet V2.
      # if self.pre_activation:
      #   inputs = batch_norm(inputs, training, self.data_format,
      #     name='pre_act'+'batch_norm')
      #   inputs = tf.nn.relu(inputs,name='pre_act'+'relu')

      # The current top layer has shape
      # `batch_size x pool_size x pool_size x final_size`.
      # ResNet does an Average Pooling layer over pool_size,
      # but that is the same as doing a reduce_mean. We do a reduce_mean
      # here because it performs better than AveragePooling2D.
      # Also perform max-pooling, and concat results.
      axes = [2, 3] if self.data_format == 'channels_first' else [1, 2]
      avg_pooled = tf.reduce_mean(input_tensor=inputs, axis=axes, keepdims=True)
      avg_pooled = tf.squeeze(avg_pooled, axes)
      max_pooled = tf.reduce_max(input_tensor=inputs, axis=axes, keepdims=True)
      max_pooled = tf.squeeze(max_pooled, axes)
      inputs = tf.concat([avg_pooled, max_pooled], axis=1)
      inputs = tf.identity(inputs, 'final_pooling')

      inputs = tf.compat.v1.layers.dense(
          inputs=inputs, units=self.num_classes, reuse=tf.AUTO_REUSE)
      inputs = tf.identity(inputs, 'final_dense')
      return inputs