Devnagri-Character-Recognition¶
The dataset was created by extraction and manual annotation of thousands of characters from handwritten documents.
Creator Name: Shailesh Acharya, Email: sailes437@gmail.com
, Institution: University of North Texas, Cell: +19402200157
Creator Name: Prashnna Kumar Gyawali, Email: gyawali.prasanna@gmail.com
, Institution: Rochester Institute of Technology
Data Type: GrayScale Image
The image dataset can be used to benchmark classification algorithm for OCR systems. The highest accuracy obtained in the Test set is 98.47%. Model Description is available in the paper. Image Format: .png Resolution: 32 by 32
Actual character is centered within 28 by 28 pixel, padding of 2 pixel is added on all four sides of actual character.
S. Acharya, A.K. Pant and P.K. Gyawali “Deep Learning Based Large Scale Handwritten Devanagari Character Recognitionâ€,In Proceedings of the 9th International Conference on Software, Knowledge, Information Management and Applications (SKIMA), pp. 121-126, 2015. Your data will be in front of the world's largest data science community. What questions do you want to see answered?
from google.colab import files
files.upload()
! mkdir ~/.kaggle
! cp kaggle.json ~/.kaggle/
! chmod 600 ~/.kaggle/kaggle.json
! kaggle datasets download -d jhashanku007/devnagri-hindi-dataset
Downloading devnagri-hindi-dataset.zip to /content 100% 158M/159M [00:04<00:00, 64.9MB/s] 100% 159M/159M [00:04<00:00, 40.3MB/s]
# downloading helper_functions.py
! wget https://raw.githubusercontent.com/Hrushi11/Dogs_VS_Cats/main/helper_functions.py
--2021-11-01 14:47:53-- https://raw.githubusercontent.com/Hrushi11/Dogs_VS_Cats/main/helper_functions.py Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.111.133, 185.199.108.133, 185.199.110.133, ... Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.111.133|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 10139 (9.9K) [text/plain] Saving to: ‘helper_functions.py’ helper_functions.py 100%[===================>] 9.90K --.-KB/s in 0s 2021-11-01 14:47:53 (79.3 MB/s) - ‘helper_functions.py’ saved [10139/10139]
Importing dependancies¶
import os
import random
import numpy as np
import pandas as pd
import tensorflow as tf
import matplotlib.pyplot as plt
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from helper_functions import unzip_data, plot_loss_curves, walk_through_dir, confusion_matrix, compare_historys
# Unzipping the data
unzip_data("/content/devnagri-hindi-dataset.zip")
# Walking through the dataset
walk_through_dir("/content/DevanagariHandwrittenCharacterDataset")
There are 2 directories and 0 images in '/content/DevanagariHandwrittenCharacterDataset'. There are 46 directories and 0 images in '/content/DevanagariHandwrittenCharacterDataset/Train'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/digit_9'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_3_ga'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/digit_7'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_8_ja'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_16_tabala'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_31_petchiryakha'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_28_la'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_27_ra'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/digit_6'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_21_pa'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_18_da'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/digit_3'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_20_na'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_30_motosaw'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_13_daa'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_32_patalosaw'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_19_dha'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/digit_5'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_5_kna'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_6_cha'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_22_pha'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_9_jha'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_1_ka'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_26_yaw'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_29_waw'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_2_kha'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/digit_8'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_25_ma'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_36_gya'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_24_bha'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_34_chhya'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_14_dhaa'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_17_tha'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_11_taamatar'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/digit_4'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_35_tra'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_33_ha'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_4_gha'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_10_yna'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/digit_0'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_7_chha'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/digit_2'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_23_ba'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_15_adna'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/digit_1'. There are 0 directories and 1700 images in '/content/DevanagariHandwrittenCharacterDataset/Train/character_12_thaa'. There are 46 directories and 0 images in '/content/DevanagariHandwrittenCharacterDataset/Test'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/digit_9'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_3_ga'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/digit_7'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_8_ja'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_16_tabala'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_31_petchiryakha'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_28_la'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_27_ra'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/digit_6'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_21_pa'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_18_da'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/digit_3'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_20_na'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_30_motosaw'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_13_daa'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_32_patalosaw'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_19_dha'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/digit_5'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_5_kna'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_6_cha'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_22_pha'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_9_jha'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_1_ka'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_26_yaw'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_29_waw'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_2_kha'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/digit_8'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_25_ma'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_36_gya'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_24_bha'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_34_chhya'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_14_dhaa'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_17_tha'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_11_taamatar'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/digit_4'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_35_tra'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_33_ha'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_4_gha'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_10_yna'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/digit_0'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_7_chha'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/digit_2'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_23_ba'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_15_adna'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/digit_1'. There are 0 directories and 300 images in '/content/DevanagariHandwrittenCharacterDataset/Test/character_12_thaa'.
# To delete the zip file
!rm devnagri-hindi-dataset.zip
train_dir = "/content/DevanagariHandwrittenCharacterDataset/Train"
test_dir = "/content/DevanagariHandwrittenCharacterDataset/Test"
# loading and preprocessing the image
def load_and_prep(filepath):
img = tf.io.read_file(filepath)
img = tf.image.decode_image(img)
img = tf.image.resize(img, (32, 32))
if img.shape[2] == 1:
img = tf.image.grayscale_to_rgb(img)
return img
# setting up classes
classes = os.listdir(train_dir)
# Visualizing a random image
class_ = random.choice(classes)
img_path = random.choice(os.listdir(train_dir + "/" + class_))
img = load_and_prep(train_dir + "/" + class_ + "/" + img_path)
plt.imshow(img/255)
plt.axis(False)
plt.title(class_, color="green");
# Plotting multiple ranodm images
plt.figure(figsize=(17, 12))
for i in range(12):
# Getting the image
class_ = random.choice(classes)
img_path = random.choice(os.listdir(train_dir + "/" + class_))
img = load_and_prep(train_dir + "/" + class_ + "/" + img_path)
# plotting on the subplot
plt.subplot(3, 4, i+1)
plt.imshow(img/255)
plt.axis(False)
plt.title(class_, color="green");
# Data generators
data_gen = ImageDataGenerator()
# Train and test data
train_data = data_gen.flow_from_directory(train_dir,
seed=42,
shuffle=True)
test_data = data_gen.flow_from_directory(test_dir,
shuffle=False)
Found 78200 images belonging to 46 classes. Found 13800 images belonging to 46 classes.
len(train_data), len(test_data)
(2444, 432)
train_data.class_indices
{'character_10_yna': 0, 'character_11_taamatar': 1, 'character_12_thaa': 2, 'character_13_daa': 3, 'character_14_dhaa': 4, 'character_15_adna': 5, 'character_16_tabala': 6, 'character_17_tha': 7, 'character_18_da': 8, 'character_19_dha': 9, 'character_1_ka': 10, 'character_20_na': 11, 'character_21_pa': 12, 'character_22_pha': 13, 'character_23_ba': 14, 'character_24_bha': 15, 'character_25_ma': 16, 'character_26_yaw': 17, 'character_27_ra': 18, 'character_28_la': 19, 'character_29_waw': 20, 'character_2_kha': 21, 'character_30_motosaw': 22, 'character_31_petchiryakha': 23, 'character_32_patalosaw': 24, 'character_33_ha': 25, 'character_34_chhya': 26, 'character_35_tra': 27, 'character_36_gya': 28, 'character_3_ga': 29, 'character_4_gha': 30, 'character_5_kna': 31, 'character_6_cha': 32, 'character_7_chha': 33, 'character_8_ja': 34, 'character_9_jha': 35, 'digit_0': 36, 'digit_1': 37, 'digit_2': 38, 'digit_3': 39, 'digit_4': 40, 'digit_5': 41, 'digit_6': 42, 'digit_7': 43, 'digit_8': 44, 'digit_9': 45}
labels = []
for i in train_data.class_indices.keys():
labels.append(i)
labels
['character_10_yna', 'character_11_taamatar', 'character_12_thaa', 'character_13_daa', 'character_14_dhaa', 'character_15_adna', 'character_16_tabala', 'character_17_tha', 'character_18_da', 'character_19_dha', 'character_1_ka', 'character_20_na', 'character_21_pa', 'character_22_pha', 'character_23_ba', 'character_24_bha', 'character_25_ma', 'character_26_yaw', 'character_27_ra', 'character_28_la', 'character_29_waw', 'character_2_kha', 'character_30_motosaw', 'character_31_petchiryakha', 'character_32_patalosaw', 'character_33_ha', 'character_34_chhya', 'character_35_tra', 'character_36_gya', 'character_3_ga', 'character_4_gha', 'character_5_kna', 'character_6_cha', 'character_7_chha', 'character_8_ja', 'character_9_jha', 'digit_0', 'digit_1', 'digit_2', 'digit_3', 'digit_4', 'digit_5', 'digit_6', 'digit_7', 'digit_8', 'digit_9']
Building the model¶
# Setting up base model
base_model = tf.keras.applications.EfficientNetB0(include_top=False)
base_model.trainable = False
# Setting input layer
inputs = tf.keras.layers.Input(shape=(32, 32, 1), name="input_layer")
x = base_model(inputs, training=False)
x = tf.keras.layers.GlobalAveragePooling2D(name="global_average_pooling")(x)
outputs = tf.keras.layers.Dense(len(labels), activation="softmax", name="output_layer")(x)
model_1 = tf.keras.Model(inputs, outputs)
# compiling the model
model_1.compile(loss=tf.keras.losses.categorical_crossentropy,
optimizer=tf.keras.optimizers.Adam(),
metrics=["accuracy"])
# fit the model
history_1 = model_1.fit(train_data,
epochs=5,
steps_per_epoch=len(train_data),
validation_data=test_data,
validation_steps=int(len(test_data) * 0.25))
WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1). Epoch 1/5 WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1). WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1). 2444/2444 [==============================] - ETA: 0s - loss: 1.1488 - accuracy: 0.7455WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1). 2444/2444 [==============================] - 427s 160ms/step - loss: 1.1488 - accuracy: 0.7455 - val_loss: 0.6485 - val_accuracy: 0.8484 Epoch 2/5 2444/2444 [==============================] - 388s 159ms/step - loss: 0.4858 - accuracy: 0.8854 - val_loss: 0.4138 - val_accuracy: 0.9016 Epoch 3/5 2444/2444 [==============================] - 388s 159ms/step - loss: 0.3491 - accuracy: 0.9159 - val_loss: 0.3115 - val_accuracy: 0.9207 Epoch 4/5 2444/2444 [==============================] - 388s 159ms/step - loss: 0.2812 - accuracy: 0.9306 - val_loss: 0.2892 - val_accuracy: 0.9233 Epoch 5/5 2444/2444 [==============================] - 388s 159ms/step - loss: 0.2385 - accuracy: 0.9411 - val_loss: 0.2434 - val_accuracy: 0.9323
model_1.evaluate(test_data)
432/432 [==============================] - 66s 153ms/step - loss: 0.2344 - accuracy: 0.9399
[0.23439805209636688, 0.9398550987243652]
plot_loss_curves(history_1)
# Unfreeze all of the layers in the base model
base_model.trainable = True
# Refreeze every layer except for the last 5
for layer in base_model.layers[:-5]:
layer.trainable = False
# Recompile model with lower learning rate
model_1.compile(loss='categorical_crossentropy',
optimizer=tf.keras.optimizers.Adam(1e-4),
metrics=['accuracy'])
# Fine-tune for 5 more epochs
fine_tune_epochs = 10
history_1_fine_tune_1 = model_1.fit(train_data,
epochs=fine_tune_epochs,
validation_data=test_data,
validation_steps=int(len(test_data) * 0.25),
initial_epoch=history_1.epoch[-1])
Epoch 5/10 WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1). WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1). 2444/2444 [==============================] - ETA: 0s - loss: 0.1618 - accuracy: 0.9537WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1). 2444/2444 [==============================] - 412s 165ms/step - loss: 0.1618 - accuracy: 0.9537 - val_loss: 0.1492 - val_accuracy: 0.9566 Epoch 6/10 2444/2444 [==============================] - 403s 165ms/step - loss: 0.1020 - accuracy: 0.9706 - val_loss: 0.1173 - val_accuracy: 0.9650 Epoch 7/10 2444/2444 [==============================] - 402s 165ms/step - loss: 0.0759 - accuracy: 0.9788 - val_loss: 0.0910 - val_accuracy: 0.9722 Epoch 8/10 2444/2444 [==============================] - 402s 165ms/step - loss: 0.0598 - accuracy: 0.9834 - val_loss: 0.0687 - val_accuracy: 0.9792 Epoch 9/10 2444/2444 [==============================] - 405s 166ms/step - loss: 0.0475 - accuracy: 0.9868 - val_loss: 0.0787 - val_accuracy: 0.9769 Epoch 10/10 2444/2444 [==============================] - 405s 166ms/step - loss: 0.0386 - accuracy: 0.9895 - val_loss: 0.0832 - val_accuracy: 0.9742
model_1.evaluate(test_data)
432/432 [==============================] - 66s 152ms/step - loss: 0.0645 - accuracy: 0.9815
[0.06451807171106339, 0.981521725654602]
compare_historys(history_1, history_1_fine_tune_1)
# Saving the model
model_1.save("/content/drive/MyDrive/Hindi-OCR")
WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1). WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1). WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1). WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1). WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1). WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1). WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1). INFO:tensorflow:Assets written to: /content/drive/MyDrive/Hindi-OCR/assets
/usr/local/lib/python3.7/dist-packages/keras/utils/generic_utils.py:497: CustomMaskWarning: Custom mask layers require a config and must override get_config. When loading, the custom mask layer must be passed to the custom_objects argument. category=CustomMaskWarning)
# Loading a model
model_1 = tf.keras.models.load_model("/content/drive/MyDrive/Hindi-OCR")
WARNING:absl:Importing a function (__inference_block1a_se_reduce_layer_call_and_return_conditional_losses_96928) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block2b_expand_activation_layer_call_and_return_conditional_losses_130957) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6b_expand_activation_layer_call_and_return_conditional_losses_98733) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4a_activation_layer_call_and_return_conditional_losses_132262) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6c_expand_activation_layer_call_and_return_conditional_losses_98894) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_stem_activation_layer_call_and_return_conditional_losses_96863) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block3a_se_reduce_layer_call_and_return_conditional_losses_131543) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4a_expand_activation_layer_call_and_return_conditional_losses_97637) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block2b_activation_layer_call_and_return_conditional_losses_131050) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block1a_activation_layer_call_and_return_conditional_losses_96887) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5a_se_reduce_layer_call_and_return_conditional_losses_133496) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block3a_activation_layer_call_and_return_conditional_losses_131477) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block2a_expand_activation_layer_call_and_return_conditional_losses_130577) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6d_se_reduce_layer_call_and_return_conditional_losses_135854) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_efficientnetb0_layer_call_and_return_conditional_losses_130051) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5a_expand_activation_layer_call_and_return_conditional_losses_98112) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4b_se_reduce_layer_call_and_return_conditional_losses_97855) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6c_activation_layer_call_and_return_conditional_losses_135383) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5c_se_reduce_layer_call_and_return_conditional_losses_134259) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block3b_se_reduce_layer_call_and_return_conditional_losses_131901) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_top_activation_layer_call_and_return_conditional_losses_99362) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5c_activation_layer_call_and_return_conditional_losses_134193) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5c_activation_layer_call_and_return_conditional_losses_98443) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5a_activation_layer_call_and_return_conditional_losses_133430) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block1a_se_reduce_layer_call_and_return_conditional_losses_130378) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block3a_se_reduce_layer_call_and_return_conditional_losses_97395) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4b_se_reduce_layer_call_and_return_conditional_losses_132686) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5b_se_reduce_layer_call_and_return_conditional_losses_98323) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block2b_activation_layer_call_and_return_conditional_losses_97186) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5b_expand_activation_layer_call_and_return_conditional_losses_133695) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_stem_activation_layer_call_and_return_conditional_losses_130219) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4c_se_reduce_layer_call_and_return_conditional_losses_98016) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5c_se_reduce_layer_call_and_return_conditional_losses_98484) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_efficientnetb0_layer_call_and_return_conditional_losses_124927) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_efficientnetb0_layer_call_and_return_conditional_losses_126680) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block2a_expand_activation_layer_call_and_return_conditional_losses_97009) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_model_layer_call_and_return_conditional_losses_119174) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6c_se_reduce_layer_call_and_return_conditional_losses_98959) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6b_se_reduce_layer_call_and_return_conditional_losses_135044) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block3a_expand_activation_layer_call_and_return_conditional_losses_131362) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4b_activation_layer_call_and_return_conditional_losses_97814) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4c_activation_layer_call_and_return_conditional_losses_133025) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6a_se_reduce_layer_call_and_return_conditional_losses_98652) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4b_expand_activation_layer_call_and_return_conditional_losses_132527) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6d_activation_layer_call_and_return_conditional_losses_135788) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5c_expand_activation_layer_call_and_return_conditional_losses_134100) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6a_activation_layer_call_and_return_conditional_losses_98611) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_model_layer_call_and_return_conditional_losses_120801) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4a_se_reduce_layer_call_and_return_conditional_losses_132328) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6d_se_reduce_layer_call_and_return_conditional_losses_99120) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block7a_activation_layer_call_and_return_conditional_losses_136193) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4a_expand_activation_layer_call_and_return_conditional_losses_132147) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block3b_se_reduce_layer_call_and_return_conditional_losses_97541) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6d_expand_activation_layer_call_and_return_conditional_losses_135695) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6d_expand_activation_layer_call_and_return_conditional_losses_99055) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6a_expand_activation_layer_call_and_return_conditional_losses_134505) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6a_se_reduce_layer_call_and_return_conditional_losses_134686) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6c_expand_activation_layer_call_and_return_conditional_losses_135290) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block3b_expand_activation_layer_call_and_return_conditional_losses_131742) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5b_se_reduce_layer_call_and_return_conditional_losses_133854) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_efficientnetb0_layer_call_and_return_conditional_losses_107554) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block7a_expand_activation_layer_call_and_return_conditional_losses_99216) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block3a_activation_layer_call_and_return_conditional_losses_97354) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_efficientnetb0_layer_call_and_return_conditional_losses_128298) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block2a_se_reduce_layer_call_and_return_conditional_losses_130758) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4c_se_reduce_layer_call_and_return_conditional_losses_133091) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block3b_expand_activation_layer_call_and_return_conditional_losses_97476) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4a_activation_layer_call_and_return_conditional_losses_97668) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5b_expand_activation_layer_call_and_return_conditional_losses_98258) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5a_expand_activation_layer_call_and_return_conditional_losses_133337) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block3b_activation_layer_call_and_return_conditional_losses_97500) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5b_activation_layer_call_and_return_conditional_losses_98282) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5b_activation_layer_call_and_return_conditional_losses_133788) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_efficientnetb0_layer_call_and_return_conditional_losses_111229) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5c_expand_activation_layer_call_and_return_conditional_losses_98419) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6c_se_reduce_layer_call_and_return_conditional_losses_135449) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4c_activation_layer_call_and_return_conditional_losses_97975) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6b_expand_activation_layer_call_and_return_conditional_losses_134885) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6b_activation_layer_call_and_return_conditional_losses_98757) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_top_activation_layer_call_and_return_conditional_losses_136458) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block2b_se_reduce_layer_call_and_return_conditional_losses_131116) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6d_activation_layer_call_and_return_conditional_losses_99079) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4c_expand_activation_layer_call_and_return_conditional_losses_97951) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5a_se_reduce_layer_call_and_return_conditional_losses_98177) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block2b_expand_activation_layer_call_and_return_conditional_losses_97162) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block1a_activation_layer_call_and_return_conditional_losses_130312) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6b_activation_layer_call_and_return_conditional_losses_134978) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6c_activation_layer_call_and_return_conditional_losses_98918) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block3b_activation_layer_call_and_return_conditional_losses_131835) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4c_expand_activation_layer_call_and_return_conditional_losses_132932) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6b_se_reduce_layer_call_and_return_conditional_losses_98798) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6a_activation_layer_call_and_return_conditional_losses_134620) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block2a_activation_layer_call_and_return_conditional_losses_97040) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block2a_activation_layer_call_and_return_conditional_losses_130692) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4b_activation_layer_call_and_return_conditional_losses_132620) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block2a_se_reduce_layer_call_and_return_conditional_losses_97081) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block6a_expand_activation_layer_call_and_return_conditional_losses_98580) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference__wrapped_model_89580) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block2b_se_reduce_layer_call_and_return_conditional_losses_97227) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block3a_expand_activation_layer_call_and_return_conditional_losses_97323) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block7a_expand_activation_layer_call_and_return_conditional_losses_136100) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4a_se_reduce_layer_call_and_return_conditional_losses_97709) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block7a_se_reduce_layer_call_and_return_conditional_losses_99281) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block4b_expand_activation_layer_call_and_return_conditional_losses_97790) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block7a_se_reduce_layer_call_and_return_conditional_losses_136259) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block5a_activation_layer_call_and_return_conditional_losses_98136) with ops with unsaved custom gradients. Will likely fail if a gradient is requested. WARNING:absl:Importing a function (__inference_block7a_activation_layer_call_and_return_conditional_losses_99240) with ops with unsaved custom gradients. Will likely fail if a gradient is requested.
WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1).
WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1).
Insights in our model¶
preds = model_1.predict(test_data)
WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1).
WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'"), but it was called on an input with incompatible shape (None, 32, 32, 1).
preds[0]
array([9.9582881e-01, 2.6212038e-11, 9.8154579e-13, 3.9618858e-10, 4.9600901e-12, 3.7116474e-13, 7.7138845e-10, 1.3794156e-06, 7.2012174e-11, 5.6772973e-07, 4.5733076e-10, 2.0151650e-05, 1.0675103e-12, 1.6194118e-10, 2.3464647e-08, 2.5897662e-04, 4.8776155e-08, 3.4213465e-07, 1.5583765e-11, 6.2619351e-05, 4.7069229e-09, 5.9471159e-08, 6.1910293e-07, 1.7079125e-11, 1.7062344e-05, 8.4313848e-11, 7.5230616e-07, 3.5860432e-07, 1.3313568e-04, 6.8861840e-07, 1.1280036e-07, 6.1802695e-07, 2.7936586e-08, 1.2068566e-09, 3.6736231e-03, 1.4535169e-08, 8.2223413e-14, 2.9153526e-12, 5.9057175e-13, 5.9487788e-13, 4.2920433e-12, 4.3636414e-09, 1.6776560e-12, 7.1392295e-13, 5.9168653e-14, 1.7717716e-16], dtype=float32)
preds[0].argmax()
0
preds[0].max()
0.9958288
true = []
for i in test_data.filepaths:
true.append(i.split("/")[4])
len(true)
13800
pred_indices = []
for i in preds:
pred_indices.append(i.argmax())
len(pred_indices)
13800
pred_labels = []
for i in pred_indices:
pred_labels.append(labels[i])
len(pred_labels)
13800
check = []
for i in range(len(pred_labels)):
check.append("True") if true[i] == pred_labels[i] else check.append("False")
len(check)
13800
pred_prob = []
for i in range(len(pred_labels)):
pred_prob.append(preds[i].max())
pred_prob[0]
0.9958288
df_test_preds = pd.DataFrame({"Filepath": test_data.filepaths,
"True label": true,
"Pred label": pred_labels,
"Pred Prob": pred_prob,
"Check": check})
df_test_preds.head()
Filepath | True label | Pred label | Pred Prob | Check | |
---|---|---|---|---|---|
0 | /content/DevanagariHandwrittenCharacterDataset... | character_10_yna | character_10_yna | 0.995829 | True |
1 | /content/DevanagariHandwrittenCharacterDataset... | character_10_yna | character_10_yna | 0.988693 | True |
2 | /content/DevanagariHandwrittenCharacterDataset... | character_10_yna | character_10_yna | 0.989036 | True |
3 | /content/DevanagariHandwrittenCharacterDataset... | character_10_yna | character_10_yna | 0.997819 | True |
4 | /content/DevanagariHandwrittenCharacterDataset... | character_10_yna | character_10_yna | 0.928055 | True |
df_test_preds.tail()
Filepath | True label | Pred label | Pred Prob | Check | |
---|---|---|---|---|---|
13795 | /content/DevanagariHandwrittenCharacterDataset... | digit_9 | digit_9 | 1.000000 | True |
13796 | /content/DevanagariHandwrittenCharacterDataset... | digit_9 | digit_9 | 0.999999 | True |
13797 | /content/DevanagariHandwrittenCharacterDataset... | digit_9 | digit_9 | 1.000000 | True |
13798 | /content/DevanagariHandwrittenCharacterDataset... | digit_9 | digit_9 | 0.999762 | True |
13799 | /content/DevanagariHandwrittenCharacterDataset... | digit_9 | digit_9 | 0.999955 | True |
df_test_preds.to_csv("/content/All-preds.csv")
filepaths = test_data.filepaths
wrng_filepaths = []
wrng_pred = []
true_ = []
wrng_pred_prob = []
for i in range(len(pred_labels)):
if check[i] == "False":
true_.append(true[i])
wrng_filepaths.append(filepaths[i])
wrng_pred.append(pred_labels[i])
wrng_pred_prob.append(pred_prob[i])
len(wrng_pred)
255
df_wrng_test_preds = pd.DataFrame({"Filepath": wrng_filepaths,
"True label": true_,
"Pred label": wrng_pred,
"Pred Prob": wrng_pred_prob})
df_wrng_test_preds.head()
Filepath | True label | Pred label | Pred Prob | |
---|---|---|---|---|
0 | /content/DevanagariHandwrittenCharacterDataset... | character_10_yna | character_24_bha | 0.554238 |
1 | /content/DevanagariHandwrittenCharacterDataset... | character_10_yna | character_8_ja | 0.589436 |
2 | /content/DevanagariHandwrittenCharacterDataset... | character_10_yna | character_8_ja | 0.800656 |
3 | /content/DevanagariHandwrittenCharacterDataset... | character_10_yna | character_17_tha | 0.480395 |
4 | /content/DevanagariHandwrittenCharacterDataset... | character_10_yna | character_8_ja | 0.716537 |
df_wrng_test_preds.tail()
Filepath | True label | Pred label | Pred Prob | |
---|---|---|---|---|
250 | /content/DevanagariHandwrittenCharacterDataset... | digit_6 | character_4_gha | 0.424101 |
251 | /content/DevanagariHandwrittenCharacterDataset... | digit_6 | digit_3 | 0.992277 |
252 | /content/DevanagariHandwrittenCharacterDataset... | digit_6 | character_7_chha | 0.471611 |
253 | /content/DevanagariHandwrittenCharacterDataset... | digit_7 | digit_1 | 0.372736 |
254 | /content/DevanagariHandwrittenCharacterDataset... | digit_9 | digit_3 | 0.749345 |
df_wrng_test_preds
Filepath | True label | Pred label | Pred Prob | |
---|---|---|---|---|
0 | /content/DevanagariHandwrittenCharacterDataset... | character_10_yna | character_24_bha | 0.554238 |
1 | /content/DevanagariHandwrittenCharacterDataset... | character_10_yna | character_8_ja | 0.589436 |
2 | /content/DevanagariHandwrittenCharacterDataset... | character_10_yna | character_8_ja | 0.800656 |
3 | /content/DevanagariHandwrittenCharacterDataset... | character_10_yna | character_17_tha | 0.480395 |
4 | /content/DevanagariHandwrittenCharacterDataset... | character_10_yna | character_8_ja | 0.716537 |
... | ... | ... | ... | ... |
250 | /content/DevanagariHandwrittenCharacterDataset... | digit_6 | character_4_gha | 0.424101 |
251 | /content/DevanagariHandwrittenCharacterDataset... | digit_6 | digit_3 | 0.992277 |
252 | /content/DevanagariHandwrittenCharacterDataset... | digit_6 | character_7_chha | 0.471611 |
253 | /content/DevanagariHandwrittenCharacterDataset... | digit_7 | digit_1 | 0.372736 |
254 | /content/DevanagariHandwrittenCharacterDataset... | digit_9 | digit_3 | 0.749345 |
255 rows × 4 columns
# df_wrng_test_preds.to_csv("/content/drive/MyDrive/Hindi-OCR/Wrong-preds.csv")
# Visualizing wrong predictions
rand_num = np.random.randint(len(wrng_pred))
img = load_and_prep(wrng_filepaths[rand_num])
plt.imshow(img/255)
plt.axis(False)
title_ = f"True label: {true_[rand_num]}, \nPred label: {wrng_pred[rand_num]}, Pred prob: {wrng_pred_prob[rand_num]:.2f}"
plt.title(title_, color = "red");
# Plotting multiple random wrong images
plt.figure(figsize=(20, 14))
rand_set = random.sample(range(len(wrng_pred)), 12)
for i in range(12):
# getting images
title_ = f"True label: {true_[rand_set[i]]}, \nPred label: {wrng_pred[rand_set[i]]}, Pred prob: {wrng_pred_prob[rand_set[i]]:.2f}"
img = load_and_prep(wrng_filepaths[rand_set[i]])
# plotting images
plt.subplot(3, 4, i+1)
plt.imshow(img/255)
plt.axis(False)
plt.title(title_, color="red");
# Random Predictions
plt.figure(figsize=(20, 14))
rand_set = random.sample(range(len(pred_prob)), 12)
for i in range(12):
# getting images
title_ = f"True label: {true[rand_set[i]]}, \nPred label: {pred_labels[rand_set[i]]}, Pred prob: {pred_prob[rand_set[i]]:.2f}"
img = load_and_prep(filepaths[rand_set[i]])
clr = "green" if true[rand_set[i]] == pred_labels[rand_set[i]] else "red"
# plotting images
plt.subplot(3, 4, i+1)
plt.imshow(img/255)
plt.axis(False)
plt.title(title_, color=clr);