frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

facenet convert failed

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

Comments

  • 4 Comments sorted by Votes Date Added
  • @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.

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

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

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

Sign In or Register to comment.