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


Python Parallel.reshape方法代码示例

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


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

示例1: fit

# 需要导入模块: from joblib import Parallel [as 别名]
# 或者: from joblib.Parallel import reshape [as 别名]
    def fit(self, modality, ground_truth=None, cat=None):
        """Compute the images images.

        Parameters
        ----------
        modality : object of type TemporalModality
            The modality object of interest.

        ground-truth : object of type GTModality or None
            The ground-truth of GTModality. If None, the whole data will be
            considered.

        cat : str or None
            String corresponding at the ground-truth of interest. Cannot be
            None if ground-truth is not None.

        Return
        ------
        self : object
             Return self.

        """
        super(HaralickExtraction, self).fit(modality=modality,
                                              ground_truth=ground_truth,
                                              cat=cat)

        # Get the data and rescale as integers within the given levels
        vol_haralick = ((modality.data_ - np.ndarray.min(modality.data_)) *
                        ((self.levels -1) /
                         (np.ndarray.max(modality.data_) -
                          np.ndarray.min(modality.data_)))).astype(int)

        # Extract the set of patches from the modality data
        patches = extract_patches(vol_haralick, patch_shape=self.patch_size)

        # Allocate the haralick maps, one for each feature that
        # will be computed
        nb_directions = 13
        nb_features = 13
        self.data_ = np.zeros((modality.data_.shape[0],
                               modality.data_.shape[1],
                               modality.data_.shape[2],
                               nb_directions,
                               nb_features))

        # WE NEED TO PARALLELIZE THIS CODE

        # # Extract Haralick feature for each patch
        # # Define the shift to apply
        if isinstance(self.patch_size, tuple):
            y_shift = int(np.ceil((self.patch_size[0] - 1) / 2.))
            x_shift = int(np.ceil((self.patch_size[1] - 1) / 2.))
            z_shift = int(np.ceil((self.patch_size[2] - 1) / 2.))
        elif isinstance(self.patch_size, int):
            y_shift = int(np.ceil((self.patch_size - 1) / 2.))
            x_shift = int(np.ceil((self.patch_size - 1) / 2.))
            z_shift = int(np.ceil((self.patch_size - 1) / 2.))

        # for y in range(patches.shape[0]):
        #     for x in range(patches.shape[1]):
        #         for z in range(patches.shape[2]):
        #             print 'Compute for the pixel at position {}{}{}'.format(
        #                 y, x, z)
        #             # Compute the haralick features
        #             self.data_[y + y_shift,
        #                        x + x_shift,
        #                        z + z_shift, :] = haralick(
        #                            patches[y, x, z, :],
        #                            distance=self.distance)

        # Create the list of indices to process
        yy, xx, zz = np.meshgrid(range(patches.shape[0]),
                                 range(patches.shape[1]),
                                 range(patches.shape[2]))
        # Linearize for fast processing
        yy = yy.reshape(-1)
        xx = xx.reshape(-1)
        zz = zz.reshape(-1)

        # Go for the parallel loop
        haralick_features = Parallel(n_jobs=-1)(delayed(
            _compute_haralick_features)(patches[y, x, z, :], self.distance)
                                                for y, x, z in zip(yy, xx, zz))

        # Convert to numpy array
        haralick_features = np.array(haralick_features)
        # Reshape the feature matrix
        haralick_features = haralick_features.reshape((patches.shape[0],
                                                       patches.shape[1],
                                                       patches.shape[2],
                                                       nb_directions,
                                                       nb_features))
        # Copy the feature into the object
        self.data_[y_shift : -y_shift,
                   x_shift : -x_shift,
                   z_shift : -z_shift] = haralick_features

        return self
开发者ID:glemaitre,项目名称:protoclass,代码行数:100,代码来源:haralick_extraction.py

示例2: fit

# 需要导入模块: from joblib import Parallel [as 别名]
# 或者: from joblib.Parallel import reshape [as 别名]
    def fit(self, modality, ground_truth=None, cat=None):
        """Compute the images images.

        Parameters
        ----------
        modality : object of type TemporalModality
            The modality object of interest.

        ground-truth : object of type GTModality or None
            The ground-truth of GTModality. If None, the whole data will be
            considered.

        cat : str or None
            String corresponding at the ground-truth of interest. Cannot be
            None if ground-truth is not None.

        Return
        ------
        self : object
             Return self.

        """
        super(DCTExtraction, self).fit(modality=modality,
                                       ground_truth=ground_truth,
                                       cat=cat)

        # Extract the set of patches from the modality data
        patches = extract_patches(modality.data_, patch_shape=self.patch_size)

        # Allocate the DCT maps, one for each feature that
        # will be computed
        nb_features = np.prod(self.patch_size)
        self.data_ = np.zeros((modality.data_.shape[0],
                               modality.data_.shape[1],
                               modality.data_.shape[2],
                               nb_features))

        # # Extract DCT feature for each patch
        # # Define the shift to apply
        if isinstance(self.patch_size, tuple):
            y_shift = int(np.ceil((self.patch_size[0] - 1) / 2.))
            x_shift = int(np.ceil((self.patch_size[1] - 1) / 2.))
            z_shift = int(np.ceil((self.patch_size[2] - 1) / 2.))
        elif isinstance(self.patch_size, int):
            y_shift = int(np.ceil((self.patch_size - 1) / 2.))
            x_shift = int(np.ceil((self.patch_size - 1) / 2.))
            z_shift = int(np.ceil((self.patch_size - 1) / 2.))

        # Create the list of indices to process
        yy, xx, zz = np.meshgrid(range(patches.shape[0]),
                                 range(patches.shape[1]),
                                 range(patches.shape[2]))
        # Linearize for fast processing
        yy = yy.reshape(-1)
        xx = xx.reshape(-1)
        zz = zz.reshape(-1)

        # Go for the parallel loop
        dct_features = Parallel(n_jobs=-1)(delayed(
            _compute_dct_features)(patches[y, x, z, :])
                                                for y, x, z in zip(yy, xx, zz))

        # Convert to numpy array
        dct_features = np.array(dct_features)
        # Reshape the feature matrix
        dct_features = dct_features.reshape((patches.shape[0],
                                             patches.shape[1],
                                             patches.shape[2],
                                             nb_features))

        # Copy the feature into the object
        self.data_[y_shift : -y_shift,
                   x_shift : -x_shift,
                   z_shift : -z_shift] = dct_features

        return self
开发者ID:glemaitre,项目名称:protoclass,代码行数:78,代码来源:dct_extraction.py


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