-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c8cd659
Showing
7 changed files
with
471 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dataset/ | ||
lekha-OCR-database/ | ||
mal_dataset.tar |
190 changes: 190 additions & 0 deletions
190
.ipynb_checkpoints/Malayalam-Character-Recognition-checkpoint.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from keras.preprocessing import image\n", | ||
"from keras.applications import imagenet_utils\n", | ||
"import numpy as np\n", | ||
"from keras import applications\n", | ||
"from keras.preprocessing.image import ImageDataGenerator\n", | ||
"from keras import optimizers\n", | ||
"from keras.models import Sequential,Model\n", | ||
"from keras.layers.normalization import BatchNormalization\n", | ||
"from keras.models import model_from_json\n", | ||
"from keras.layers import Dense, Activation, Dropout, Flatten\n", | ||
"from keras.layers import Convolution2D\n", | ||
"from keras.layers import MaxPooling2D\n", | ||
"from keras.layers import ZeroPadding2D" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Found 34553 images belonging to 133 classes.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"train_datagen = image.ImageDataGenerator(\n", | ||
" rescale=1./255,\n", | ||
" shear_range=0.2,\n", | ||
" zoom_range=0.2,\n", | ||
" horizontal_flip=True)\n", | ||
"\n", | ||
"test_datagen = image.ImageDataGenerator(rescale=1./255)\n", | ||
"\n", | ||
"train_generator = train_datagen.flow_from_directory(\n", | ||
" '/home/amrith/Machine-Learning/MalayalamOCR/dataset',\n", | ||
" target_size=(32, 32),\n", | ||
" batch_size=16,\n", | ||
" class_mode='binary')\n", | ||
"\n", | ||
"# validation_generator = test_datagen.flow_from_directory(\n", | ||
"# '/home/amrith/Machine-Learning/FastAI/courses/dogscats/sample/valid/',\n", | ||
"# target_size=(64, 64),\n", | ||
"# batch_size=16,\n", | ||
"# class_mode='binary')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def create_model():\n", | ||
" model=Sequential()\n", | ||
" model.add(Convolution2D(64,(3,3),input_shape=(32,32,3),activation='relu',padding='same'))\n", | ||
" model.add(Convolution2D(64,(3,3),activation='relu',padding='same'))\n", | ||
" model.add(MaxPooling2D((2, 2), strides=(2, 2)))\n", | ||
" model.add(Convolution2D(128,(3,3),activation='relu',padding='same'))\n", | ||
" model.add(Convolution2D(128,(3,3),activation='relu',padding='same'))\n", | ||
" model.add(MaxPooling2D((2, 2), strides=(2, 2)))\n", | ||
" model.add(Flatten())\n", | ||
" model.add(Dense(4096, activation='relu'))\n", | ||
" model.add(Dropout(0.5))\n", | ||
" model.add(Dense(4096, activation='relu'))\n", | ||
" model.add(Dropout(0.5))\n", | ||
" model.add(Dense(133, activation='softmax'))\n", | ||
" return model" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"model=create_model()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 15, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"_________________________________________________________________\n", | ||
"Layer (type) Output Shape Param # \n", | ||
"=================================================================\n", | ||
"conv2d_17 (Conv2D) (None, 32, 32, 64) 1792 \n", | ||
"_________________________________________________________________\n", | ||
"conv2d_18 (Conv2D) (None, 32, 32, 64) 36928 \n", | ||
"_________________________________________________________________\n", | ||
"max_pooling2d_9 (MaxPooling2 (None, 16, 16, 64) 0 \n", | ||
"_________________________________________________________________\n", | ||
"conv2d_19 (Conv2D) (None, 16, 16, 128) 73856 \n", | ||
"_________________________________________________________________\n", | ||
"conv2d_20 (Conv2D) (None, 16, 16, 128) 147584 \n", | ||
"_________________________________________________________________\n", | ||
"max_pooling2d_10 (MaxPooling (None, 8, 8, 128) 0 \n", | ||
"_________________________________________________________________\n", | ||
"flatten_5 (Flatten) (None, 8192) 0 \n", | ||
"_________________________________________________________________\n", | ||
"dense_13 (Dense) (None, 4096) 33558528 \n", | ||
"_________________________________________________________________\n", | ||
"dropout_9 (Dropout) (None, 4096) 0 \n", | ||
"_________________________________________________________________\n", | ||
"dense_14 (Dense) (None, 4096) 16781312 \n", | ||
"_________________________________________________________________\n", | ||
"dropout_10 (Dropout) (None, 4096) 0 \n", | ||
"_________________________________________________________________\n", | ||
"dense_15 (Dense) (None, 133) 544901 \n", | ||
"=================================================================\n", | ||
"Total params: 51,144,901\n", | ||
"Trainable params: 51,144,901\n", | ||
"Non-trainable params: 0\n", | ||
"_________________________________________________________________\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"model.summary()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 18, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"model.compile(optimizer='adagrad',\n", | ||
" loss='categorical_crossentropy',\n", | ||
" metrics=['accuracy'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"WARNING (theano.tensor.blas): We did not found a dynamic library into the library_dir of the library we use for blas. If you use ATLAS, make sure to compile it with dynamics library.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"model.fit_generator(train_generator,steps_per_epoch=2000,epochs=50)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 2", | ||
"language": "python", | ||
"name": "python2" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.13" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.