fizyr / keras-maskrcnn

Keras implementation of MaskRCNN object detection.
Apache License 2.0
406 stars 131 forks source link

Convert resnet50_coco_v0.2.0.h5 to tensorflow serving #107

Open ajinkya933 opened 4 years ago

ajinkya933 commented 4 years ago

@hgaiser

I am referring to MatterPort Mask_RCNN to convert (resnet50_coco_v0.2.0.h5) file to tf serving. Detailed steps to convert h5 to serving can be found here: https://github.com/bendangnuksung/mrcnn_serving_ready. I am using this git repo to convert my Keras model (resnet50_coco_v0.2.0.h5) to tensorflow serving.

From the above lined repo when I run

python3 main.py

The error I get is:

ValueError: Layer #2 (named "conv1") expects 2 weight(s), but the saved weights have 1 element(s).

complete error stack trace:

FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/ajinkya/anaconda3/envs/tensorflowGPU_p36/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/ajinkya/anaconda3/envs/tensorflowGPU_p36/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/ajinkya/anaconda3/envs/tensorflowGPU_p36/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/ajinkya/anaconda3/envs/tensorflowGPU_p36/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/ajinkya/anaconda3/envs/tensorflowGPU_p36/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
/home/ajinkya/anaconda3/envs/tensorflowGPU_p36/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/ajinkya/anaconda3/envs/tensorflowGPU_p36/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/ajinkya/anaconda3/envs/tensorflowGPU_p36/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/ajinkya/anaconda3/envs/tensorflowGPU_p36/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/ajinkya/anaconda3/envs/tensorflowGPU_p36/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/ajinkya/anaconda3/envs/tensorflowGPU_p36/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
Using TensorFlow backend.
WARNING:tensorflow:From main.py:10: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

2020-05-14 10:40:17.583273: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-05-14 10:40:17.623709: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3193675000 Hz
2020-05-14 10:40:17.624878: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x562e8e163e60 executing computations on platform Host. Devices:
2020-05-14 10:40:17.624924: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
WARNING:tensorflow:From /home/ajinkya/.local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:4070: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.

WARNING:tensorflow:From /home/ajinkya/Downloads/mrcnn_serving_ready-master/model.py:337: The name tf.log is deprecated. Please use tf.math.log instead.

WARNING:tensorflow:From /home/ajinkya/Downloads/mrcnn_serving_ready-master/model.py:395: add_dispatch_support.<locals>.wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0, which has the same broadcast rule as np.where
WARNING:tensorflow:From /home/ajinkya/Downloads/mrcnn_serving_ready-master/model.py:419: calling crop_and_resize_v1 (from tensorflow.python.ops.image_ops_impl) with box_ind is deprecated and will be removed in a future version.
Instructions for updating:
box_ind is deprecated, use box_indices instead
WARNING:tensorflow:From /home/ajinkya/Downloads/mrcnn_serving_ready-master/model.py:719: The name tf.sets.set_intersection is deprecated. Please use tf.sets.intersection instead.

WARNING:tensorflow:From /home/ajinkya/Downloads/mrcnn_serving_ready-master/model.py:721: The name tf.sparse_tensor_to_dense is deprecated. Please use tf.sparse.to_dense instead.

WARNING:tensorflow:From /home/ajinkya/Downloads/mrcnn_serving_ready-master/model.py:771: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.cast` instead.
Traceback (most recent call last):
  File "main.py", line 108, in <module>
    model.load_weights(H5_WEIGHT_PATH, by_name=True)
  File "/home/ajinkya/Downloads/mrcnn_serving_ready-master/model.py", line 2131, in load_weights
    saving.load_weights_from_hdf5_group_by_name(f, layers)
  File "/home/ajinkya/.local/lib/python3.6/site-packages/keras/engine/saving.py", line 1309, in load_weights_from_hdf5_group_by_name
    ' element(s).')
ValueError: Layer #2 (named "conv1") expects 2 weight(s), but the saved weights have 1 element(s).

What is happening here ? any thoughts to get serving model from this script?

The main.py script seems to be working fine for mask_rcnn_coco.h5 file from https://github.com/matterport/Mask_RCNN/releases