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
"weight_sets", weight_set_name) if not os.path.exists(pwd): print("cannot find a trained weight set.") exit() set_path = os.path.join(pwd, "set.json") with open(set_path, "r") as file: set_data = json.load(file) s = set_data["size"] input_size = (s[0], s[1]) num_layers = set_data["num_layers"] session_name = "weight_sets/" + set_data["session_name"] print(session_name, pwd) formatter = dataformat.DataFormat(input_size[0]) data, labels = dataformat.read_data_directory(formatter, from_date, to_date, set_list) # data = random_flip(data) 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)
import numpy as np import cv2 import matplotlib.pyplot as plt from matplotlib import offsetbox from sklearn import (manifold, datasets, decomposition, ensemble, discriminant_analysis, random_projection) import os import sys sys.path.append(os.path.join(os.path.dirname(__file__), '..')) import dataformat import momentnet import tensorflow as tf 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,