def _create_ranks(ninjas=None): ranking = Rankings() if ninjas is None: return ranking for ninja in ninjas: ranking.add(ninja) return ranking
def main(args): # TODO: Move constants to startup script ranker = Rankings(5, "../data/celeb_vectors.pk") with tf.Graph().as_default(): with tf.Session() as sess: # Load the model print('Model directory: %s' % args.model_dir) meta_file, ckpt_file = facenet.get_model_filenames( os.path.expanduser(args.model_dir)) print('Metagraph file: %s' % meta_file) print('Checkpoint file: %s' % ckpt_file) facenet.load_model(args.model_dir, meta_file, ckpt_file) print('Watching: %s' % args.watch_dir) while True: # TODO: Only accept VALID (fully downloaded) image files image_filenames = os.listdir(args.watch_dir) if not image_filenames: time.sleep(0.01) else: # TODO: Implement max_batch_size image_filepaths = [ os.path.join(args.watch_dir, image_filename) for image_filename in image_filenames ] images = load_and_align_data(image_filepaths, args.image_size, args.margin, args.gpu_memory_fraction) # Get input and output tensors images_placeholder = tf.get_default_graph( ).get_tensor_by_name("input:0") embeddings = tf.get_default_graph().get_tensor_by_name( "embeddings:0") # Run forward pass to calculate embeddings feed_dict = {images_placeholder: images} emb = sess.run(embeddings, feed_dict=feed_dict) for filename, vector in zip(image_filenames, emb.tolist()): image_filepath = os.path.join(args.watch_dir, filename) output_filepath = os.path.join( args.output_dir, os.path.splitext(filename)[0] + ".json") rank = ranker.calculate_ranking(vector) rank_names = [c.name for c in rank] with open(output_filepath, 'w') as fp: json.dump(rank_names, fp) os.remove(image_filepath)
def test_all_preferred(self): rank = Rankings({ 1: ['A', 'B'], 2: ['A', 'B'], 'A': [2, 1], 'B': [2, 1] }) self.assertEqual(set(), set(rank.all_preferred(1, 'A'))) self.assertEqual(set(), set(rank.all_preferred(2, 'A'))) self.assertEqual({'A'}, set(rank.all_preferred(1, 'B'))) self.assertEqual({2}, set(rank.all_preferred('B', 1))) self.assertEqual({2}, set(rank.all_preferred('A', 1)))
def test_stability_of_output(self): rank = Rankings({ 1: ['A', 'B'], 2: ['B', 'A'], 'A': [1, 2], 'B': [2, 1] }) init = Pairing((1, 'B'), (2, 'A')) final_pairing, _ = stochastic_marriage(rank, init) self.assertEqual(Pairing((1, 'A'), (2, 'B')), final_pairing)
def test_rogues(self): rank = Rankings({ 1: ['A', 'B'], 2: ['B', 'A'], 'A': [1, 2], 'B': [2, 1] }) init = Pairing((1, 'B'), (2, 'A')) r = Rogues(init, rank) self.assertEqual(2, len(r)) self.assertEqual({(2, 'B'), (1, 'A')}, {r.select(), r.select()})
def main(): try: f = open("auth.txt") auth_id = f.readline().rstrip() auth_secret = f.readline().rstrip() except IOError: print( "auth.txt doesn't exist. Please place client ID and secret into a file named 'auth.txt' with the ID on the first line and the secret on the second." ) finally: f.close() filename = "results" parser = argparse.ArgumentParser( description="Basic AQ parse performance for GDKP splits" ) parser.add_argument( "-r", "--report", required=True, type=str, help="Warcraftlogs report ID to be analyzed", ) parser.add_argument( "-f", "--filename", required=False, type=str, help="Filename in which the results should be stored", ) parser.add_argument( "-s", "--split", required=True, type=int, help="100% split value" ) parser.add_argument( "-b", "--brackets", action="append", help="Three integers specifying the dps parse " "brackets", ) parser.add_argument("-he", "--healers", type=int, help="Healer bracket cutoff") parser.add_argument("-v", "--verbose", required=False, action="store_true") parser.add_argument("-vi", "--visc", required=False, action="store_true") args = parser.parse_args() client = Client(auth_id, auth_secret, args.report) if args.filename: filename = args.filename rankings = Rankings(client, args.verbose, args.brackets, args.healers, args.visc) write_rankings(rankings, args.split, filename)
def test_rankings(self): rank = Rankings({ 1: ['A', 'B'], 2: ['A', 'B'], 'A': [2, 1], 'B': [2, 1] }) self.assertTrue(rank.prefers(1, 'A', 'B')) self.assertTrue(rank.prefers(2, 'A', 'B')) self.assertTrue(rank.prefers('A', 2, 1)) self.assertFalse(rank.prefers('A', 1, 2)) self.assertFalse(rank.prefers('A', 1, 1)) self.assertFalse(rank.prefers('A', 1, 3))
def ninja_ranks(): ranking = Rankings() for ninja in FIRST_NINJAS: ranking.add(ninja) return ranking
from __future__ import division import json import numpy as np import pandas as pd from rankings import Rankings val = pd.read_pickle("../data/val.pk") correct = np.zeros((1680), dtype=np.int) r = Rankings(5, "../data/train.pk") for i, item in enumerate(val.iteritems()): ranking = r.calculate_ranking(item[1]) for j, celeb in enumerate(ranking): if ranking[j].name == item[0]: correct[i] = j + 1 break print(np.bincount(correct))