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

Use tf.contrib.image.rotate in place of lambda:tf.py_func(random_rotate_image, [image], tf.uint8) #789

Open
vivekaditya opened this issue Jun 12, 2018 · 12 comments

Comments

@vivekaditya
Copy link

vivekaditya commented Jun 12, 2018

In the graph we are using
lambda:tf.py_func(random_rotate_image, [image], tf.uint8)
inside
create_input_pipeline
This causes problem while using tensor flow serving as python layers are not supported on TensorFlow serving.

Can we convert this to a TensorFlow operations ? Something like tf.contrib.image.rotate ? What could be the downside ? @davidsandberg @xolott, @Cecilwang, @scotthong Please comment.

This issue would also get resolved.

@quhongjun
Copy link

Having the same issue, waiting for a solution.

@FortiLeiZhang
Copy link

I think you can remove this line and re-train the model. Because based on the training parameters that the author @davidsandberg provided in this train example, '--random_rotate' is not set and thus this function will not be used in training.

@xolott
Copy link

xolott commented Jul 18, 2018

We don't have this issue with facenet in TF-Serving. We used it for 4 months without a problem.

@FortiLeiZhang
Copy link

what I did is: download the pre-trained model, export it to TF serverable using the code provided in this thread, and got the same error as described here by @Dr-Champ

@xolott
Copy link

xolott commented Jul 18, 2018

I used the SavedModelBuilder to generate the servable model. Load the model, get the 3 tensor (input, embeddings y phase_train), create the prediction_signature. Then add this signature and the meta_graph (tag_constants.SERVING) to the builder... The just save the servable model.

I don't have the code anymore, but this script took me no more than 30 lines of code.

@FortiLeiZhang
Copy link

Hi, @xolott
Thanks for your reply.

I found your script which you used for generate the servable, but still got the same issue. However, I also found an older version '20170512-110547' instead of the latest one '20180402-114759' on the page . The old one can be run on TF-Serving.

Anyway, I will still remove the 'py_func' and re-train the model. will let you know once i have done.

@tamaghnadutta
Copy link

Hi @FortiLeiZhang,

I was able to create the servable. Then when I was trying to invoke the tensorfow_model_server to specify the port, it threw me the 'PyFunc' error. I then went back and commented the 'tf.py_func()' line in facenet.py, created the servable again and ran the model server. It still threw me the 'PyFunc' error which was quite weird.

You mentioned that you tried an older version, viz. '20170512-110547' and there was no problem in serving the model. But, using '20180402-114759' throws this 'PyFunc' error. Now, it got me thinking, is it because the older version doesn't have py_func() used anywhere (while creating the pre-trained .pb file) but the latest version does? That's why even if we remove the py_func() line from facenet.py it still throws this error?

Can you kindly tell me where you found the '20170512-110547' file? I don't seem to be able to find it on the page.

@FortiLeiZhang
Copy link

Hi, @tamaghnadutta

In the facenet package, you can find in "download_and_extract.py". Read the code, then you will get the download link.

@FortiLeiZhang
Copy link

a quick update. I removed all the lines

            image = tf.cond(get_control_flag(control[0], RANDOM_ROTATE),
                            lambda:tf.py_func(random_rotate_image, [image], tf.uint8), 
                            lambda:tf.identity(image))

and re-train the model. The first checkpoint is serverable without the py_func issue.

@amirmgh1375
Copy link

amirmgh1375 commented Nov 11, 2019

@FortiLeiZhang can you share your retrained weights without py_func preprocessing layer please ?

@zh3389
Copy link

zh3389 commented Dec 7, 2020

a quick update. I removed all the lines

            image = tf.cond(get_control_flag(control[0], RANDOM_ROTATE),
                            lambda:tf.py_func(random_rotate_image, [image], tf.uint8), 
                            lambda:tf.identity(image))

and re-train the model. The first checkpoint is serverable without the py_func issue.

Hello, where is this update? I can't find it

@zh3389
Copy link

zh3389 commented Dec 7, 2020

a quick update. I removed all the lines

            image = tf.cond(get_control_flag(control[0], RANDOM_ROTATE),
                            lambda:tf.py_func(random_rotate_image, [image], tf.uint8), 
                            lambda:tf.identity(image))

and re-train the model. The first checkpoint is serverable without the py_func issue.

I delete py_ func, and use training to copy the weight, the problem has been solved, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants