text_plain_output_1.png
import cv2

import cv2

import glob

import glob

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import os

import os

import random

import random
labels = [1, 2, 3]
count = 0
for l in labels:
    train_files = ['../input/train/Type_' + str(l) + '/' + f for f in os.listdir('../input/train/Type_' + str(l) + '/')]
    random_file = random.choice(train_files)
    im = cv2.imread(random_file)
    plt.axis('off')
    count += 1

img_rows = 224
img_cols = 224
def get_im_cv2(path, img_rows, img_cols, color_type=3):
    if color_type == 1:
        img = cv2.imread(path, 0)
    elif color_type == 3:
        img = cv2.imread(path)
    resized = cv2.resize(img, (img_cols, img_rows))
    return resized
def load_train(img_rows, img_cols, color_type=3):
    X_train = []
    y_train = []
    print('Read train images')
    for j in range(1, 4):
        print('Load folder Type_{}'.format(j))
        path = os.path.join('..', 'input', 'train', 'Type_' + str(j), '*.jpg')
        files = glob.glob(path)
        for fl in files:
            flbase = os.path.basename(fl)
            img = get_im_cv2(fl, img_rows, img_cols, color_type)
            X_train.append(img)
            y_train.append(j)
    return (X_train, y_train)
X_train, y_train = load_train(64, 64, 3)