<jupyter_start><jupyter_text>Important Links1. https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html2. https://www.pyimagesearch.com/2019/07/08/keras-imagedatagenerator-and-data-augmentation/3. https://www.tensorflow.org/api_docs/python/tf/keras/preprocessing/image/ImageDataGenerator4. https://github.com/Arsey/keras-transfer-learning-for-oxford102/issues/1  Importing dataset<jupyter_code>!ls
!unzip Dataset.zip
# Loading libraries

from keras.preprocessing.image import ImageDataGenerator
from PIL import ImageFile<jupyter_output><empty_output><jupyter_text>Data augmentation<jupyter_code>ImageFile.LOAD_TRUNCATED_IMAGES = True

train_datagen = ImageDataGenerator( rescale= 1./255 , shear_range= .2 , rotation_range=25)
test_datagen = ImageDataGenerator(rescale = 1./255)

# Loading data from directory

train_data = train_datagen.flow_from_directory('Dataset/Train/', 
                                               target_size=(40,40),
                                               batch_size=32 ,
                                               class_mode= 'categorical'
                                               )
test_data = test_datagen.flow_from_directory("Dataset/Test/",
                                            target_size=(40,40),
                                            batch_size=32 ,
                                            class_mode= 'categorical')<jupyter_output>Found 12000 images belonging to 50 classes.
Found 3000 images belonging to 50 classes.<jupyter_text>Model build<jupyter_code>import tensorflow as tf
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense,Dropout
model = Sequential()

model.add(Conv2D(filters = 128, kernel_size = (3, 3), activation = 'relu', input_shape = (40, 40, 3)))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Dropout(.2))

model.add(Conv2D(filters = 64, kernel_size = (3, 3), activation = 'relu'))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Dropout(.2))

model.add(Flatten())

model.add(Dense(units = 128, activation = 'relu'))
model.add(Dropout(.2))

model.add(Dense(units = 50, activation = 'softmax'))

model.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])<jupyter_output><empty_output><jupyter_text>Fitting the model  Notes1. model.fit is used when the entire training dataset can fit into the memory and no data augmentation is applied.2. model.fit_generator is used when either we have a huge dataset to fit into our memory or when data augmentation needs to be applied.link: https://www.pyimagesearch.com/2018/12/24/how-to-use-keras-fit-and-fit_generator-a-hands-on-tutorial/But it is deprecated in Tensorflow 2+<jupyter_code>model.fit(train_data, epochs = 2, validation_data = test_data)
model.summary()
classifier_json = model.to_json()

with open("BanglaHandWrittenCharacterRecognition_CNN.json", "w") as json_file:
    json_file.write(classifier_json)
    
model.save_weights("BanglaHandWrittenCharacterRecognition_CNN.h5")
print('Saved model to disk')<jupyter_output>Saved model to disk<jupyter_text>Validate our model<jupyter_code># importing libraries

import PIL
from PIL import ImageTk, ImageDraw, Image
from keras.preprocessing import image
!pip install pillow<jupyter_output>Requirement already satisfied: pillow in /usr/local/lib/python3.6/dist-packages (7.0.0)<jupyter_text><jupyter_code>def determine_character(res):
    if res == 0:
        print('prediction : অ')
    elif res == 1:
        print('prediction : আ')
    elif res == 2:
        print('prediction : ই')
    elif res == 3:
        print('prediction : ঈ')
    elif res == 4:
        print('prediction : উ')
    elif res == 5:
        print('prediction : ঊ')
    elif res == 6:
        print('prediction : ঋ')
    elif res == 7:
        print('prediction : এ')
    elif res == 8:
        print('prediction : ঐ')
    elif res == 9:
        print('prediction : ও')
    elif res == 10:
        print('prediction : ঔ')
    elif res == 11:
        print('prediction : ক')
    elif res == 12:
        print('prediction : খ')
    elif res == 13:
        print('prediction : গ')
    elif res == 14:
        print('prediction : ঘ')
    elif res == 15:
        print('prediction : ঙ')
    elif res == 16:
        print('prediction : চ')
    elif res == 17:
        print('prediction : ছ')
    elif res == 18:
        print('prediction : জ')
    elif res == 19:
        print('prediction : ঝ')
    elif res == 20:
        print('prediction : ঞ')
    elif res == 21:
        print('prediction : ট')
    elif res == 22:
        print('prediction : ঠ')
    elif res == 23:
        print('prediction : ড')
    elif res == 24:
        print('prediction : ঢ')
    elif res == 25:
        print('prediction : ণ')
    elif res == 26:
        print('prediction : ত')
    elif res == 27:
        print('prediction : থ')
    elif res == 28:
        print('prediction : দ')
    elif res == 29:
        print('prediction : ধ')
    elif res == 30:
        print('prediction : ন')
    elif res == 31:
        print('prediction : প')
    elif res == 32:
        print('prediction : ফ')
    elif res == 33:
        print('prediction : ব')
    elif res == 34:
        print('prediction : ভ')
    elif res == 35:
        print('prediction : ম')
    elif res == 36:
        print('prediction : য')
    elif res == 37:
        print('prediction : র')
    elif res == 38:
        print('prediction : ল')
    elif res == 39:
        print('prediction : শ')
    elif res == 40:
        print('prediction : ষ')
    elif res == 41:
        print('prediction : স')
    elif res == 42:
        print('prediction : হ')
    elif res == 43:
        print('prediction : ড়')
    elif res == 44:
        print('prediction : ঢ়')
    elif res == 45:
        print('prediction : য়')
    elif res == 46:
        print('prediction : ৎ')
    elif res == 47:
        print('prediction : ং')
    elif res == 48:
        print('prediction : ঃ')
    else:
        print('prediction : ঁ')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12813324538258575, 'fraction_numerical': 0.03133245382585752, 'mean_word_length': 2.6295631358467983, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 5, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '573184', 'license': 'MIT', 'n_tokens_mistral': 2143, 'n_tokens_neox': 1926, 'n_words': 467, 'path': 'Bangla Character Recognition using CNN.ipynb', 'repo_name': 'Manash-git/Bangla-Character-Recognition-using-CNN', 'size': '6064'}