What is the value of the chain image recognition Classifier.predictor?

Asked 5 months ago, Updated 5 months ago, 14 views

I saved the model by using a chain to learn 73 hiragana characters from images on a convolutional neural network.I'm writing a code that reads the model I learned in serializers.load_npz, enters a handwritten image, recognizes it, and displays the top five as a result with a percentage.

Target Display Results (Example)

tegaki_na.png Identification Results
 Yes: 60%
 only: 25%
 Yes: 10%
 Ah: 4%
 —1% of 1%

However, we found that the matrix (73 elements) obtained from the predictor data that we were trying to use as a percentage is from positive to negative, so it cannot be used as a percentage (even if we add everything together, it never went to 1 or 100).
When I read the official Chain.Links.Classifier section, there was no description of the output of the predictor, so I asked you a question here.

Here is the source code.Here, the actual value in the predictor is to be printed as it is (I want this to be a percentage)

import numpy as np
import cv2
import chain
import chain.links as L
from chain import Variable
# Convolution model saved as convolution_model.py
import convolution_model as CNN

label=['A', 'I', 'U', 'E', 'O',
         'Ka', 'ki', 'gi', 'ku', 'gu', 'ke', 'ge', 'ko', 'go', 'go', 'go', 'go'
         'Sa', 'the', 'shi', 'ji', 'su', 'zu', 'se', 'ze', 'so', 'so', 'so', 'so', 'so', 'so', 'so', 'so', 'so', 'so', 'so', 'so', 'so', 'so', 'so', 'so', '
         "Ta", "da", "chi", "ji", "tsu", "tsu", "te", "te", "te", "te", "te", "te", "te", "te", "te", "te", "te", "te", "te", "te", "te", "te", "te", "te", "te
         of 'na', 'n', 'n', 'ne', 'ne', 'ne', 'ne', 'ne', 'ne', 'ne', 'ne', 'ne,ne',
         ' is ', 'ba', 'pa', 'hi', 'bi', 'pi', 'fu', 'bu', 'pu', 'he', 'be', 'bae', 'ho', 'bo', 'po', 'po', 'po', 'po', 'po', 'po', 'po', 'po', 'po', 'po', 'po', 'po', 'po', 'po', 'po', 'po', 'po', 'po', 'po', 'po', 'po', 'po',
         "Ma", "Mi", "Mu", "Me", "Momo",
         'Hey', 'Yu', 'Yu', 'Yo',
         'ra', 'ri', 'ru', 're', 'ro', 'wa', 'i', 'e', 'e', 'e', 'e', 'n'n'n'n'n'n'n'n'n'n'n'n'n'n'n'n'n'n'n'n'n'n]

# Assume image size is 48x48
model = L. Classifier (CNN.Model())

defloadimg (image):
    img_=cv2.imread(image,0)# Load as grayscale

    height,width=img_.shape [:2]
    if height!=48 or width!=48:# If length is not 48px
        resize to img_=cv2.resize(img_, (48,48))#48x48

    temp = [ ]
    temp2 = [ ]
    return img_

def score(image):

    result=result.data[0]#Probability of each character?


    a_label = a_label [-1::-1]
    a_ratio=a_ratio [-1::-1]
    return a_label, a_ratio

Code to execute (assuming you are moving the current to the working directory)

AL,AR = score (IMGName)

print(IMGName, 'Results')
for i in range (73):
    an_l = AL[i]
    print(str(label[ans_l], ':', str(AR[i]))


tegaki_na.png Identification Results
 Yes: 42.3303
 only: 30.025
 is 26.0882
 Ah: 25.0445
 where: 19.8176

python chainer

2022-09-30 12:01

1 Answers


The predictor attribute stores the first argument given to the L.Classifier, so the source of the question is the CNN.Model()) portion of model=L.Classifier(CNN.Model()).
The Model in convolution_model.py just shows the value you defined.

(In other words, L.Classifier is only passing the identification model you defined.)

2022-09-30 12:01

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.