Example #1
0
        idx = path.split(os.path.sep)[-1].split(".")[0]
        ids.append(int(idx))

        # preprocess image
        image = cv2.imread(path)
        for p in [aap, iap]:    # maintain AR and resize to 224x224
            image = p.preprocess(image)   

        # Special for ImageNet dataset => substracting mean RGB pixel intensity
        image = imagenet_utils.preprocess_input(image)  # (224, 224, 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)
        pass

    else:
        # loop over batchImages, resize to (227, 227)
        for i in range(len(batchImages)):
            batchImages[i] = cv2.resize(batchImages[i], (224, 224))
        batchImages = np.array(batchImages)     # (224, 224, 3)
Example #2
0
    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)

                #pred = crops_probs.mean(axis=0)    # (1. 2)
                #predictions.append(np.argmax(pred))

                # predict probs of dogs
                pred = crops_probs.mean(axis=0)[1]
                predictions.append(pred)
            pass

        else:
            # loop over batchImages, resize to (227, 227)
            for i in range(len(batchImages)):