本文整理汇总了Python中facenet.load_data方法的典型用法代码示例。如果您正苦于以下问题:Python facenet.load_data方法的具体用法?Python facenet.load_data怎么用?Python facenet.load_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类facenet
的用法示例。
在下文中一共展示了facenet.load_data方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: evaluate_accuracy
# 需要导入模块: import facenet [as 别名]
# 或者: from facenet import load_data [as 别名]
def evaluate_accuracy(sess, images_placeholder, phase_train_placeholder, image_size, embeddings,
paths, actual_issame, augment_images, aug_value, batch_size, orig_image_size, seed):
nrof_images = len(paths)
nrof_batches = int(math.ceil(1.0*nrof_images / batch_size))
emb_list = []
for i in range(nrof_batches):
start_index = i*batch_size
end_index = min((i+1)*batch_size, nrof_images)
paths_batch = paths[start_index:end_index]
images = facenet.load_data(paths_batch, False, False, orig_image_size)
images_aug = augment_images(images, aug_value, image_size)
feed_dict = { images_placeholder: images_aug, phase_train_placeholder: False }
emb_list += sess.run([embeddings], feed_dict=feed_dict)
emb_array = np.vstack(emb_list) # Stack the embeddings to a nrof_examples_per_epoch x 128 matrix
thresholds = np.arange(0, 4, 0.01)
embeddings1 = emb_array[0::2]
embeddings2 = emb_array[1::2]
_, _, accuracy = facenet.calculate_roc(thresholds, embeddings1, embeddings2, np.asarray(actual_issame), seed)
return accuracy
示例2: load_testset
# 需要导入模块: import facenet [as 别名]
# 或者: from facenet import load_data [as 别名]
def load_testset(size):
# Load images paths and labels
pairs = lfw.read_pairs(pairs_path)
paths, labels = lfw.get_paths(testset_path, pairs, file_extension)
# Random choice
permutation = np.random.choice(len(labels), size, replace=False)
paths_batch_1 = []
paths_batch_2 = []
for index in permutation:
paths_batch_1.append(paths[index * 2])
paths_batch_2.append(paths[index * 2 + 1])
labels = np.asarray(labels)[permutation]
paths_batch_1 = np.asarray(paths_batch_1)
paths_batch_2 = np.asarray(paths_batch_2)
# Load images
faces1 = facenet.load_data(paths_batch_1, False, False, image_size)
faces2 = facenet.load_data(paths_batch_2, False, False, image_size)
# Change pixel values to 0 to 1 values
min_pixel = min(np.min(faces1), np.min(faces2))
max_pixel = max(np.max(faces1), np.max(faces2))
faces1 = (faces1 - min_pixel) / (max_pixel - min_pixel)
faces2 = (faces2 - min_pixel) / (max_pixel - min_pixel)
# Convert labels to one-hot vectors
onehot_labels = []
for index in range(len(labels)):
if labels[index]:
onehot_labels.append([1, 0])
else:
onehot_labels.append([0, 1])
return faces1, faces2, np.array(onehot_labels)
示例3: main
# 需要导入模块: import facenet [as 别名]
# 或者: from facenet import load_data [as 别名]
def main():
image_size = 96
old_dataset = '/home/david/datasets/facescrub/fs_aligned_new_oean/'
new_dataset = '/home/david/datasets/facescrub/facescrub_110_96/'
eq = 0
num = 0
l = []
dataset = facenet.get_dataset(old_dataset)
for cls in dataset:
new_class_dir = os.path.join(new_dataset, cls.name)
for image_path in cls.image_paths:
try:
filename = os.path.splitext(os.path.split(image_path)[1])[0]
new_filename = os.path.join(new_class_dir, filename+'.png')
#print(image_path)
if os.path.exists(new_filename):
a = facenet.load_data([image_path, new_filename], False, False, image_size, do_prewhiten=False)
if np.array_equal(a[0], a[1]):
eq+=1
num+=1
err = np.sum(np.square(np.subtract(a[0], a[1])))
#print(err)
l.append(err)
if err>2000:
fig = plt.figure(1)
p1 = fig.add_subplot(121)
p1.imshow(a[0])
p2 = fig.add_subplot(122)
p2.imshow(a[1])
print('%6.1f: %s\n' % (err, new_filename))
pass
else:
pass
#print('File not found: %s' % new_filename)
except:
pass
示例4: compute_facial_encodings
# 需要导入模块: import facenet [as 别名]
# 或者: from facenet import load_data [as 别名]
def compute_facial_encodings(sess,images_placeholder,embeddings,phase_train_placeholder,image_size,
embedding_size,nrof_images,nrof_batches,emb_array,batch_size,paths):
""" Compute Facial Encodings
Given a set of images, compute the facial encodings of each face detected in the images and
return them. If no faces, or more than one face found, return nothing for that image.
Inputs:
image_paths: a list of image paths
Outputs:
facial_encodings: (image_path, facial_encoding) dictionary of facial encodings
"""
for i in range(nrof_batches):
start_index = i*batch_size
end_index = min((i+1)*batch_size, nrof_images)
paths_batch = paths[start_index:end_index]
images = facenet.load_data(paths_batch, False, False, image_size)
feed_dict = { images_placeholder:images, phase_train_placeholder:False }
emb_array[start_index:end_index,:] = sess.run(embeddings, feed_dict=feed_dict)
facial_encodings = {}
for x in range(nrof_images):
facial_encodings[paths[x]] = emb_array[x,:]
return facial_encodings
示例5: load_testset
# 需要导入模块: import facenet [as 别名]
# 或者: from facenet import load_data [as 别名]
def load_testset(size):
# Load images paths and labels
pairs = lfw.read_pairs(pairs_path)
paths, labels = lfw.get_paths(testset_path, pairs)
# Random choice
permutation = np.random.choice(len(labels), size, replace=False)
paths_batch_1 = []
paths_batch_2 = []
for index in permutation:
paths_batch_1.append(paths[index * 2])
paths_batch_2.append(paths[index * 2 + 1])
labels = np.asarray(labels)[permutation]
paths_batch_1 = np.asarray(paths_batch_1)
paths_batch_2 = np.asarray(paths_batch_2)
# Load images
faces1 = facenet.load_data(paths_batch_1, False, False, image_size)
faces2 = facenet.load_data(paths_batch_2, False, False, image_size)
# Change pixel values to 0 to 1 values
min_pixel = min(np.min(faces1), np.min(faces2))
max_pixel = max(np.max(faces1), np.max(faces2))
faces1 = (faces1 - min_pixel) / (max_pixel - min_pixel)
faces2 = (faces2 - min_pixel) / (max_pixel - min_pixel)
# Convert labels to one-hot vectors
onehot_labels = []
for index in range(len(labels)):
if labels[index]:
onehot_labels.append([1, 0])
else:
onehot_labels.append([0, 1])
return faces1, faces2, np.array(onehot_labels)
示例6: main
# 需要导入模块: import facenet [as 别名]
# 或者: from facenet import load_data [as 别名]
def main(args):
with tf.Graph().as_default():
with tf.Session() as sess:
# create output directory if it doesn't exist
output_dir = os.path.expanduser(args.output_dir)
if not os.path.isdir(output_dir):
os.makedirs(output_dir)
# load the model
print("Loading trained model...\n")
meta_file, ckpt_file = facenet.get_model_filenames(os.path.expanduser(args.trained_model_dir))
facenet.load_model(args.trained_model_dir, meta_file, ckpt_file)
# grab all image paths and labels
print("Finding image paths and targets...\n")
data = load_files(args.data_dir, load_content=False, shuffle=False)
labels_array = data['target']
paths = data['filenames']
# 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")
phase_train_placeholder = tf.get_default_graph().get_tensor_by_name("phase_train:0")
image_size = images_placeholder.get_shape()[1]
embedding_size = embeddings.get_shape()[1]
# Run forward pass to calculate embeddings
print('Generating embeddings from images...\n')
start_time = time.time()
batch_size = args.batch_size
nrof_images = len(paths)
nrof_batches = int(np.ceil(1.0*nrof_images / batch_size))
emb_array = np.zeros((nrof_images, embedding_size))
for i in xrange(nrof_batches):
start_index = i*batch_size
end_index = min((i+1)*batch_size, nrof_images)
paths_batch = paths[start_index:end_index]
images = facenet.load_data(paths_batch, do_random_crop=False, do_random_flip=False, image_size=image_size, do_prewhiten=True)
feed_dict = { images_placeholder:images, phase_train_placeholder:False}
emb_array[start_index:end_index,:] = sess.run(embeddings, feed_dict=feed_dict)
time_avg_forward_pass = (time.time() - start_time) / float(nrof_images)
print("Forward pass took avg of %.3f[seconds/image] for %d images\n" % (time_avg_forward_pass, nrof_images))
print("Finally saving embeddings and gallery to: %s" % (output_dir))
# save the gallery and embeddings (signatures) as numpy arrays to disk
np.save(os.path.join(output_dir, "gallery.npy"), labels_array)
np.save(os.path.join(output_dir, "signatures.npy"), emb_array)