3

I am using a Keras network that uses an input image of 128x128 pixels, this network got an accuracy of more than 85% on the chars74K dataset. When I converted this network to a CoreML model the results are always 100% certain but always wrong, never the correct letter. The code for my Keras network can be found here: https://github.com/thijsheijden/chars74kCNN

The code I used to convert to a CoreMLModel is the following:

import coremltools
import h5py
import pandas

coreml_model = coremltools.converters.keras.convert(
                                                    "chars74kV4.0.h5", class_labels = "class_labels.txt", image_input_names= ['input'], input_names=['input'])
coreml_model.author = 'Thijs van der Heijden'
coreml_model.license = 'MIT'
coreml_model.description = 'A basic Deep Convolutional Neural Network to classify handwritten letters.'
coreml_model.input_description['input'] = 'A 128x128 pixel Image'
coreml_model.save('chars74k.mlmodel')

The code for my IOS App can be found here: https://github.com/thijsheijden/Visionary

I would greatly appreciate any help as I am really stuck on this one! Thanks in advance!

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Thijs van der Heijden
  • 1,147
  • 1
  • 10
  • 25
  • There are several things to check. For your inputs, what colorspace does your trained model expect (RGB, BGR, RGBA or BGRA) and what orientation were the trained images? Are you matching this for your Core ML inference? Are you properly scaling the images to the correct input size? Is your mapping table for the numerical outputs from your network correct? You most likely have a mismatch somewhere. – Brad Larson Nov 10 '17 at 18:10
  • My input images are 128x128 and are scaled like this: 1./255, how should I enter this into the conversion code? And what do you mean with the mapping table for the numerical outputs? Is that the same as the class labels or? – Thijs van der Heijden Nov 10 '17 at 20:27
  • I wrote a blog post that goes into a bit more detail: http://machinethink.net/blog/help-core-ml-gives-wrong-output/ – Matthijs Hollemans Nov 11 '17 at 12:45

0 Answers0