def run(self, path, choice=[0, 0, 0], top=3):
     preds = []
     x = self.load_image(path)
     if choice[0] == 1:
         preds.extend(self.resnet.predict(x))
     if choice[1] == 1:
         preds.extend(self.inception.predict(x))
     if choice[2] == 1:
         preds.extend(self.inceptionresnet.predict(x))
     scores = map_scores(preds, top)
     return scores
Beispiel #2
0
    def run(self,path,choice=[0,0,0],top=3):
        """
        Inputs image and predicts using selected model
        
        # Arguments
            path: String path to image
            choice: Array of binary values for selecting models to infer.
                Each index of array used to represent a model.
                Ex:
                    [1, 1, 1] toggles [ResNet152V2, InceptionV3, InceptionResNetV2]'
            top: Integer indicating the top 'X' classes of prediction.

        # Returns
            A list of lists of model name and top class prediction tuples
            Ex:
                path = 'image_path'
                choice = [1,0,1]
                top = 3

                [
                    [
                        'ResNet152V2', 
                        ('nv', 'melanocytic nevi', 0.9999974), 
                        ('bkl', 'benign keratosis-like lesions, solar lentigines / seborrheic keratoses and lichen-planus like keratoses', 2.5060908e-06), 
                        ('akiec', "Actinic keratoses and intraepithelial carcinoma / Bowen's disease", 1.4720392e-07)
                    ], 
                    [
                        'InceptionResNetV2', 
                        ('nv', 'melanocytic nevi', 1.0), 
                        ('mel', 'melanoma', 2.9319884e-13), 
                        ('bkl', 'benign keratosis-like lesions, solar lentigines / seborrheic keratoses and lichen-planus like keratoses', 8.238215e-15)
                    ]
                ]
        """
        
        preds = []
        x = self.load_image(path)
        if choice[0] == 1:
            arr = ['ResNet152V2']
            arr.extend(self.resnet.predict(x))
            preds.append(arr)
        if choice[1] == 1:
            arr = ['InceptionV3']
            arr.extend(self.inception.predict(x))
            preds.append(arr)
        if choice[2] == 1:
            arr = ['InceptionResNetV2']
            arr.extend(self.inceptionresnet.predict(x))
            preds.append(arr)
        scores = map_scores(preds,top)
        return scores
Beispiel #3
0
import numpy as np
import tensorflow as tf
import time

config = tf.ConfigProto()
config.gpu_options.allow_growth = True
tf.keras.backend.set_session(tf.Session(config=config))

start_time = time.time()

dim_size = 224
input_tensor = Input(shape=(dim_size, dim_size, 3))

model = InceptionResNetV2(input_tensor=input_tensor, weights=None, classes=7)
model.load_weights('weights_inceptionresnet224.h5', by_name=False)

img_path = str(
    Path(__file__).resolve().parents[1]) + '/test_imgs/keratosis1.jpg'
img = image.load_img(img_path, target_size=(dim_size, dim_size))
x = image.img_to_array(img)
x = x / 255.0
x = np.expand_dims(x, axis=0)
#x = preprocess_input(x)

preds = model.predict(x)
# decode the results into a list of tuples (class, description, probability)
# (one such list for each sample in the batch)
print('Predicted:', map_scores(preds, 3)[0])

elapsed_time = time.time() - start_time
print('Runtime: ', elapsed_time)
def predict(x, model):
    preds = model.predict(x)
    return map_scores(preds, 3)[0]