Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keras Exported Model shows very low accuracy in Tensorflow Serving #7848

Open
vijayg78 opened this Issue Sep 8, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@vijayg78
Copy link

commented Sep 8, 2017

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

This comment has been minimized.

Copy link

commented Dec 7, 2017

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.

@stale stale bot added the stale label Dec 7, 2017

@caiya55

This comment has been minimized.

Copy link

commented Apr 13, 2018

I have the same problems, still looking for answers

@caiya55

This comment has been minimized.

Copy link

commented Apr 13, 2018

do you find the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.