apple / coremltools

Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.
https://coremltools.readme.io
BSD 3-Clause "New" or "Revised" License
4.4k stars 634 forks source link

Conversion of Tensorflow 1.x object detection model to coreml using coremltools #1138

Open rajeshm71 opened 3 years ago

rajeshm71 commented 3 years ago

🐞Describe the bug

Hello , I have trained object detection model using tensorflow object detection api 1. I have exported the model in .pb format . I want to use it in the ios so i tried converting it to .mlmodel . But i am getting some errors like 'Input max_boxes must be const at compile time'. I have given details below. I am using SSD-MobileNetV1 model

Trace

Running TensorFlow Graph Passes: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 7/7 [00:01<00:00, 4.36 passes/s] Converting Frontend ==> MIL Ops: 45%|β–ˆβ–ˆβ–ˆβ–ˆβ– | 323/719 [00:00<00:00, 3226.29 ops/s] Converting Frontend ==> MIL Ops: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 9/9 [00:00<00:00, 4198.97 ops/s]

Converting Frontend ==> MIL Ops: 0%| | 0/30 [00:00<?, ? ops/s]WARNING:root:Input ls elem type unknown. Override with <class 'coremltools.converters.mil.mil.types.type_tensor.tensor..tensor'> WARNING:root:Input ls elem type unknown. Override with <class 'coremltools.converters.mil.mil.types.type_tensor.tensor..tensor'> Converting Frontend ==> MIL Ops: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 30/30 [00:00<00:00, 1523.76 ops/s]

Converting Frontend ==> MIL Ops: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 9/9 [00:00<00:00, 6113.16 ops/s]

Converting Frontend ==> MIL Ops: 0%| | 0/30 [00:00<?, ? ops/s]WARNING:root:Input ls elem type unknown. Override with <class 'coremltools.converters.mil.mil.types.type_tensor.tensor..tensor'> WARNING:root:Input ls elem type unknown. Override with <class 'coremltools.converters.mil.mil.types.type_tensor.tensor..tensor'> Converting Frontend ==> MIL Ops: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 30/30 [00:00<00:00, 1438.46 ops/s] Converting Frontend ==> MIL Ops: 93%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž| 666/719 [00:01<00:00, 294.71 ops/s] Converting Frontend ==> MIL Ops: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 9/9 [00:00<00:00, 1378.75 ops/s]

Converting Frontend ==> MIL Ops: 0%| | 0/381 [00:00<?, ? ops/s] Converting Frontend ==> MIL Ops: 28%|β–ˆβ–ˆβ–Š | 108/381 [00:00<00:00, 1076.34 ops/s] Converting Frontend ==> MIL Ops: 47%|β–ˆβ–ˆβ–ˆβ–ˆβ–‹ | 178/381 [00:00<00:00, 507.98 ops/s] Converting Frontend ==> MIL Ops: 93%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž| 666/719 [00:01<00:00, 351.75 ops/s]

ValueError Traceback (most recent call last)

in () 2 model = "inference_graph/frozen_inference_graph.pb" 3 outputs=['detection_classes:0','detection_scores:0','detection_boxes:0','num_detections:0'] ----> 4 coremltools.convert(model,outputs=outputs) 22 frames /usr/local/lib/python3.7/dist-packages/coremltools/converters/mil/mil/input_type.py in validate_inputs(self, op_name, op_type, candidate_kvs) 112 msg = msg_prefix + \ 113 'Input {} must be const at compile time' --> 114 raise ValueError(msg.format(name), name, var.name) 115 116 if not isinstance(var, InternalVar) and \ ValueError: ('Op "non_maximum_suppression_8" (op_type: non_maximum_suppression) Input max_boxes must be const at compile time', 'max_boxes', 'Postprocessor/BatchMultiClassNonMaxSuppression/map/while/MultiClassNonMaxSuppression/Minimum') ## To Reproduce import coremltools model = "inference_graph/frozen_inference_graph.pb" outputs=['detection_classes:0','detection_scores:0','detection_boxes:0','num_detections:0'] coremltools.convert(model,outputs=outputs) # Paste code snippet here ``` - If applicable, please attach the source model please find source model below : [https://drive.google.com/file/d/114dq7RPQrDi-PX2qzREuPPj9ilblm4z3/view?usp=sharing](url) ## System environment (please complete the following information): - coremltools version (e.g., 3.0b5): ](url) 4.1 - OS (e.g., MacOS, Linux): Windows - macOS version (if applicable): NA - XCode version (if applicable): NA - How you install python (anaconda, virtualenv, system):sytem - python version (e.g. 3.7): 3.7 - any other relevant information: tensorflow version 1.15
Jeetendra-Shakya commented 2 years ago

Is this problem fixed - i am still having similar issue?