1
$\begingroup$

so some context, I'm trying to develop an OCR (for fun) and for that reason I decided to first find text within a page, parse it in to letters within the text and from there try and classify the letters that were extracted one by one.

For the classification I'm trying to build a CNN based upon the following database: http://www.ee.surrey.ac.uk/CVSSP/demos/chars74k/

and the following CNN architecture:

 # CNN architecture
input = Input(shape=(32, 32, 1))
conv1 = Conv2D(32, (3, 3))(input)
pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)
drop1 = Dropout(0.5)(pool1)
conv2 = Conv2D(64, (3, 3))(drop1)
pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)
drop2 = Dropout(0.5)(pool2)
flatten = Flatten()(drop2)
fully_connected = Dense(512, activation='relu')(flatten)
output = Dense(62)(fully_connected)
model = Model(inputs=input, outputs=output)
model.compile(loss='sparse_categorical_crossentropy',optimizer='Adam', metrics=['accuracy'])
print(model.summary())
model.fit(X, y, epochs=10 , validation_split=0.3)

However, all I seen to get no matter what I try (epochs, batch size, validation split) etc is 0 accuracy.... So assuming my database and labels are fine... what could be going wrong?

$\endgroup$
1
  • $\begingroup$ Check your targets. Are they one-hot encoded or not? $\endgroup$ Commented Sep 26, 2019 at 6:49

1 Answer 1

0
$\begingroup$

So there are some things you could consider.

First of all, normally datasets like this (or for example mnist) will be one hot encoded. So you have a vector with the length of all classes, each position stands for one class and is 1 if it is the class and 0 otherwise. As you are predicting values between zero and one, the activation of your output should do the same. So the first thing i would change is the activation function of the last layer to sigmoid. It is linear in your case.

Other things to consider are data preprocessing like normalizing pixel values between 0 and 1. Also no data preprocessing at all can lead to unstable training it is unlikely to cause no learning at all.

$\endgroup$
3
  • $\begingroup$ Not entirely sure what being one hot encoded means, however I'm pretty sure my dataset is just a bunch of pictures with nothing else added to them. How can I check this? $\endgroup$
    – crommy
    Commented Sep 26, 2019 at 10:02
  • $\begingroup$ All I did was give letters a label according to their ascii value, was this a mistake? $\endgroup$
    – crommy
    Commented Sep 26, 2019 at 10:05
  • $\begingroup$ So basically you have pictures as input of your neural network. But for supervised learning, what is what you are doing, you also need ground Truth Labels for comparing your predictions against, calculating a loss and update weights of your network via backpropagation. Your Labels should be one hot encoded - and also your output (prediction) should be. If you have three classes A, B, C. [1, 0, 0] would be class A and [0,0,1] class C respectively. There is always only one class present that's why its called ONE hot encoded. Your "Dataset" should contain images AND Labels (onehot in this case) $\endgroup$
    – Jens K
    Commented Sep 26, 2019 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.