keras-team/keras

Keras Exported Model shows very low accuracy in Tensorflow Serving

vijayg78 opened this issue · 4 comments

Hi,
I have a trained xception model with keras & tensorflow for 8 classes. With the validation set it already gives 95% accuracy.

I exported the model with the following code.


import sys
import os
from keras.layers import *
from keras.optimizers import *
from keras.applications import *
from keras.models import Model
import time
from keras.applications.xception import Xception
from keras.preprocessing import image
from keras.applications.xception import preprocess_input, decode_predictions
from keras.models import Model
import numpy 

from tensorflow.python.saved_model import builder as saved_model_builder
from tensorflow.python.saved_model import utils
from tensorflow.python.saved_model import tag_constants, signature_constants
from tensorflow.python.saved_model.signature_def_utils_impl import build_signature_def, predict_signature_def
from tensorflow.contrib.session_bundle import exporter
from keras import backend as K

nb_classes = 8 
img_width, img_height = 299, 299 
export_path = './export/1/'
TF_WEIGHTS_PATH = './top_model_weights-00-0.95.h5'


if __name__ == '__main__':
	K.set_learning_phase(0)
	new_model = Xception(input_shape=(299, 299, 3), weights=None, include_top=True,classes=3)
        new_model.load_weights(TF_WEIGHTS_PATH)
	builder = saved_model_builder.SavedModelBuilder(export_path)

	signature = predict_signature_def(inputs={'images': new_model.input},
                                  outputs={'scores': new_model.output})

	with K.get_session() as sess:
    		builder.add_meta_graph_and_variables(sess=sess,
                                         tags=[tag_constants.SERVING],
                                         signature_def_map={'predict': signature})
    		builder.save()
	k.clear_session()

for a test set of 5 images if I test with the keras test script, i get high accuracy 0f > 0.9. But when this model is deployed to serving, i get accuracy of 0.4 - 0.5. Look like a issue with dropout from the behaviour. While training i had used dropout of 0.5.

Any idea what might be issue? Because our TF version is 1.0.0 and Serving 1.0.0 i have not tested it with the latest TF run time.

Best Regards,
Vijay

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.

I have the same problems, still looking for answers

do you find the solution?

I also have the same problem