I'm trying to convert MTCNN model ( https://github.com/blaueck/tf-mtcnn/blob/master/mtcnn.pb ) from .pb file to .tflite and get problems with input and output shapes. Original input shape is ?x?x3 and output shape is Nx4 where N is number of detected faces.
I've tried to set the input shape to [None, None, 3] and get error "None is only supported in the 1st dimension" . Then I've set this to [500, 500, 3] and get other error "Check failed: batch == 1 (500 vs. 1)" . Then I've set the shape to [1, 500, 500, 3] and get "ValueError: The shape of tensor 'input' cannot be changed from (?, ?, 3) to [1, 500, 500, 3]. Shapes must be equal rank, but are 3 and 4" .
UPD: I've converted original caffe model from input shape [None, None, 3] to [500, 500, 3] but this does not solve the problem.
I want to convert this model to .tflite format. Can I actually do this?
step by step toturial:
use official dr.zhang mtcnn repo that implemented by caffe: https://github.com/kpzhang93/MTCNN_face_detection_alignment
after that converter it to tensorflow model from the below link: https://github.com/ethereon/caffe-tensorflow
(even though you can pre-converted models such as the below repo:) https://github.com/AITTSMD/MTCNN-Tensorflow https://github.com/wangbm/MTCNN-Tensorflow (but i strongly recommend you to do it yourself)
finally, you are possible to convert tf model to tf lite from google documentation: https://www.tensorflow.org/lite/convert
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_dataset
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = tf.uint8 # or tf.int8
converter.inference_output_type = tf.uint8 # or tf.int8
tflite_model = converter.convert()
with open('8bit_quantized_model_in_.tflite', 'wb') as f:
f.write(tflite_model)
def representative_dataset():
for i in range(<>):
testimage = cv2.imread('path')
yield [testimage.astype(np.float32)]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.