Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.

facenet convert failed

idata
Employee
748 Views

Hi, i want to convert a facenet graph file from original facenet whose link is facenet VGGFace2 20180402-114759 using script below ncappzoo/blob/master/tensorflow/facenet/convert_facenet.py but failed.

 

Here is what i executed.

 

python3 convert_facenet.py model_base=model-20180402-114759.ckpt-275

 

and the error log is

 

/usr/lib/python3/dist-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`. from ._conv import register_converters as _register_converters model base file name is: model-20180402-114759.ckpt-275 Restoring model-20180402-114759.ckpt-275 Traceback (most recent call last): File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1322, in _do_call return fn(*args) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1307, in _run_fn options, feed_dict, fetch_list, target_list, run_metadata) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1409, in _call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [128] rhs shape= [512] [[Node: save/Assign_20 = Assign[T=DT_FLOAT, _class=["loc:@InceptionResnetV1/Bottleneck/BatchNorm/moving_variance"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](InceptionResnetV1/Bottleneck/BatchNorm/moving_variance, save/RestoreV2:20)]] During handling of the above exception, another exception occurred: Traceback (most recent call last): File "convert_facenet.py", line 99, in <module> sys.exit(main()) File "convert_facenet.py", line 76, in main saver.restore(sess, model_base_file_name) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 1802, in restore {self.saver_def.filename_tensor_name: save_path}) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 900, in run run_metadata_ptr) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1135, in _run feed_dict_tensor, options, run_metadata) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1316, in _do_run run_metadata) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1335, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [128] rhs shape= [512] [[Node: save/Assign_20 = Assign[T=DT_FLOAT, _class=["loc:@InceptionResnetV1/Bottleneck/BatchNorm/moving_variance"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](InceptionResnetV1/Bottleneck/BatchNorm/moving_variance, save/RestoreV2:20)]] Caused by op 'save/Assign_20', defined at: File "convert_facenet.py", line 99, in <module> sys.exit(main()) File "convert_facenet.py", line 64, in main saver = tf.train.Saver(tf.global_variables()) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 1338, in __init__ self.build() File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 1347, in build self._build(self._filename, build_save=True, build_restore=True) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 1384, in _build build_save=build_save, build_restore=build_restore) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 835, in _build_internal restore_sequentially, reshape) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 494, in _AddRestoreOps assign_ops.append(saveable.restore(saveable_tensors, shapes)) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/training/saver.py", line 185, in restore self.op.get_shape().is_fully_defined()) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/ops/state_ops.py", line 283, in assign validate_shape=validate_shape) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/ops/gen_state_ops.py", line 60, in assign use_locking=use_locking, name=name) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op op_def=op_def) File "/home/pi/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1718, in __init__ self._traceback = self._graph._extract_stack() # pylint: disable=protected-access InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [128] rhs shape= [512] [[Node: save/Assign_20 = Assign[T=DT_FLOAT, _class=["loc:@InceptionResnetV1/Bottleneck/BatchNorm/moving_variance"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](InceptionResnetV1/Bottleneck/BatchNorm/moving_variance, save/RestoreV2:20)]]

 

So the error was caused by shape mismatch by 128 VS 512

0 Kudos
5 Replies
idata
Employee
471 Views

@shartoo So it looks like in the last update, the new model was changed from using 128 dimension embeddings to 512 dimension embeddings. If you have the facenet ncappzoo project, edit the inception_resnet_v1.py script in your facenet ncappzoo folder and change line 131 from:

 

bottleneck_layer_size=128, weight_decay=0.0, reuse=None):

 

to

 

bottleneck_layer_size=512, weight_decay=0.0, reuse=None):

 

and then change line 154 from:

 

bottleneck_layer_size=128,

 

to

 

bottleneck_layer_size=512,

 

Then try running the convert_facenet.py script again. Let me know if this works for you.

0 Kudos
idata
Employee
471 Views

Ok thank you,i'll try it later and reply you.

0 Kudos
idata
Employee
471 Views

Ok thank you,i'll try it later and reply you.

0 Kudos
idata
Employee
471 Views

Ok thank you,i'll try it later and reply you.

0 Kudos
idata
Employee
471 Views

Hi , so I tried the suggestion above, changing the two lines and running convert_facenet.py and here's what I get… there are remnants of 128 …

 

python3 convert_facenet.py model_base=facenet_celeb

 

model base file name is: facenet_celeb

 

2018-12-28 18:24:43.116767: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA

 

Restoring facenet_celeb

 

Traceback (most recent call last):

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1322, in _do_call

 

return fn(*args)

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1307, in _run_fn

 

options, feed_dict, fetch_list, target_list, run_metadata)

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1409, in _call_tf_sessionrun

 

run_metadata)

 

tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [1,1,896,512] rhs shape= [1,1,896,128]

 

[[Node: save/Assign_317 = Assign[T=DT_FLOAT, _class=["loc:@InceptionResnetV1/Repeat_1/block17_5/Branch_1/Conv2d_0a_1x1/weights"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](InceptionResnetV1/Repeat_1/block17_5/Branch_1/Conv2d_0a_1x1/weights, save/RestoreV2:317)]]

 

During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

 

File "convert_facenet.py", line 99, in

 

sys.exit(main())

 

File "convert_facenet.py", line 76, in main

 

saver.restore(sess, model_base_file_name)

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 1752, in restore

 

{self.saver_def.filename_tensor_name: save_path})

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 900, in run

 

run_metadata_ptr)

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1135, in _run

 

feed_dict_tensor, options, run_metadata)

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1316, in _do_run

 

run_metadata)

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1335, in _do_call

 

raise type(e)(node_def, op, message)

 

tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [1,1,896,512] rhs shape= [1,1,896,128]

 

[[Node: save/Assign_317 = Assign[T=DT_FLOAT, _class=["loc:@InceptionResnetV1/Repeat_1/block17_5/Branch_1/Conv2d_0a_1x1/weights"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](InceptionResnetV1/Repeat_1/block17_5/Branch_1/Conv2d_0a_1x1/weights, save/RestoreV2:317)]]

 

Caused by op 'save/Assign_317', defined at:

 

File "convert_facenet.py", line 99, in

 

sys.exit(main())

 

File "convert_facenet.py", line 64, in main

 

saver = tf.train.Saver(tf.global_variables())

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 1284, in init

 

self.build()

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 1296, in build

 

self._build(self._filename, build_save=True, build_restore=True)

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 1333, in _build

 

build_save=build_save, build_restore=build_restore)

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 781, in _build_internal

 

restore_sequentially, reshape)

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 422, in _AddRestoreOps

 

assign_ops.append(saveable.restore(saveable_tensors, shapes))

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 113, in restore

 

self.op.get_shape().is_fully_defined())

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/state_ops.py", line 219, in assign

 

validate_shape=validate_shape)

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_state_ops.py", line 60, in assign

 

use_locking=use_locking, name=name)

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper

 

op_def=op_def)

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 3414, in create_op

 

op_def=op_def)

 

File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1740, in init

 

self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

 

InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [1,1,896,512] rhs shape= [1,1,896,128]

 

[[Node: save/Assign_317 = Assign[T=DT_FLOAT, _class=["loc:@InceptionResnetV1/Repeat_1/block17_5/Branch_1/Conv2d_0a_1x1/weights"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](InceptionResnetV1/Repeat_1/block17_5/Branch_1/Conv2d_0a_1x1/weights, save/RestoreV2:317)]]
0 Kudos
Reply