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


Python PatchExtractor.transform方法代码示例

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


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

示例1: test_patch_extractor_all_patches

# 需要导入模块: from sklearn.feature_extraction.image import PatchExtractor [as 别名]
# 或者: from sklearn.feature_extraction.image.PatchExtractor import transform [as 别名]
def test_patch_extractor_all_patches():
    faces = face_collection
    i_h, i_w = faces.shape[1:3]
    p_h, p_w = 8, 8
    expected_n_patches = len(faces) * (i_h - p_h + 1) * (i_w - p_w + 1)
    extr = PatchExtractor(patch_size=(p_h, p_w), random_state=0)
    patches = extr.transform(faces)
    assert_true(patches.shape == (expected_n_patches, p_h, p_w))
开发者ID:0664j35t3r,项目名称:scikit-learn,代码行数:10,代码来源:test_image.py

示例2: test_patch_extractor_color

# 需要导入模块: from sklearn.feature_extraction.image import PatchExtractor [as 别名]
# 或者: from sklearn.feature_extraction.image.PatchExtractor import transform [as 别名]
def test_patch_extractor_color():
    faces = _make_images(orange_face)
    i_h, i_w = faces.shape[1:3]
    p_h, p_w = 8, 8
    expected_n_patches = len(faces) * (i_h - p_h + 1) * (i_w - p_w + 1)
    extr = PatchExtractor(patch_size=(p_h, p_w), random_state=0)
    patches = extr.transform(faces)
    assert_true(patches.shape == (expected_n_patches, p_h, p_w, 3))
开发者ID:0664j35t3r,项目名称:scikit-learn,代码行数:10,代码来源:test_image.py

示例3: test_patch_extractor_max_patches

# 需要导入模块: from sklearn.feature_extraction.image import PatchExtractor [as 别名]
# 或者: from sklearn.feature_extraction.image.PatchExtractor import transform [as 别名]
def test_patch_extractor_max_patches():
    faces = face_collection
    i_h, i_w = faces.shape[1:3]
    p_h, p_w = 8, 8

    max_patches = 100
    expected_n_patches = len(faces) * max_patches
    extr = PatchExtractor(patch_size=(p_h, p_w), max_patches=max_patches,
                          random_state=0)
    patches = extr.transform(faces)
    assert patches.shape == (expected_n_patches, p_h, p_w)

    max_patches = 0.5
    expected_n_patches = len(faces) * int((i_h - p_h + 1) * (i_w - p_w + 1)
                                          * max_patches)
    extr = PatchExtractor(patch_size=(p_h, p_w), max_patches=max_patches,
                          random_state=0)
    patches = extr.transform(faces)
    assert patches.shape == (expected_n_patches, p_h, p_w)
开发者ID:jerry-dumblauskas,项目名称:scikit-learn,代码行数:21,代码来源:test_image.py

示例4: generate_data

# 需要导入模块: from sklearn.feature_extraction.image import PatchExtractor [as 别名]
# 或者: from sklearn.feature_extraction.image.PatchExtractor import transform [as 别名]
def generate_data(img_folder, max_patches=0.001):
    for fpath in get_img_filepaths(img_folder):
        print ('Reading image', fpath)
        patch_extractor = PatchExtractor(patch_size=(32,32),
                                             max_patches=max_patches)

        img_tensor = imread(fpath, mode='RGB')
        # shape : (row, col, channels)

        input_matrix = np.array([img_tensor])
        # shape : (1, row, col, channels)

        input_matrix = input_matrix/255.0 # Casting into 0 to 1 space which DNN models learn faster
        
        patches = patch_extractor.transform(input_matrix)
        # shape : (n_samples, row, col, channels)

        patches = np.rollaxis(patches, axis=3, start=1)
        # shape : (n_samples, channels, row, col)

        small_patches = np.array([resize(patch) for patch in patches])
        # shape : (n_samples, channels, max_x, max_y)

        patches = np.array([p.reshape(p.shape[0] * p.shape[1] * p.shape[2])
                            for p in patches])
        # shape : (n_samples, output_vector_size)

        if False:
            # Print out values to debug
            print ("Shapes of tensors", small_patches.shape, patches.shape)
            for i, (small, big) in enumerate(zip(small_patches, patches)):
                small_img = np.rollaxis(small, axis=0, start=3)
                if not os.path.exists('debug'):
                    os.makedirs('debug')
                imsave('debug/small_patch_{}.jpg'.format(i), small_img)
                imsave('debug/big_patch_{}.jpg'.format(i), vec2img(big))

        yield small_patches, patches
开发者ID:wnzhang,项目名称:sr,代码行数:40,代码来源:train.py

示例5: test_patch_extractor_max_patches_default

# 需要导入模块: from sklearn.feature_extraction.image import PatchExtractor [as 别名]
# 或者: from sklearn.feature_extraction.image.PatchExtractor import transform [as 别名]
def test_patch_extractor_max_patches_default():
    faces = face_collection
    extr = PatchExtractor(max_patches=100, random_state=0)
    patches = extr.transform(faces)
    assert_equal(patches.shape, (len(faces) * 100, 19, 25))
开发者ID:0664j35t3r,项目名称:scikit-learn,代码行数:7,代码来源:test_image.py

示例6: extract_patches

# 需要导入模块: from sklearn.feature_extraction.image import PatchExtractor [as 别名]
# 或者: from sklearn.feature_extraction.image.PatchExtractor import transform [as 别名]
 def extract_patches(self, patch_size, max_patches=None, random_state=None):
   patch_extractor = PatchExtractor(patch_size=patch_size, max_patches=np.int(
       max_patches / self.num_images()), random_state=random_state)
   return patch_extractor.transform(self._images).astype(np.uint8)
开发者ID:queqichao,项目名称:FredholmLearning,代码行数:6,代码来源:dataset.py

示例7: test_patch_extractor_max_patches_default

# 需要导入模块: from sklearn.feature_extraction.image import PatchExtractor [as 别名]
# 或者: from sklearn.feature_extraction.image.PatchExtractor import transform [as 别名]
def test_patch_extractor_max_patches_default():
    lenas = lena_collection
    extr = PatchExtractor(max_patches=100, random_state=0)
    patches = extr.transform(lenas)
    assert_equal(patches.shape, (len(lenas) * 100, 12, 12))
开发者ID:AtonLerin,项目名称:maya_python_packages,代码行数:7,代码来源:test_image.py


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