Skip to content

Ancient Japanese Kana classification based on Keras CNN

Notifications You must be signed in to change notification settings

chiawei-liu/Kana-CNN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ancient Japanese Kana classification with CNN

Install venv

$ python -m venv <env_name>
$ source <env_name>/bin/activate
(<env_name>)$ pip install -r ./requirements.txt

on Windows, run <env_name>\Scripts\activate.bat instead of source <env_name>/bin/activate

Training model

Run

$ python main.py -d [data_path]

For example

$ python main.py -d /alcon2019/dataset/train_kana

As default, all images are read and preprocessed to generate ./preprocessed_data.npy If you modify the model structure and want to retrain again, while the data are the same, you can run

$ python main.py -d [data_path] -r False

to skip the preprocessing. The program will import processed data from preproccessed_data.npy directly.

After training, the model is stored in ./model/ and the label binarization object is stored in ./labelbin/. These two files are used for prediction of new input image.

A visualized result of the loss and accuracy rates over each epoch is stored in ./plot/.

A json file counting the incorrect validations of each class is stored as ./incorrectCount.json

Classify new input image with the trained model

From terminal

Run

$ python classify.py -m ./model/model -l ./labelbin/labelbin -i [image_path]

to classify a Kana image.

From code

from classify import KanaClassifier
import cv2

model_path = './model/model'
labelbin_path = './labelbin/labelbin'
image_path = 'some_path'

kc = KanaClassifier(model_path, labelbin_path)
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
result = kc.classify(img)

result is a list of dictionaries containing two keys, unicode and confidence, sorted by the confidence from high to low.

About

Ancient Japanese Kana classification based on Keras CNN

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages