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


Python image.load_img方法代码示例

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


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

示例1: run_inference

# 需要导入模块: from tensorflow.python.keras.preprocessing import image [as 别名]
# 或者: from tensorflow.python.keras.preprocessing.image import load_img [as 别名]
def run_inference():
    model = ResNet50(input_shape=(224, 224, 3), num_classes=10)
    model.load_weights(MODEL_PATH)

    picture = os.path.join(execution_path, "Haitian-fireman.jpg")

    image_to_predict = image.load_img(picture, target_size=(
        224, 224))
    image_to_predict = image.img_to_array(image_to_predict, data_format="channels_last")
    image_to_predict = np.expand_dims(image_to_predict, axis=0)

    image_to_predict = preprocess_input(image_to_predict)

    prediction = model.predict(x=image_to_predict, steps=1)

    predictiondata = decode_predictions(prediction, top=int(5), model_json=JSON_PATH)

    for result in predictiondata:
        print(str(result[0]), " : ", str(result[1] * 100))


# run_inference() 
开发者ID:OlafenwaMoses,项目名称:IdenProf,代码行数:24,代码来源:idenprof.py

示例2: test

# 需要导入模块: from tensorflow.python.keras.preprocessing import image [as 别名]
# 或者: from tensorflow.python.keras.preprocessing.image import load_img [as 别名]
def test():
    import os
    import numpy as np
    from PIL import Image
    from tensorflow.python.keras.preprocessing.image import load_img

    from models import Darknet19Encoder, Darknet19Decoder

    inputShape = (256, 256, 3)
    batchSize = 8
    latentSize = 100

    img = load_img(os.path.join(os.path.dirname(__file__), '..','images', 'img.jpg'), target_size=inputShape[:-1])
    img.show()

    img = np.array(img, dtype=np.float32) * (2/255) - 1
#     print(np.min(img))
#     print(np.max(img))
#     print(np.mean(img))

    img = np.array([img]*batchSize) # make fake batches to improve GPU utilization

    # This is how you build the autoencoder
    encoder = Darknet19Encoder(inputShape, latentSize=latentSize, latentConstraints='bvae', beta=69)
    decoder = Darknet19Decoder(inputShape, latentSize=latentSize)
    bvae = AutoEncoder(encoder, decoder)
    bvae.ae.compile(optimizer='adam', loss='mean_absolute_error')
    while True:
        bvae.ae.fit(img, img,
                    epochs=100,
                    batch_size=batchSize)

        # example retrieving the latent vector
        latentVec = bvae.encoder.predict(img)[0]
        print(latentVec)

        pred = bvae.ae.predict(img) # get the reconstructed image
        pred = np.uint8((pred + 1)* 255/2) # convert to regular image values

        pred = Image.fromarray(pred[0])
        pred.show() # display popup 
开发者ID:alecGraves,项目名称:BVAE-tf,代码行数:43,代码来源:ae.py

示例3: preprocess_image

# 需要导入模块: from tensorflow.python.keras.preprocessing import image [as 别名]
# 或者: from tensorflow.python.keras.preprocessing.image import load_img [as 别名]
def preprocess_image(path):
        '''Process an image to numpy array.

        Args:
            path: the path of the image.

        Returns:
            Numpy array of the image.
        '''
        img = process_image.load_img(path, target_size=(224, 224))
        x = process_image.img_to_array(img)
        # x = np.expand_dims(x, axis=0)
        x = preprocess_input(x)
        return x 
开发者ID:ryanfwy,项目名称:image-similarity,代码行数:16,代码来源:model_util.py

示例4: load_img

# 需要导入模块: from tensorflow.python.keras.preprocessing import image [as 别名]
# 或者: from tensorflow.python.keras.preprocessing.image import load_img [as 别名]
def load_img(in_dir):
    pred_img = [f for f in os.listdir(in_dir) if os.path.isfile(os.path.join(in_dir, f))]
    img_collection = []
    for idx, img in enumerate(pred_img):
        img = os.path.join(in_dir, img)
        img_collection.append(image.load_img(img, target_size=(out_res, out_res)))
    if (np.square(out_dim) > len(img_collection)):
        raise ValueError("Cannot fit {} images in {}x{} grid".format(len(img_collection), out_dim, out_dim))
    return img_collection 
开发者ID:prabodhhere,项目名称:tsne-grid,代码行数:11,代码来源:tsne_grid.py

示例5: main

# 需要导入模块: from tensorflow.python.keras.preprocessing import image [as 别名]
# 或者: from tensorflow.python.keras.preprocessing.image import load_img [as 别名]
def main():
    model = build_model()
    img_collection = load_img(in_dir)
    activations = get_activations(model, img_collection)
    print("Generating 2D representation.")
    X_2d = generate_tsne(activations)
    print("Generating image grid.")
    save_tsne_grid(img_collection, X_2d, out_res, out_dim) 
开发者ID:prabodhhere,项目名称:tsne-grid,代码行数:10,代码来源:tsne_grid.py

示例6: _get_batches_of_transformed_samples

# 需要导入模块: from tensorflow.python.keras.preprocessing import image [as 别名]
# 或者: from tensorflow.python.keras.preprocessing.image import load_img [as 别名]
def _get_batches_of_transformed_samples(self, index_array):
        batch_x = np.zeros(
            (len(index_array),) + self.image_shape,
            dtype=floatx())
        grayscale = self.color_mode == 'grayscale'

        # Build batch of image data
        for i, j in enumerate(index_array):
            fname = self.filenames[j]
            img = load_img(
                os.path.join(self.directory, fname),
                grayscale=grayscale,
                target_size=None,
                interpolation=self.interpolation)
            x = img_to_array(img, data_format=self.data_format)

            # Pillow images should be closed after `load_img`, but not PIL images.
            if hasattr(img, 'close'):
                img.close()

            x = self.image_data_generator.standardize(x)
            batch_x[i] = x

        # Optionally save augmented images to disk for debugging purposes
        if self.save_to_dir:
            for i, j in enumerate(index_array):
                img = array_to_img(batch_x[i], self.data_format, scale=True)
                fname = '{prefix}_{index}_{hash}.{format}'.format(
                    prefix=self.save_prefix,
                    index=j,
                    hash=np.random.randint(1e7),
                    format=self.save_format)
                img.save(os.path.join(self.save_to_dir, fname))

        # Build batch of labels
        if self.class_mode == 'input':
            batch_y = batch_x.copy()
        elif self.class_mode == 'sparse':
            batch_y = self.classes[index_array]
        elif self.class_mode == 'binary':
            batch_y = self.classes[index_array].astype(floatx())
        elif self.class_mode == 'categorical':
            batch_y = np.zeros(
                (len(batch_x), self.num_classes),
                dtype=floatx())
            for i, label in enumerate(self.classes[index_array]):
                batch_y[i, label] = 1.
        else:
            return batch_x

        return batch_x, batch_y 
开发者ID:ryanfwy,项目名称:BCNN-keras-clean,代码行数:53,代码来源:data_preprocesser.py


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