def __init__(self, face_rec_graph, model_path='models/model-20170512-110547.ckpt-250000'): ''' :param face_rec_sess: FaceRecSession object :param model_path: ''' print("Loading Resnet Model") with face_rec_graph.graph.as_default(): self.sess = tf.Session() self.x = tf.placeholder('float', [None, 160, 160, 3], name='batch_join') #default input for the NN is 160x160x3 self.embeddings = tf.nn.l2_normalize(resnet.inference( self.x, 0.6, phase_train=False)[0], 1, 1e-10, name='embeddings') #some magic numbers that u dont have to care about saver = tf.train.Saver() #saver load pretrain model saver.restore(self.sess, model_path) print("Resnet Model loaded")
def __init__(self, face_rec_graph, model_path = 'models/model-20170512-110547.ckpt-250000'): print("Loading model...") with face_rec_graph.as_default(): self.sess = tf.Session() self.x = tf.placeholder('float', [None,160,160,3]); self.embeddings = tf.nn.l2_normalize( resnet.inference(self.x, 0.6, phase_train=False)[0], 1, 1e-10); saver = tf.train.Saver() #load pretrain model saver.restore(self.sess, model_path) print("Model loaded")
def __init__(self, model_path = 'models/model-20170512-110547.ckpt-250000'): ''' :param face_rec_sess: FaceRecSession object :param model_path: ''' print("Loading face recognition models(it will take about 1 minute)...") with tf.Graph().as_default(), tf.device('/cpu:0'): self.sess = tf.Session() self.x = tf.placeholder('float', [None,160,160,3]); #default input for the NN is 160x160x3 self.embeddings = tf.nn.l2_normalize( resnet.inference(self.x, 0.6, phase_train=False)[0], 1, 1e-10); saver = tf.train.Saver() #saver load pretrain model saver.restore(self.sess, model_path) print("Face recognition models loaded")
def __init__(self, face_rec_graph, model_path = 'models/model-20170512-110547.ckpt-250000'): ''' :param face_rec_sess: FaceRecSession object :param model_path: ''' print("Loading model...") with face_rec_graph.graph.as_default(): self.sess = tf.Session() self.x = tf.placeholder('float', [None,160,160,3]); #default input for the NN is 160x160x3 self.embeddings = tf.nn.l2_normalize( resnet.inference(self.x, 0.6, phase_train=False)[0], 1, 1e-10); #some magic numbers that u dont have to care about saver = tf.train.Saver() #saver load pretrain model saver.restore(self.sess, model_path) print("Model loaded")
def __init__(self, model_path='models/model-20170512-110547.ckpt-250000'): ''' :param face_rec_sess: FaceRecSession object :param model_path: ''' print( "Loading face recognition models(it will take about 1 minute)...") with tf.Graph().as_default(), tf.device('/cpu:0'): self.sess = tf.Session() self.x = tf.placeholder('float', [None, 160, 160, 3]) #default input for the NN is 160x160x3 self.embeddings = tf.nn.l2_normalize( resnet.inference(self.x, 0.6, phase_train=False)[0], 1, 1e-10) saver = tf.train.Saver() #saver load pretrain model saver.restore(self.sess, model_path) print("Face recognition models loaded")
def __init__(self, face_rec_graph, model_path='models/model-20170512-110547.ckpt-250000'): print("\n [INFO] Loading the pretrained model...") with face_rec_graph.graph.as_default(): self.sess = tf.Session() # Default input shape -> [160, 160, 3] self.x = tf.placeholder('float', [None, 160, 160, 3]) # Reload the base model variables self.embeddings = tf.nn.l2_normalize( resnet.inference(self.x, KEEP_PROB, phase_train=DO_NOT_TRAIN_MODEL)[0], 1, 1e-10) # Restore the pretrained model saver = tf.train.Saver() saver.restore(self.sess, model_path) print("\n [INFO] Sucessfully loaded model.")
def __init__(self, face_rec_graph, save_part, model_path='models/model-20170512-110547.ckpt-250000'): ''' :param face_rec_sess: FaceRecSession object :param model_path: ''' if save_part == True: print("Loading model...") with face_rec_graph.graph.as_default(): self.sess = tf.Session() #face_rec_graph.sess # self.sess.run(tf.global_variables_initializer()) self.x = tf.placeholder('float', [None, 160, 160, 3], name='input') #default input for the NN is 160x160x3 self.embeddings = tf.nn.l2_normalize( resnet.inference(self.x, 0.6, phase_train=False)[0], 1, 1e-10) #some magic numbers that u dont have to care about print("self.embeddings") print(self.embeddings) saver = tf.train.Saver() #saver load pretrain model saver.restore(self.sess, model_path) print("Model loaded") writer = tf.summary.FileWriter("/tmp/model4/FaceFeature/", self.sess.graph) saver = tf.train.Saver() #saver load pretrain model save_path = tf.train.Saver().save( self.sess, "/tmp/model4/FaceFeature/model.ckpt") print("Model saved in path: %s" % save_path) self.features = lambda img: self.sess.run( ('l2_normalize:0'), feed_dict={"input:0": img}) else: if model_pb == True: print("Load FaceFeature from saved pb file ") model_filename = '/tmp/model4/FaceFeature/graph/graph_FaceFeature.pb' g_in = load_graph(model_filename) self.sess = tf.Session(graph=g_in) # self.sess.run(tf.global_variables_initializer()) print("///////////////////llllll") for v in tf.trainable_variables(): # if v.name == scope_variable: print(v) print("/******************/") print(self.sess.run(v)) for v in self.sess.graph.get_operations(): print(v) print("/******************/") # print(self.sess.run(v)) else: print("Load FaceFeature from saved model ") self.sess = tf.Session() self.sess.run(tf.global_variables_initializer()) model_path = "/tmp/model4/FaceFeature/model.ckpt" model_path_p = "/tmp/model4/FaceFeature/" new_saver = tf.train.import_meta_graph(model_path + '.meta') new_saver.restore(self.sess, tf.train.latest_checkpoint(model_path_p)) self.features = lambda img: self.sess.run( ('prefix/l2_normalize:0'), feed_dict={"prefix/input:0": img})