text_plain_output_1.png
from keras.layers import AveragePooling2D, MaxPooling2D, Dropout, GlobalMaxPooling2D, GlobalAveragePooling2D

from keras.layers import Input,Add, Dense, Activation, ZeroPadding2D, BatchNormalization, Flatten, Conv2D

from keras.models import Model

import h5py

import numpy as np # linear algebra

def load_dataset():
    train_dataset = h5py.File('../input/hand-sign/train_signs.h5', 'r')
    train_set_x_orig = np.array(train_dataset['train_set_x'][:])
    train_set_y_orig = np.array(train_dataset['train_set_y'][:])
    test_dataset = h5py.File('../input/hand-sign-test/test_signs.h5', 'r')
    test_set_x_orig = np.array(test_dataset['test_set_x'][:])
    test_set_y_orig = np.array(test_dataset['test_set_y'][:])
    train_set_y_orig = train_set_y_orig.reshape((1, train_set_y_orig.shape[0]))
    test_set_y_orig = test_set_y_orig.reshape((1, test_set_y_orig.shape[0]))
    return (train_set_x_orig, train_set_y_orig, test_set_x_orig, test_set_y_orig)

train_x, train_y, test_x, test_y = load_dataset()
(train_x.shape, train_y.shape, test_x.shape, test_y.shape)

train_y = train_y.reshape((1080,))
test_y = test_y.reshape((120,))
Y_train = np.zeros([1080, 6])
count = 0
for i in train_y:
    Y_train[count, i] = 1
    count = count + 1
Y_test = np.zeros([120, 6])
count = 0
for i in test_y:
    Y_test[count, i] = 1
    count = count + 1

def plain_layer(X, n_c):
    X_in = X
    X = Conv2D(n_c, kernel_size=(3, 3), padding='same')(X_in)
    X = BatchNormalization()(X)
    X = Activation('relu')(X)
    X = MaxPooling2D(pool_size=(2, 2))(X)
    return X

def identity_block(X, F):
    X_in = X
    F1, F2, F3 = F
    X = Conv2D(F1, kernel_size=(3, 3), padding='same')(X_in)
    X = BatchNormalization()(X)
    X = Activation('relu')(X)
    X = Conv2D(F2, kernel_size=(3, 3), padding='same')(X)
    X = BatchNormalization()(X)
    X = Activation('relu')(X)
    X = Conv2D(F3, kernel_size=(3, 3), padding='same')(X)
    X = BatchNormalization()(X)
    X = Add()([X, X_in])
    X = Activation('relu')(X)
    return X

def Resnet(input_shape=(64, 64, 3), classes=6):
    X_in = Input(input_shape)
    X = plain_layer(X_in, 32)
    F = [16, 32, 32]
    X = identity_block(X, F)
    X = MaxPooling2D(pool_size=(2, 2))(X)
    X = identity_block(X, F)
    X = MaxPooling2D(pool_size=(2, 2))(X)
    X = identity_block(X, F)
    X = MaxPooling2D(pool_size=(2, 2))(X)
    X = plain_layer(X, 16)
    X = Flatten()(X)
    X = Dense(512, activation='relu')(X)
    X = Dense(128, activation='relu')(X)
    X = Dense(classes, activation='softmax')(X)
    model = Model(inputs=X_in, outputs=X, name='Resnet')
    return model

train_x = train_x / 255
test_x = test_x / 255

my_model = Resnet()

my_model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
my_model.fit(x=train_x, y=Y_train, epochs=10, batch_size=32)

my_model.evaluate(train_x, Y_train)

pred = my_model.predict(train_x)

pred