text_plain_output_1.png
from keras.applications.vgg16 import VGG16

from keras.layers import Dense, Conv2D, MaxPooling2D, Dropout, BatchNormalization, Activation

from keras.layers import Flatten

from keras.models import Model, Sequential

from keras.optimizers import SGD

from keras.preprocessing.image import ImageDataGenerator

from matplotlib import pyplot

import cv2

import numpy as np

import numpy as np # linear algebra

import sys

def define_model():
    model = VGG16(include_top=False, input_shape=(224, 224, 3))
    for layer in model.layers:
        layer.trainable = False
    flat1 = Flatten()(model.layers[-1].output)
    class1 = Dense(256, activation='relu', kernel_initializer='he_uniform')(flat1)
    output = Dense(166, activation='softmax')(class1)
    model = Model(inputs=model.inputs, outputs=output)
    opt = SGD(lr=0.001, momentum=0.9)
    model.compile(optimizer=opt, loss='categorical_crossentropy', metrics=['accuracy'])
    return model

def summarize_diagnostics(history):
    filename = sys.argv[0].split('/')[-1]
    pyplot.close()

train_datagen = ImageDataGenerator(rescale=1.0 / 255.0)
test_datagen = ImageDataGenerator(rescale=1.0 / 255.0)
train_it = train_datagen.flow_from_directory('/kaggle/input/dataset/train/', class_mode='categorical', batch_size=10, target_size=(224, 224))
test_it = test_datagen.flow_from_directory('/kaggle/input/dataset/test/', class_mode='categorical', batch_size=5, target_size=(224, 224))

model = define_model()
model.summary()

history = model.fit_generator(train_it, steps_per_epoch=len(train_it), validation_data=test_it, validation_steps=len(test_it), epochs=20, verbose=1)
_, acc = model.evaluate_generator(test_it, steps=len(test_it), verbose=0)
model.save('accuracy - %.3f' % (acc * 100.0) + '.h5')
summarize_diagnostics(history)

import cv2
img = cv2.imread('/kaggle/input/dataset/test/Voltorb/Voltorb.14.png')
img = cv2.resize(img, (100, 100))
pred = model.predict(np.array([img]))
move_code = np.argmax(pred[0])
move_code