tensorflow-hangul-recognition icon indicating copy to clipboard operation
tensorflow-hangul-recognition copied to clipboard

Execution error

Open songkovong opened this issue 4 years ago • 5 comments

When I train the model and try the model with 'classify-hangul.py', I get the following error:

ValueError: Cannot feed value of shape (4096,) for Tensor 'hangul-model / input: 0', which has shape '(?, 4096)'.

If I ignore this problem and run it with 'optimized_hangul_tensorflow.pb' in the android asset folder, I get the following error:

java.lang.RuntimeException: Error loading pre-trained model. Caused by: java.lang.RuntimeException: Failed to load model from 'new_hangul.pb' Caused by: java.io.IOException: Not a valid TensorFlow Graph serialization: NodeDef mentions attr 'explicit_paddings' not in Op<name=Conv2D; signature=input:T, filter:T -> output:T; attr=T:type,allowed=[DT_HALF, DT_BFLOAT16, DT_FLOAT, DT_DOUBLE]; attr=strides:list(int); attr=use_cudnn_on_gpu:bool,default=true; attr=padding:string,allowed=["SAME", "VALID"]; attr=data_format:string,default="NHWC",allowed=["NHWC", "NCHW"]; attr=dilations:list(int),default=[1, 1, 1, 1]>; NodeDef: {{node Conv2D}}. (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).

How can I solve this problem?

songkovong avatar Mar 13 '20 06:03 songkovong

For the first issue, I think something with API changed that altered the shape of the input image. I will push an update. But seems like all you need to do is change the reshape line (line 26) to image = tf.reshape(image, (1, 64*64)). Thanks for bringing this up.

For the second issue, I am not too sure, I was able to build and run the app okay with the latest Android Studio and supported gradle version (5.6.4). Try seeing if you have the latest versions. I will also push a commit updating the version in the gradle build file.

pvaneck avatar Mar 14 '20 01:03 pvaneck

Thanks for the answer. The first problem was solved. You think the second one is a version problem? I'll finish the other work and try.

songkovong avatar Mar 16 '20 02:03 songkovong

@pvaneck I'm sorry to ask you same problem.

캡처

I changed gradle version like this. But I have the same problem. In my opinion, maybe it is a pb file loading problem. Is there any other solution? I'll wait your answer :)

songkovong avatar Mar 17 '20 11:03 songkovong

Sorry, I was using the optimized_hangul_tensorflow.pb file already contained in the Android folder (https://github.com/IBM/tensorflow-hangul-recognition/blob/master/hangul-tensordroid/app/src/main/assets/optimized_hangul_tensorflow.pb) which does work since it was trained using an older version of TF.

I did get the same error when trying to use the model just trained with a fresh install. Seems like it has to do with a version mismatch between the Python TensorFlow and the Android TensorFlow AAR file. Version 1.15.2 of TF is used while the highest version available for the TensorFlow AAR is 1.13.1 for the TensorFlow AAR.

My suggestion is to use the 1.13.1 version of TF for training and saving. Sorry about that! I went ahead and pinned the TF version for now. I hope to soon update this project to use TF 2+ and TF Lite for the Android portion.

pvaneck avatar Mar 17 '20 19:03 pvaneck

Thank you very much for the answer. My tensorflow version is 1.15.2, but there is no way to apply this version. I should try again with 1.13.1 :)

songkovong avatar Mar 22 '20 08:03 songkovong