Converter.py 872 B

12345678910111213141516171819
  1. import coremltools
  2. output_labels = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
  3. scale = 1 / 255.
  4. coreml_model = coremltools.converters.keras.convert('./mnist_cnn_keras.h5',
  5. input_names='image',
  6. image_input_names='image',
  7. output_names='output',
  8. class_labels=output_labels,
  9. image_scale=scale)
  10. coreml_model.author = 'sky'
  11. coreml_model.license = 'MIT'
  12. coreml_model.short_description = 'Model to classify hand written digit'
  13. coreml_model.input_description['image'] = 'Grayscale image of hand written digit'
  14. coreml_model.output_description['output'] = 'Predicted digit'
  15. coreml_model.save('mnistCNN.mlmodel')