014-01.手書き文字-日本語の文字を外挿評価-教師有り

サイトの紹介と使い方動画


created: 2021/10/08 modified: 2021/11/06

概要

  1. 指定した文字の正答率を算出します。

外挿評価

1グループ対応 :013-01.py

共有変数と関数-c001.py

c001.手書き文字-日本語-共有ソースを参照してください。

import os,glob,sys
import numpy as np
from PIL import Image
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.models import model_from_json

import c001_env as env

def main():
    json_string = open( env.fs_json,'r' ).read()
    model = model_from_json(json_string)
    model.load_weights( env.fs_hdf5 )

    nncor = 0

    for idx,group in enumerate( env.groups ):
        img_dir = env.test_dir + group
        files   = glob.glob( img_dir+env.file_type )
        nfiles  = len(files)
        ncor    = 0
        for ii,ff in enumerate(files):

            img = Image.open( ff )
            img = img.resize( (env.img_size,env.img_size) )
            img = img.convert( env.img_mode )
            data = np.asarray( img )
            x2   = data.tolist()
            x1 = []
            x1.append( x2 )
            data = np.asarray( x1,dtype='int8' )
            data = data.astype( 'float32') /255

            pre = model.predict( data )
            idx2,max = env.best_char(pre[0])
            if( idx==idx2 ):
                ncor += 1

        nncor += ncor
        print( group,ncor,' / ',nfiles )

    print( nncor,' / ',env.nb_classes*nfiles )

    print( 'success' )

main()

Family対応 :013-51.py

共有変数と関数-c002.py

c001.手書き文字-日本語-共有ソースを参照してください。

import os,glob,sys
import numpy as np
from PIL import Image
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.models import model_from_json

import c002_env as env

def main():
    json_string = open( env.fs_json,'r' ).read()
    model = model_from_json(json_string)
    model.load_weights( env.fs_hdf5 )

    nncor  = 0
    preidx = 0

    for ii,f_dir in enumerate( env.family_dir ):
        groups = env.family_member[ii]
        rdir   = env.root_dir+'/'+f_dir+'/test/'
        print( groups,rdir )
        idx     = preidx
        preidx += len( env.family_member[ii] )
        for jj,group in enumerate( groups ):
            img_dir = rdir + group
            files   = glob.glob( img_dir+env.file_type )
            nfiles  = len(files)
            ncor    = 0
            idx3    = idx+jj
            for kk,ff in enumerate(files):
                img = Image.open( ff )
                img = img.resize( (env.img_size,env.img_size) )
                img = img.convert( env.img_mode )
                data = np.asarray( img )
                x2   = data.tolist()
                x1 = []
                x1.append( x2 )
                data = np.asarray( x1,dtype='int8' )
                data = data.astype( 'float32') /255
                pre = model.predict( data )
                idx2,max = env.best_char(pre[0])
                if( idx3==idx2 ):
                    ncor += 1

            nncor += ncor
            print( group,ncor,' / ',nfiles )

    print( nncor,' / ',env.nb_classes*nfiles )

    print( 'success' )

main()

内挿評価

Family対応 :013-512.py

共有変数と関数-c002.py

c001.手書き文字-日本語-共有ソースを参照してください。

import os,glob,sys
import numpy as np
from PIL import Image
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.models import model_from_json

import c002_env as env

def main():
    json_string = open( env.fs_json,'r' ).read()
    model = model_from_json(json_string)
    model.load_weights( env.fs_hdf5 )

    nncor  = 0
    preidx = 0

    for ii,f_dir in enumerate( env.family_dir ):
        groups = env.family_member[ii]
        rdir   = env.root_dir+'/'+f_dir+'/train/'
        print( groups,rdir )
        idx     = preidx
        preidx += len( env.family_member[ii] )
        for jj,group in enumerate( groups ):
            img_dir = rdir + group
            files   = glob.glob( img_dir+env.file_type )
            nfiles  = len(files)
            ncor    = 0
            idx3    = idx+jj
            for kk,ff in enumerate(files):
                img = Image.open( ff )
                img = img.resize( (env.img_size,env.img_size) )
                img = img.convert( env.img_mode )
                data = np.asarray( img )
                x2   = data.tolist()
                x1 = []
                x1.append( x2 )
                data = np.asarray( x1,dtype='int8' )
                data = data.astype( 'float32') /255
                pre = model.predict( data )
                idx2,max = env.best_char(pre[0])
                if( idx3==idx2 ):
                    ncor += 1

            nncor += ncor
            print( group,ncor,' / ',nfiles )

    print( nncor,' / ',env.nb_classes*nfiles )

    print( 'success' )

main()

前の記事:013-01.手書き文字-日本語の認識モデルの作成
次の記事:015-01.手書き文字-日本語の似ている文字の洗い出し

お問合せ・御要望

  • お問合せ
  • トップへ戻る
    タイトルとURLをコピーしました