def setup(self, index): self.index = index if len(weight_sets) <= self.index: return False s = weight_sets[self.index]["size"] self.size = (s[0], s[1]) self.num_layers = weight_sets[self.index]["num_layers"] self.session_name = "weight_sets/" + weight_sets[self.index]["session_name"] self.formatter = dataformat.DataFormat(self.size[0]) self.close_down() print(self.session_name) num_intra_class = 10 num_inter_class = 20 self.comparator = momentnet.Comparator((2, self.size[0]), self.size[1], num_intra_class=num_intra_class, num_inter_class=num_inter_class, layers=self.num_layers) config = tf.ConfigProto() config.gpu_options.allow_growth = True self.running = True self.sess = tf.Session(config=config) self.sess.run(tf.global_variables_initializer()) self.comparator.load_session(self.sess, self.session_name) return True
print("testset shapes: ", data.shape, labels.shape) if args.template is not None: template_path = os.path.join("templates", args.template) else: template_path = os.path.join("templates", "default") templates, template_labels = dataformat.read_template_directory( formatter, template_path, with_flip=False) print("template shapes: ", templates.shape, template_labels.shape) num_intra_class = 10 num_inter_class = 20 comparator = momentnet.Comparator((2, input_size[0]), input_size[1], num_intra_class=num_intra_class, num_inter_class=num_inter_class, layers=num_layers) sess = tf.Session() sess.run(tf.global_variables_initializer()) comparator.load_session(sess, session_name) classes, raw = comparator.process( sess, np.reshape(data, [-1, input_size[0] * 2]), np.reshape(templates, [-1, input_size[0] * 2])) print(classes) sess.close() print( "Percent correct = ", np.count_nonzero(labels[:, 0] == template_labels[classes, 0]) * 100.0 /
template_dir = "neo_large" formatter = dataformat.DataFormat(256) templates, template_labels, raws = dataformat.read_template_directory( formatter, os.path.join("templates", template_dir), with_flip=True, return_raw=True) print(templates.shape) X = np.reshape(templates, [templates.shape[0], -1]) perform_embedding = True if perform_embedding: comparator = momentnet.Comparator((2, 256), 32, num_intra_class=10, num_inter_class=20, layers=5, lambdas=(5, 0.5, 5)) session_name = os.path.join(os.path.dirname(__file__), '..', "weight_sets", "neo_large_5L_flip", "test") sess = tf.Session() sess.run(tf.global_variables_initializer()) comparator.load_session(sess, session_name) X = comparator.embed(sess, X) sess.close() #---------------------------------------------------------------------- # Scale and visualize the embedding vectors