Example #1
0
        "test4" : 
        load_model("./output/test4_simple_imgtoarr_version2aug/model-resnet50_new_head-004-0.0673-2515.hdf5"),
        "test5" :
        load_model("./output/test5_simple_meansub_imgtoarr_version2aug/model-resnet50_new_head-003-0.0933-5503.hdf5"),
        "test6" :
        load_model("./output/test6_aspect_meansub_imgtoarr_version2aug/model-resnet50_new_head-002-0.0974-11163.hdf5"),

        }
model = ModelBanks[modelname]


## initialize preprocessors
sp = SimplePreprocessor(224, 224)
aap = AspectAwarePreprocessor(224, 224)
iap = ImageToArrayPreprocessor()
cp1 = CropPreprocessor(224, 224) # 10-crops TTA

trainmeans = json.loads(open("./output/dogs_vs_cats_mean.json").read())
mp = MeanPreprocessor(trainmeans["R"], trainmeans["G"], trainmeans["B"])


print("[INFO] using %s model..." % modelname)
predictions = []
ids = []
submission = pd.read_csv("./sample_submission.csv")  # columns = [id/int, label/float]

# preprocess batch images & do prediction
if useTTA == "True":
    print("[INFO] applying TTA..") 
else:
    print("[INFO] NOT applying TTA..") 
Example #2
0
from keras.models import load_model
import json
import numpy as np
import matplotlib
matplotlib.use("Agg")
from tqdm import tqdm


# parameters
BATCH_SIZE = 64

## initiate all image preprocessors
sp = SimplePreprocessor(227, 227)
pp = PatchPreprocessor(227, 227)
iap = ImageToArrayPreprocessor()
cp = CropPreprocessor(227, 227)

# load in RGB mean values of training set
trainmeans = json.loads(open("./output/dogs_vs_cats_train_mean.json").read())
mp = MeanPreprocessor(trainmeans["R"], trainmeans["G"], trainmeans["B"])


## load pre-trained model
#print("[INFO] predicting with AlexNet...")
#model = load_model(os.path.join(config.OUTPUT_PATH, \
#        "model-alexnet-075-0.2944_without_padding_10283.hdf5"))

print("[INFO] predicting with AlexNet2 (with padding)...")
model = load_model(os.path.join(config.OUTPUT_PATH, \
        "model-alexnet2-075-0.2972_with_padding_9299.hdf5"))
Example #3
0
N = len(imagePaths)
useTTA = args["TTA"]  # MUST be str!!!

print("[INFO] using %s model..." % modelname)
predictions = []
submission = pd.read_csv("./sample_submission.csv")  # columns = [id,label]

# preprocess batch images & do prediction
if "alexnet" in modelname:

    if useTTA == "True":
        print("[INFO] applying TTA..")
    else:
        print("[INFO] NOT applying TTA..")

    cp1 = CropPreprocessor(227, 227)  # 10-crops TTA

    # loop over batches
    for i in tqdm(range(0, N, B)):
        batchPaths = imagePaths[i:i + B]
        batchImages = []
        for path in batchPaths:
            image = cv2.imread(path)
            image = aap.preprocess(
                image)  # maintain AR and resize to 256 x 256
            image = iap.preprocess(image)
            # Special for ImageNet dataset => substracting mean RGB pixel intensity
            image = imagenet_utils.preprocess_input(image)  # (256, 256, 3)
            batchImages.append(image)
            pass
NUM_CLASSES = 2
VAL_HDF5 = "./data/val.hdf5"
DATASET_MEAN = "./output/dogs_vs_cats_mean.json"

#OUTPUT_PATH = "./output/test5_simple_meansub_imgtoarr_version2aug"
OUTPUT_PATH = "./output/test6_aspect_meansub_imgtoarr_version2aug"
        

BATCH_SIZE = 64


## initiate all image preprocessors
sp = SimplePreprocessor(224, 224)
pp = PatchPreprocessor(224, 224)
iap = ImageToArrayPreprocessor()
cp = CropPreprocessor(224, 224)
aap = AspectAwarePreprocessor(224, 224)

# load in RGB mean values of training set
trainmeans = json.loads(open("./output/dogs_vs_cats_mean.json").read())
mp = MeanPreprocessor(trainmeans["R"], trainmeans["G"], trainmeans["B"])


## load pre-trained model & initiate HDF5DataGenerator for valset
print("[INFO] predicting with ResNet50...")
model = load_model(os.path.join(OUTPUT_PATH, \
        "model-resnet50_new_head-002-0.0974-11163.hdf5"))   # for test 6
#        "model-resnet50_new_head-003-0.0933-5503.hdf5"))   # for test 5


print("[INFO] evaluating on valset WITHOUT crop/TTA ...")