image_output_1.png
from keras.utils import to_categorical

import h5py

import numpy as np

import pandas as pd

data = pd.read_csv('../input/letters.csv')
files = data['file']
letters = data['letter']
backgrounds = data['background']

f = h5py.File('../input/LetterColorImages.h5', 'r')
keys = list(f.keys())
keys

backgrounds = np.array(f[keys[0]])
tensors = np.array(f[keys[1]])
targets = np.array(f[keys[2]])

tensors = tensors.astype('float32') / 255

gray_tensors = np.dot(tensors[..., :3], [0.299, 0.587, 0.114])
gray_tensors = gray_tensors.reshape(-1, 32, 32, 1)

cat_targets = to_categorical(np.array(targets - 1), 33)
cat_targets.shape

backgrounds = to_categorical(backgrounds, 2)
backgrounds.shape

back_targets = np.concatenate((cat_targets, backgrounds), axis=1)
back_targets.shape