from PIL import Image
import os, glob
import numpy as np
from sklearn import model_selection

classes = ["car", "bycycle", "motorcycle", "pedestrian"]
num_class = len(classes)
image_size = 50

# 画像の読み込み

X = []
Y = []

for index, classlabel in enumerate(classes):
    photos_dir = "./" + classlabel
    files = glob.glob(photos_dir + "/*.jpg")
    for i, file in enumerate(files):
        if i >=237: break
        image = Image.open(file)
        image = image.convert("RGB")
        image = image.resize((image_size, image_size))
        data = np.asarray(image) / 255
        X.append(data)
        Y.append(index)

X = np.array(X)
Y = np.array(Y)

X_train, X_test, y_train, y_test = model_selection.train_test_split(X, Y)
xy = (X_train, X_test, y_train, y_test)
np.save("./vehicle.npy", xy)
[(27, 'numpy.array', 'np.array', True, 'import numpy as np\n'), (28, 'numpy.array', 'np.array', True, 'import numpy as np\n'), (30, 'sklearn.model_selection.train_test_split', 'model_selection.train_test_split', False, 'from sklearn import model_selection\n'), (32, 'numpy.save', 'np.save', True, 'import numpy as np\n'), (17, 'glob.glob', 'glob.glob', False, 'import os, glob\n'), (20, 'PIL.Image.open', 'Image.open', False, 'from PIL import Image\n'), (23, 'numpy.asarray', 'np.asarray', True, 'import numpy as np\n')]