application_vnd.jupyter.stderr_output_1.png
from PIL import Image

import numpy as np

import os

import pandas as pd

def get_pixel_data(filepath):
    """
    Get the pixel data from an image as a pandas DataFrame.
    """
    image = Image.open(filepath)
    pixel_data = np.array(image.getdata())
    pixel_data = pixel_data.mean(axis=1)
    pixel_data = pixel_data.reshape(1, 32 * 32)
    pixel_data = pd.DataFrame(pixel_data, columns=np.arange(32 * 32))
    image.close()
    return pixel_data

path = '../input/train/train/'
train = pd.DataFrame()
for file in sorted(os.listdir(path)):
    image = get_pixel_data(path + file)
    train = train.append(image, ignore_index=True)
labels_train = pd.read_csv('../input/train.csv').sort_values('id')
path = '../input/test/test/'
test = pd.DataFrame()
test_id = []
for file in sorted(os.listdir(path)):
    image = get_pixel_data(path + file)
    test = test.append(image, ignore_index=True)
    test_id.append(file)

print('TRAIN---------------------')
print('Shape: {}'.format(train.shape))
print('Label 0 (False): {}'.format(np.sum(labels_train.has_cactus == 0)))
print('Label 1 (True):  {}'.format(np.sum(labels_train.has_cactus == 1)))
print('TEST----------------------')
print('Shape: {}'.format(test.shape))