code: def compute_fitness(predict_fn, loss_fn, adv_pop, y, targeted=False):
      """
      Compute fitness for the population
      """
      # population shape: [B, N, F]
      n_batch, n_samples, n_dim = adv_pop.shape
      # reshape to [B * N, F]
      adv_pop = adv_pop.reshape(-1, n_dim)
      # output shape: [B * N, C]
      probs = predict_fn(adv_pop)
  
      # reshape to [B, N, C]
      probs = probs.reshape(n_batch, n_samples, -1)
      # outputs shape: [B, N]
      fitness = loss_fn(probs, y, targeted=targeted)
  
      return fitness
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  from typing import Optional
  from math import inf
  import torch
  import torch.nn.functional
  from advertorch.attacks.base import Attack
  from advertorch.attacks.base import LabelMixin
  from .utils import _check_param, _flatten, _make_projector
label_desc: Use image node_id 2 for calling a global function with example usage: compute_fitness(predict_fn, loss_fn, adv_pop, y, targeted) and returns: fitness