Example #1
0
submission = pd.read_csv("./sample_submission.csv")  # columns = [id,label]

# preprocess batch images & do prediction
if useTTA == "True":
    print("[INFO] applying TTA..")
else:
    print("[INFO] NOT applying 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

    if useTTA == "True":
        for image in batchImages:
            crops = cp1.preprocess(image)

            # predict over 10 crops
            crops_probs = model.predict(crops)

            # predict probs of dogs
            pred = crops_probs.mean(axis=0)[1]
            predictions.append(pred)
Example #2
0
print("[INFO] rank-1 accuracy = {:.2f}%".format(rank1acc1 * 100))
testGen1.close()


print("[INFO] evaluating on valset WITH crop/TTA ...")
testGen2 = HDF5DatasetGenerator(
        config.TEST_HDF5, 
        BATCH_SIZE,
        # substract mean
        preprocessors=[mp],
        classes=2,
        )

predictions2 = []
# loop over batchs & apply 10-crops oversampling/TTA
for images, labels in tqdm(testGen2.generator(passes=1)):
    # loop over image, create 10-crops, convert to keras array 
    for image in images:
        crops = cp.preprocess(image)
        crops = np.array([iap.preprocess(crop) for crop in crops], dtype="float32")
        # predict over 10 crops
        preds = model.predict(crops)
        predictions2.append(preds.mean(axis=0))
    pass

rank1acc2, _ = rank5_accuracy(predictions2, testGen2.db["labels"])
print("[INFO] rank-1 accuracy = {:.2f}%".format(rank1acc2 * 100)) 
testGen2.close()