embedding可视化/yale人脸数据集
2017-07-26 11:17
411 查看
环境tensorflow1.1,python3
我们可以把学习向量映射到2维中以便我们观察,其中用到的技术可以参考 t-SNE 降纬技术和PCA。当我们用可视化的方式来观察这些向量,这实际上是非常有用的。本实验是人脸数据集中,图像经过embedding后在空间可视化
#coding:utf-8 from tensorflow.contrib.tensorboard.plugins import projector import matplotlib.pyplot as plt import tensorflow as tf import numpy as np import os import scipy.io as sio #加载数据集 #加载数据 def read_data(filename): with open(filename,'rb') as f: #记载matlab文件 dict = sio.loadmat(f) return dict['fea'],dict['gnd'] train_data,train_labels = read_data('Yale_64x64.mat') log_dir = 'yalesample' name_to_visualise_variable = 'yaleembedding' batch_size = 20 #保存数据 path_for_face_png = os.path.join(log_dir,'newface.png') path_for_face_data = os.path.join(log_dir,'newface.tsv') #建立embedding embedding_var = tf.Variable(train_data,name=name_to_visualise_variable) #将信息写入log_dir目录下 summary_writer = tf.summary.FileWriter(log_dir) config = projector.ProjectorConfig() embedding = config.embeddings.add() embedding.tensor_name = embedding_var.name embedding.metadata_path = path_for_face_data embedding.sprite.image_path = path_for_face_png embedding.sprite.single_image_dim.extend([64,64]) #将embedding可视化 projector.visualize_embeddings(summary_writer,config) sess = tf.InteractiveSession() sess.run(tf.global_variables_initializer()) saver = tf.train.Saver() saver.save(sess,os.path.join(log_dir,'model.ckpt'),1) #将图片拼成一张大图 def create_sprite_image(images): if isinstance(images, list): images = np.array(images) img_h = images.shape[1] img_w = images.shape[2] n_plots = int(np.ceil(np.sqrt(images.shape[0]))) spriteimage = np.ones((img_h * n_plots ,img_w * n_plots )) for i in range(n_plots): for j in range(n_plots): this_filter = i * n_plots + j if this_filter < images.shape[0]: this_img = images[this_filter] spriteimage[i * img_h:(i + 1) * img_h, j * img_w:(j + 1) * img_w] = this_img return spriteimage #将矩阵转为图片 def vector_to_matrix_face(face_digits): return np.reshape(face_digits,(-1,64,64)) #将图片转为黑白 def invert_grayscale(face_digits): return 1-face_digits to_visualise = train_data to_visualise = vector_to_matrix_face(to_visualise) to_visualise = invert_grayscale(to_visualise) sprite_image = create_sprite_image(to_visualise) plt.imsave(path_for_face_png,sprite_image,cmap='gray') plt.imshow(sprite_image,cmap='gray') with open(path_for_face_data,'w') as f: f.write('Index\tLabel\n') for index,label in enumerate(train_labels): f.write('%d\t%d\n' %(index,label))
结果:
PCA:t-SNE:
相关文章推荐
- 人脸年龄和性别训练的数据集和开源代码
- SSD人脸检测安装:SSD训练自己的数据集
- ORL Face Database 人脸识别数据集
- Four face databases in matlab format 4个matlab 格式的 人脸识别 数据集
- 人脸和手势识别数据集 FGnet - IST-2000-26434 Face and Gesture Recognition Working group
- 人脸数据集
- 人脸数据集整理
- 在sklearn上读取人脸数据集保存图片到本地
- 在windows平台上测试自己的人脸检测算法在FDDB数据集
- 深度学习、机器学习图像/人脸/字幕/自动驾驶数据集(Dataset)汇总
- The BioID Face Database 人脸数据集
- InfoGAN修改训练人脸数据集celebA的过程记录
- gabor变换人脸识别的python实现,att_faces数据集平均识别率99%
- 数据挖掘—LDA,PCA特征提取降维与SVM多分类在人脸识别中的应用-数据集ORL
- TCDCN人脸数据集
- 人脸检测数据集评价代码FDDB evaluation运行方法
- [人脸识别]使用VGG Face Model微调(Fine tune)自己的数据集
- python爬取人脸识别图片数据集/python爬去图片/python爬虫
- 人脸识别数据集fetch_olivetti_faces()导入失败
- 人脸数据集(用于深度学习)