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


Python image.load_img方法代码示例

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


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

示例1: _compute_stats

# 需要导入模块: from keras_preprocessing import image [as 别名]
# 或者: from keras_preprocessing.image import load_img [as 别名]
def _compute_stats(self, mean = None, std = None):
        """ Computes channel-wise mean and standard deviation of all images in the dataset.
        
        If `mean` and `std` arguments are given, they will just be stored instead of being re-computed.

        The channel order of both is always "RGB", independent of `color_mode`.
        """
        
        if mean is None:
            mean = 0
            for fn in tqdm(self.train_img_files, desc = 'Computing channel mean'):
                mean += np.mean(np.asarray(load_img(fn), dtype=np.float64), axis = (0,1))
            mean /= len(self.train_img_files)
            print('Channel-wise mean:               {}'.format(mean))
        self.mean = np.asarray(mean, dtype=np.float32)
        if (mean is None) or (std is None):
            std = 0
            for fn in tqdm(self.train_img_files, desc = 'Computing channel variance'):
                std += np.mean((np.asarray(load_img(fn), dtype=np.float64) - self.mean) ** 2, axis = (0,1))
            std = np.sqrt(std / (len(self.train_img_files) - 1))
            print('Channel-wise standard deviation: {}'.format(std))
        self.std = np.asarray(std, dtype=np.float32) 
开发者ID:cvjena,项目名称:semantic-embeddings,代码行数:24,代码来源:common.py

示例2: load_images

# 需要导入模块: from keras_preprocessing import image [as 别名]
# 或者: from keras_preprocessing.image import load_img [as 别名]
def load_images(data_dir, image_paths, image_shape):
    images = None

    for i, image_path in enumerate(image_paths):
        print()
        try:
            # Load image
            loaded_image = image.load_img(os.path.join(data_dir, image_path), target_size=image_shape)

            # Convert PIL image to numpy ndarray
            loaded_image = image.img_to_array(loaded_image)

            # Add another dimension (Add batch dimension)
            loaded_image = np.expand_dims(loaded_image, axis=0)

            # Concatenate all images into one tensor
            if images is None:
                images = loaded_image
            else:
                images = np.concatenate([images, loaded_image], axis=0)
        except Exception as e:
            print("Error:", i, e)

    return images 
开发者ID:PacktPublishing,项目名称:Generative-Adversarial-Networks-Projects,代码行数:26,代码来源:run.py

示例3: get_preds

# 需要导入模块: from keras_preprocessing import image [as 别名]
# 或者: from keras_preprocessing.image import load_img [as 别名]
def get_preds(model):
    size = model.input_shape[1]

    filename = os.path.join(os.path.dirname(__file__),
                            'data', '565727409_61693c5e14.jpg')

    batch = KE.preprocess_input(img_to_array(load_img(
                                filename, target_size=(size, size))))

    batch = np.expand_dims(batch, 0)

    pred = decode_predictions(model.predict(batch),
                              backend=K, utils=utils)

    return pred 
开发者ID:titu1994,项目名称:keras-efficientnets,代码行数:17,代码来源:test_build.py

示例4: _load_image

# 需要导入模块: from keras_preprocessing import image [as 别名]
# 或者: from keras_preprocessing.image import load_img [as 别名]
def _load_image(self, filename, target_size = None, randzoom = False):
        """ Loads an image file.

        # Arguments:

        - filename: The path of the image file.

        - target_size: Int or tuple of ints. Specifies the target size which the image will be resized to.
                       If a single int is given, it specifies the size of the smaller side of the image and the aspect ratio will be retained.
                       If set to -1, the image won't be resized.
                       If set to None, the default_target_size passed to the constructor will be used.
                       The actual size may be modified further is `randzoom` is True.
        
        - randzoom: If True and `self.randzoom_range` is not None, random zooming will be applied.
                    If `self.randzoom_range` is given as floats defining a range relative to the image size,
                    `target_size` will be used as reference if it is not None, otherwise the original image size.
        
        # Returns:
            the image as PIL image.
        """

        img = load_img(filename)
        if target_size is None:
            target_size = self.default_target_size
        
        if (target_size > 0) or (randzoom and (self.randzoom_range is not None)):
            if target_size <= 0:
                target_size = img.size
            if randzoom and (self.randzoom_range is not None):
                if isinstance(self.randzoom_range[0], float):
                    target_size = np.round(np.array(target_size) * np.random.uniform(self.randzoom_range[0], self.randzoom_range[1])).astype(int).tolist()
                else:
                    target_size = np.random.randint(self.randzoom_range[0], self.randzoom_range[1])
            if isinstance(target_size, int):
                target_size = (target_size, round(img.size[1] * (target_size / img.size[0]))) if img.size[0] < img.size[1] else (round(img.size[0] * (target_size / img.size[1])), target_size)
            img = img.resize(target_size, PIL.Image.BILINEAR)
        
        return img 
开发者ID:cvjena,项目名称:semantic-embeddings,代码行数:40,代码来源:common.py

示例5: preprocess_image

# 需要导入模块: from keras_preprocessing import image [as 别名]
# 或者: from keras_preprocessing.image import load_img [as 别名]
def preprocess_image(img_path):
    img = image.load_img(img_path, target_size=(224, 224))
    input_img_data = image.img_to_array(img)
    input_img_data = np.expand_dims(input_img_data, axis=0)
    input_img_data = preprocess_input(input_img_data)  # final input shape = (1,224,224,3)
    return input_img_data 
开发者ID:peikexin9,项目名称:deepxplore,代码行数:8,代码来源:utils.py


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