facenet icon indicating copy to clipboard operation
facenet copied to clipboard

Workaround for tensorflow 2.0

Open rizkyputranto opened this issue 5 years ago • 11 comments

Is there any workaround for tensorflow 2.0?

rizkyputranto avatar Nov 25 '19 09:11 rizkyputranto

+1

ichippa96 avatar Dec 03 '19 08:12 ichippa96

+1

xfchangwei avatar Mar 30 '20 06:03 xfchangwei

I found the problem to be with loading the facenet model, did you find a workaround? error message ValueError: Node 'gradients/InceptionResnetV1/Bottleneck/BatchNorm/cond/FusedBatchNorm_1_grad/FusedBatchNormGrad' has an _output_shapes attribute inconsistent with the GraphDef for output #3: Dimension 0 in both shapes must be equal, but are 0 and 512. Shapes are [0] and [512].

Alloooshe avatar Jul 11 '20 17:07 Alloooshe

update: you can simply run the code for inference on tf2 using import tensorflow.compat.v1 as tf tf.disable_v2_behavior() and the frozen model provided.

Alloooshe avatar Jul 14 '20 10:07 Alloooshe

@Alloooshe Hi, could you share your solution with more details?same issue with you.

github2016-yuan avatar Jul 31 '20 07:07 github2016-yuan

@github2016-yuan just use the frozen model pb, if you don't have it then I didn't find a work around

Alloooshe avatar Jul 31 '20 21:07 Alloooshe

I solved it by using the pb files instead of ckpt file in tf2.x (I am using tf2.2.0) Here is my code and hope it helps someone who has the same issue.

with tf.gfile.FastGFile("20180402-114759.pb", 'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) _ = tf.import_graph_def(graph_def, name='')

images_placeholder = tf.get_default_graph().get_tensor_by_name("input:0") embeddings = tf.get_default_graph().get_tensor_by_name("embeddings:0") phase_train_placeholder = tf.get_default_graph().get_tensor_by_name("phase_train:0")

github2016-yuan avatar Aug 01 '20 06:08 github2016-yuan

Still facing the same issue got error like below

results = c_api.TF_GraphImportGraphDefWithResults( tensorflow.python.framework.errors_impl.InvalidArgumentError: Node 'gradients/InceptionResnetV1/Bottleneck/BatchNorm/cond/FusedBatchNorm_1_grad/FusedBatchNormGrad' has an _output_shapes attribute inconsistent with the GraphDef for output #3: Dimension 0 in both shapes must be equal, but are 0 and 512. Shapes are [0] and [512].

rohitdoddapani avatar Apr 22 '22 09:04 rohitdoddapani

@github2016-yuan Which Python file should be modified with the code you told us?

thoongee avatar Jul 20 '22 11:07 thoongee

Hi, which python file and on wich location should we update?

trinanda avatar Jul 22 '22 07:07 trinanda

im having a similar problem to @rohitdoddapani, trying to load in my .meta file and I get error

ValueError: Node 'gradients/UNet/conv0_up/batch_normalization_3/FusedBatchNorm_grad/FusedBatchNormGrad' has an _output_shapes attribute inconsistent with the GraphDef for output # 3: Dimension 0 in both shapes must be equal, but are 0 and 16. Shapes are [0] and [16].

sayloren avatar Mar 01 '24 20:03 sayloren