当前位置: 首页>>代码示例>>Python>>正文


Python facenet.get_dataset方法代码示例

本文整理汇总了Python中facenet.get_dataset方法的典型用法代码示例。如果您正苦于以下问题:Python facenet.get_dataset方法的具体用法?Python facenet.get_dataset怎么用?Python facenet.get_dataset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在facenet的用法示例。


在下文中一共展示了facenet.get_dataset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import facenet [as 别名]
# 或者: from facenet import get_dataset [as 别名]
def main(args):

    dataset = facenet.get_dataset(args.dir)
    paths, _ = facenet.get_image_paths_and_labels(dataset)
    t = np.zeros((len(paths)))
    x = time.time()
    for i, path in enumerate(paths):
        start_time = time.time()
        with open(path, mode='rb') as f:
            _ = f.read()
        duration = time.time() - start_time
        t[i] = duration
        if i % 1000 == 0 or i==len(paths)-1:
            print('File %d/%d  Total time: %.2f  Avg: %.3f  Std: %.3f' % (i, len(paths), time.time()-x, np.mean(t[0:i])*1000, np.std(t[0:i])*1000)) 
开发者ID:1024210879,项目名称:facenet-demo,代码行数:16,代码来源:dataset_read_speed.py

示例2: main

# 需要导入模块: import facenet [as 别名]
# 或者: from facenet import get_dataset [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 
开发者ID:1024210879,项目名称:facenet-demo,代码行数:38,代码来源:test_align.py

示例3: main

# 需要导入模块: import facenet [as 别名]
# 或者: from facenet import get_dataset [as 别名]
def main(args):
    funnel_cmd = 'funnelReal'
    funnel_model = 'people.train'

    output_dir = os.path.expanduser(args.output_dir)
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
    # Store some git revision info in a text file in the output directory
    src_path,_ = os.path.split(os.path.realpath(__file__))
    facenet.store_revision_info(src_path, output_dir, ' '.join(sys.argv))
    dataset = facenet.get_dataset(args.input_dir)
    np.random.shuffle(dataset)
    # Scale the image such that the face fills the frame when cropped to crop_size
    #scale = float(args.face_size) / args.image_size
    with TemporaryDirectory() as tmp_dir:
        for cls in dataset:
            output_class_dir = os.path.join(output_dir, cls.name)
            tmp_output_class_dir = os.path.join(tmp_dir, cls.name)
            if not os.path.exists(output_class_dir) and not os.path.exists(tmp_output_class_dir):
                print('Aligning class %s:' % cls.name)
                tmp_filenames = []
                if not os.path.exists(tmp_output_class_dir):
                    os.makedirs(tmp_output_class_dir)
                input_list_filename = os.path.join(tmp_dir, 'input_list.txt')
                output_list_filename = os.path.join(tmp_dir, 'output_list.txt')
                input_file = open(input_list_filename, 'w')
                output_file = open(output_list_filename,'w')
                for image_path in cls.image_paths:
                    filename = os.path.split(image_path)[1]
                    input_file.write(image_path+'\n')
                    output_filename = os.path.join(tmp_output_class_dir, filename)
                    output_file.write(output_filename+'\n')
                    tmp_filenames.append(output_filename)
                input_file.close()
                output_file.close()
                cmd = args.funnel_dir+funnel_cmd + ' ' + input_list_filename + ' ' + args.funnel_dir+funnel_model + ' ' + output_list_filename
                subprocess.call(cmd, shell=True)
                
                # Resize and crop images
                if not os.path.exists(output_class_dir):
                    os.makedirs(output_class_dir)
                scale = 1.0
                for tmp_filename in tmp_filenames:
                    img = misc.imread(tmp_filename)
                    img_scale = misc.imresize(img, scale)
                    sz1 = img.shape[1]/2
                    sz2 = args.image_size/2
                    img_crop = img_scale[int(sz1-sz2):int(sz1+sz2),int(sz1-sz2):int(sz1+sz2),:]
                    filename = os.path.splitext(os.path.split(tmp_filename)[1])[0]
                    output_filename = os.path.join(output_class_dir, filename+'.png')
                    print('Saving image %s' % output_filename)
                    misc.imsave(output_filename, img_crop)
                    
                # Remove tmp directory with images
                shutil.rmtree(tmp_output_class_dir) 
开发者ID:1024210879,项目名称:facenet-demo,代码行数:57,代码来源:funnel_dataset.py


注:本文中的facenet.get_dataset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。