예제 #1
0
def preprocess_image(image, target_size):
    img = image.resize(target_size)
    img = img_to_array(img)
    img = preprocess_input(img)
    img = np.expand_dims(img, axis=0)

    return img
예제 #2
0
def preprocess_image(image):
    #image = tf.image.decode_jpeg(image, channels=3)
    #image = tf.image.resize(image, [224, 224])
    #image = keras.applications.xception.preprocess_input(image)  ## 수정해야함

    image = tf.image.decode_jpeg(image, channels=3)
    image = tf.image.resize(image, [224, 224])  #  antialias = True
    image = preprocess_input(image)
    return image
 def format_image(self, image):
     """Resize the images to a fixed input size, and
     rescale the input channels to a range of [-1, 1].
     (According to https://www.tensorflow.org/tutorials/images/transfer_learning)
     """
     image = tf.cast(image, tf.float32)
     #       \/ does the same #  image = (image / 127.5) - 1
     image = preprocess_input(
         image
     )  # https://github.com/keras-team/keras-applications/blob/master/keras_applications/imagenet_utils.py#L152
     image = tf.image.resize(image, (self.IMG_SIZE, self.IMG_SIZE))
     return image
예제 #4
0
def matching_dog(model, img_input_path, embedding_path, merged_path, target_size, top_n=15):
    """Returns list of top_n similar dog objects"""
    img = image.load_img(img_input_path, target_size=target_size)

    img_data = image.img_to_array(img)
    img_data = np.expand_dims(img_data, axis=0)
    img_data = preprocess_input(img_data)
    emb_input = model.predict(img_data)[0]

    merged = pd.read_csv(merged_path)

    emb_matrix = np.loadtxt(embedding_path)

    scores = []
    for i in range(len(emb_matrix)):
        scores.append(cos_d(emb_input, list(emb_matrix[i])))

    ranks = [[index, merged.photo_url[index], merged.links[index],
              merged.titles[index], score] for index,
             score in enumerate(scores, 0)]
    ranks.sort(key=lambda x: x[-1])

    dogs = []

    seen = set()
    ind = 0
    while len(dogs) < top_n:
        instance = ranks[ind]
        if instance[1] not in seen:
            seen.add(instance[1])
        else:
            ind += 1
            continue
        profile = PetProfile(instance[2],instance[1])
        dogs.append(profile)
        ind += 1
    return dogs
예제 #5
0
def preprocess_image(image):

    image = tf.image.decode_jpeg(image, channels=3)
    image = tf.image.resize(image, [IMG_SIZE, IMG_SIZE])  #  antialias = True
    image = preprocess_input(image)
    return image
예제 #6
0
def preprocess_input(image):
    image = efn.preprocess_input(image)
    image = tf.cast(tf.reshape(1, 300, 300, 3), tf.float32)
    return image
import os
import sys
import numpy as np
from skimage.io import imread
import matplotlib.pyplot as plt
sys.path.append('..')
# if you use tensorflow.keras:
from efficientnet.tfkeras import EfficientNetB0
from efficientnet.tfkeras import center_crop_and_resize, preprocess_input
from tensorflow.keras.applications.imagenet_utils import decode_predictions
# test image
test_b_2 = "../predict/pics/ROI.png"
image = imread(test_b_2)

plt.figure(figsize=(10, 10))
plt.imshow(image)
plt.show()

# loading pretrained model
model = EfficientNetB0(weights='imagenet')

# preprocess input
image_size = model.input_shape[1]
x = center_crop_and_resize(image, image_size=image_size)
x = preprocess_input(x)
print(x.shape)
x = np.expand_dims(x, 0)

# make prediction and decode
y = model.predict(x)
print(decode_predictions(y))
예제 #8
0
def _get_panda_input(input_shape):
    image = imread(PANDA_PATH)
    image = efn.center_crop_and_resize(image, input_shape[1])
    image = efn.preprocess_input(image)
    image = np.expand_dims(image, 0)
    return image
예제 #9
0
 def preprocess_image(self, inputs):
     """ Takes as input an image and prepares it for being passed through the network.
     """
     return efn.preprocess_input(inputs)
예제 #10
0
def preprocess_image(image):
    image = tf.image.decode_jpeg(image, channels=3)
    image = tf.image.resize(image, [224, 224])
    image = preprocess_input(image)

    return image
예제 #11
0
def preprocess_image(image):
    img = tf.image.resize(image, (331, 331))
    img = preprocess_input(img)
    return img
예제 #12
0
def load_images(img_path):
    img = load_img(img_path, target_size=(224, 224))
    img = img_to_array(img)
    img = preprocess_input(img)
    return img
예제 #13
0
def load_image(image_path):
    img = tf.io.read_file(image_path)
    img = tf.image.decode_png(img, channels=3)
    img = tf.image.resize(img, (299, 299))
    img = efn.preprocess_input(img)
    return img, image_path
def load_image(image_path):
    img = tf.io.read_file(image_gcs_path+image_path)
    img = tf.image.decode_jpeg(img, channels=3)
    img = tf.image.resize(img, (331, 331))
    img = preprocess_input(img)
    return img, image_path
예제 #15
0
from tensorflow.keras.models import Model, load_model
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from efficientnet.tfkeras import preprocess_input
from tensorflow.keras.preprocessing import image
import numpy as np

# This is the path from where the trained model will be loaded from
trained_model_dir = 'models/trained/effnetb4_retrainedpt9.h5'

# This is the directory containing the test data
test_dir = 'data/test'

# Load model
model = load_model(trained_model_dir)

img = image.load_img(imgPath, target_size=(380, 380))
img = image.img_to_array(img)
img = preprocess_input(img)
img = np.expand_dims(img, axis=0)

classes = ['akiec', 'bcc', 'bkl', 'df', 'mel', 'nv', 'vasc']

resultset = model.predict(img)

prediction_string = ''
index = 0
for result in resultset[0]:
    prediction_string += '{} {}\n'.format(classes[index], result)
    index += 1

print(prediction_string)
예제 #16
0
def read_image(img_file):
    return preprocess_input(square_crop(cv2.cvtColor(cv2.imread(img_file), cv2.COLOR_BGR2RGB)))