Load keras model h5 unknown metrics

后端 未结 3 940
陌清茗
陌清茗 2021-01-26 02:59

I have trained a keras CNN monitoring the metrics as follow:

METRICS = [
  TruePositives(name=\'tp\'),
  FalsePositives(name=\'fp\'),
  TrueNegatives(name=\'tn\'         


        
3条回答
  •  抹茶落季
    2021-01-26 03:39

    It looks like you are playing with a tensorflow tutorial. I also used these exact metrics and had the same problem. What worked for me was to load the model with compile = False and then compile it with the custom metrics. Then you should be able to use model.predict(....) as expected.

    import keras
    
    model = keras.models.load_model('model.h5', compile = False)
    
    METRICS = [
          keras.metrics.TruePositives(name='tp'),
          keras.metrics.FalsePositives(name='fp'),
          keras.metrics.TrueNegatives(name='tn'),
          keras.metrics.FalseNegatives(name='fn'), 
          keras.metrics.BinaryAccuracy(name='accuracy'),
          keras.metrics.Precision(name='precision'),
          keras.metrics.Recall(name='recall'),
          keras.metrics.AUC(name='auc'),
    ]
    
    model.compile(optimizer = keras.optimizers.Adam(learning_rate=1e-4),
                  loss = 'binary_crossentropy',
                  metrics = METRICS
                 )
    

提交回复
热议问题