code: def step2():
      global v, n, u, nextgraph
  
      # Start out by loading the encoded images
      n = np.load("data/encryption.npy")
      n = np.transpose(n, (0, 3, 1, 2))
  
      # Then load the graph with 100 cluster-centers.
      keep = np.array(
          np.load("data/100_clusters.npy", allow_pickle=True)
      )
      graph = np.load("data/graph.npy")
  
      # Now we're going to record the distance to each of the cluster centers
      # from every encoded image, so that we can do the matching.
  
      # To do that, though, first we need to choose the cluster centers.
      # Start out by choosing the best cluster centers.
  
      distances = []
  
      for x in keep:
          this_set = x[:50]
          use_elts = graph[this_set]
          distances.append(np.sum(use_elts, axis=0))
      distances = np.array(distances)
  
      ds = np.argsort(distances, axis=1)
  
      # Now we record the "prototypes" of each cluster center.
      # We just need three, more might help a little bit but not much.
      # (And then do that ten times, so we can average out noise
      # with respect to which cluster centers we picked.)
  
      prototypes = []
      for _ in range(10):
          ps = []
          # choose 3 random samples from each set
          for i in range(3):
              ps.append(n[ds[:, random.randint(0, 20)]])
          prototypes.append(np.concatenate(ps, 1))
      prototypes = np.concatenate(prototypes, 0)
  
      # Finally compute the distances from each node to each cluster center.
      nextgraph = []
      for i in range(5000):
          out = model.predict(
              prototypes, np.tile(n[i : i + 1], (1000, 1, 1, 1))
          )
          out = out.reshape((10, 100, 2))
  
          v = np.sum(out, axis=0)
          v = v[:, 0] - v[:, 1]
          v = np.array(v)
          nextgraph.append(v)
  
      np.save("data/nextgraph.npy", nextgraph)
  
file_path: privacy/research/instahide_attack_2020/step_3_second_graph.py
imports: import objax
  import numpy
  import jax.numpy
  import functools
  import os
  import random
  from objax.zoo import wide_resnet
label_desc: Use image node_id 2 for calling a global function with example usage: step2() without return types