Closed wowliuzj closed 6 years ago
I'm using inception model from official Tensorflow repo. If you clone it and build Android example, you'll have tensorflow_inception_graph.pb file right here in assets folder. It's not in the repository though, I assume it gets downloaded during the build, so you can explore build tools to check where it's coming from.
When you use your own model (especially if it's not inception but mobilenet or something else), you should also make sure to set correct variables in Calssifier.cs:
private static int INPUT_SIZE = 224;
private static int IMAGE_MEAN = 117;
private static float IMAGE_STD = 1;
private static string INPUT_NAME = "input";
private static string OUTPUT_NAME = "output";
Thank you for reply! It's still now working. I use the pb file in repo to predict in my python project, and it says KeyError: "The name 'import/input' refers to an Operation not in the graph.". Don't know if the model format is not compatible or something.
That error means that input name in this variable private static string INPUT_NAME = "input";
isn't the same as in the trained model. You can try "Mul"
as the other common name for input layer. If it still doesn't work, you'll have to explore your model closely to find out the name of its input layer, which is out of scope of my expertise, I'm afraid.
I tried several ways. First, I retrained the model which you used in project, and it predicts fine under python and c#, but in mobile, it always fails with "Object reference not set to an instance of an object". Then I tried using Inception V3 model which from "tensorflow-for-poets", but fails with the same issue. I tried to adjust input name and output name, but has no effect.
NullReferenceException might be caused by my code, if you can attach a model for me to reproduce this issue, I'll check why it's happening.
Thank you so much! Here is the model model.zip
and the exception happens in this code runner.AddInput(graph[INPUT_NAME][0], tensor).Fetch(graph[OUTPUT_NAME][0]);
I retrained the model from "tensorflow-for-poets", using MobileNet with 224 width and height, if this helps.
Ok, I'll let you know what I found out
sorry, forget to tell you, the model input name is input and output name is final_result private static string INPUT_NAME = "input"; private static string OUTPUT_NAME = "final_result"
It seems like problem might be because of mismatch between Tensorflow version you used to train this model and Tensorflow version that Unity plugin uses. What TF version you have? You can probably just do pip list
in a terminal to see it.
I used the version 1.6, should I down-grade to train the model? tensorflow (1.6.0) tensorflow-gpu (1.6.0)
Yes, it seems like this is the problem. Please downgrade TF to 1.4 and check model trained with that version. This is part of the exception I see in adb, which gives you a hint there at the end:
InvalidArgumentError (see above for traceback): NodeDef mentions attr 'dilations' not in Op<name=Conv2D; ... (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).
OK, I will try it and will let you know.
Still not working, I tried 1.4, 1.2 and 1.0
Could you attach your model trained with 1.4?
Really thank you for your help! I guess it was environment issue. I start a new docker container with tensorflow 1.4.0, and now it finally works on my cellphone. Without your help, I can't do it. Thank you so much!
Ok great, glad I could help! I'm gonna close this issue now.
Hi, could you tell me what model do you use in your example? I replace the bytes file with pb file export from my model, but it doesn't work. Could you give me your model file or checkpoint? Thanks so much!