Exemple #1
0
def load_data(split='train'):
    data = dict()

    for shape in shapes_type:
        path = shapes_dataset_path + '/' + str(split) + '/' + str(shape) + '/'
        imgs = find_files(path)
        x = load_images(imgs, path)
        y = [shapes_label[shape]] * len(x)
        data[shape] = (x, y)

    return data
Exemple #2
0
    def run(self, data_path, video=False):

        data = find_files(data_path, sorted_by_idx=False)

        if video:
            media = load_videos(data, data_path)
        else:
            media = load_images(data, data_path)

        if video:
            print(len(media), len(media[0]))

        size = self.model_specs['size']
        omega = self.model_specs['omega']

        cropper = CropImage(size)

        for instance in media:

            instance = rgb2grayscale(instance)

            plt.imshow(instance, cmap='gray')
            plt.title('Input')
            plt.show()

            original_crops = cropper.crop(instance)
            lg_filter = laguerre_gauss_filter(size, omega)
            ft_lg_filter = np.fft.fft2(lg_filter)
            x_profile, y_profile = ft_pipeline(ft_lg_filter, original_crops)
            ft_crops = np.abs(np.concatenate((x_profile, y_profile), axis=1))

            if not self.is_joblib:
                predictions = self.model.predict_on_batch(ft_crops)
            else:
                predictions = self.model.predict(ft_crops)

            print(predictions)

            pos_preds = []

            for i in range(len(predictions)):

                if not self.is_joblib:
                    pred = np.argmax(predictions[i])
                else:
                    pred = predictions[i]

                if pred == 0:
                    continue

                # img = original_crops[i]

                # plt.imshow(img, cmap='gray')
                # plt.title('Prediction: ' + str(pred))
                # plt.show()
                # plt.pause()
                # plt.close()

                pos_preds.append(original_crops[i])

            print(len(pos_preds))
            n_row, n_col = 2, 3
            _, axs = plt.subplots(n_row, n_col, figsize=(12, 12))
            axs = axs.flatten()
            plt.suptitle('Positive Predictions kNN')
            for img, ax in zip(pos_preds, axs):
                ax.imshow(img, cmap='gray')
            plt.show()
Exemple #3
0
    def __init__(self, path):

        self.path = path

        images_path = find_files(self.path)
        self.images_path = shuffle(images_path)
Exemple #4
0
        for img in images:
            resized.append(resize(img, dim))

        return resized


if __name__ == '__main__':

    cropper = CropImage(64)

    path = '/home/alejandro/Documents/Universidad/Semestre 6/PI1/Datasets/Mineria/samples/'
    save_path = '/home/alejandro/Documents/Universidad/Semestre 6/PI1/Datasets/Mineria/crop_64x64_samples/'

    cropper = CropImage(64)

    imgs = find_files(path)
    print('found_images')
    images = load_images(imgs, path)
    print('loaded_images')

    count_0 = 0
    count_1 = 0
    for i in range(len(imgs)):
        image = rgb2grayscale(images[i])
        crops = cropper.crop(image)
        if i % 100 == 0:
            print(i)
        for c in crops:
            img_class = imgs[i][0]
            if img_class == 0:
                class_count = count_0