Problem after converting keras model into Tensorflow pb - 将keras模型转换为Tensorflow pb后的问题

I'm using keras 2.1.* with tensorflow 1.13.* backend. I save my model during training with .h5 format and after that I convert it into protobuf (.pb) model. Everything looks good during converting process, but the result of tensorflow model is a bit weird. It shows a little bit different results. Also I'm loading keras model with not compiled mode. Something like this.

import keras
keras.models.load_model('model.h5', compile=False)

Solution 1

Most probable the problem is related to running environment. There are some variables which are being computed in training phase for future use. If you don't change to test phase, it will use current values. For example dropout and batch normalization. If you use it in training mode, then for mean and variance it will use current values, but in test time it will use moving_mean and moving_variance. That's why you should call 

import keras.backend as K
k.set_learning_phase(0) # 0 testing, 1 training mode

aipool discussion: https://ai-pool.com/d/problem_after_converting_keras_model_into_tensorflow_pb

猜你喜欢

转载自www.cnblogs.com/hazarapet/p/10754132.html