How to predict input image using trained model in Keras?

前端 未结 5 1388
刺人心
刺人心 2020-12-04 06:40

I\'m only beginning with keras and machine learning in general.

I trained a model to classify images from 2 classes and saved it using model.save(). Her

5条回答
  •  醉话见心
    2020-12-04 07:32

    That's because you're getting the numeric value associated with the class. For example if you have two classes cats and dogs, Keras will associate them numeric values 0 and 1. To get the mapping between your classes and their associated numeric value, you can use

    >>> classes = train_generator.class_indices    
    >>> print(classes)
        {'cats': 0, 'dogs': 1}
    

    Now you know the mapping between your classes and indices. So now what you can do is

    if classes[0][0] == 1: prediction = 'dog' else: prediction = 'cat'

提交回复
热议问题