Open stepanzalis opened 1 year ago
I am able to reproduce the error. Thanks for sharing the model to easily reproduce the issue.
This is clearly a bug, that happens in the const_deduplication
pass while loading the mlpackge model into the internal model class. We will look into it to find the root cause and fix.
Meanwhile, can you try one thing. Re-converting the model from TF but without using the classifier mode, so that the outputs are just multi arrays. And then verify if the ct.optimize.coreml
APIs still dont work. This will rule out if it's a classifier related bug.
Thanks for the reply. When converting model from TF without classifier (like example below):
mlModel = ct.convert(
model,
inputs=[image_input],
# classifier_config=classifier_config,
minimum_deployment_target=ct.target.iOS16,
)
It doesn't produce any error while converting to 8 bits and mlpackage model looks fine, so seems like it's related to classifier_config
param.
Hi @stepanzalis, I successfully resolved the shape not applicable to ListVar
error, but I encountered a new error
File "/Volumes/data/Software/Mine/coremltools-github_issue-1937/coremltools/converters/mil/mil/passes/defs/optimize_repeat_ops.py", line 800, in _add_output_sinks
out_sink = mb.identity(x=out_var)
File "/Volumes/data/Software/Mine/coremltools-github_issue-1937/coremltools/converters/mil/mil/ops/registry.py", line 183, in add_op
return cls._add_op(op_cls_to_add, **kwargs)
File "/Volumes/data/Software/Mine/coremltools-github_issue-1937/coremltools/converters/mil/mil/builder.py", line 166, in _add_op
new_op = op_cls(**kwargs)
File "/Volumes/data/Software/Mine/coremltools-github_issue-1937/coremltools/converters/mil/mil/operation.py", line 187, in __init__
self._validate_and_set_inputs(input_kv)
File "/Volumes/data/Software/Mine/coremltools-github_issue-1937/coremltools/converters/mil/mil/operation.py", line 495, in _validate_and_set_inputs
self.input_spec.validate_inputs(self.name, self.op_type, input_kvs)
File "/Volumes/data/Software/Mine/coremltools-github_issue-1937/coremltools/converters/mil/mil/input_type.py", line 162, in validate_inputs
raise ValueError(msg.format(name, var.name, input_type.type_str,
ValueError: Op "identity_1" (op_type: identity) Input x="classLabel_probs" expects list, tensor, or scalar but got dict[str,fp64]
The reason of these errors seem to be the use of python List
and Dict
rather than TensorFlow tensor. Is this the case in your original TensorFlow model?
Sharing definition of the model:
model = tf.keras.models.Sequential()
model.add(base_model)
model.add(tf.keras.layers.Dropout(0.5))
model.add(tf.keras.layers.Dense(
units=NUM_CLASSES,
activation=tf.keras.activations.softmax,
kernel_regularizer=tf.keras.regularizers.l2(l=0.01)
))
where base_model is Keras default model:
base_model = tf.keras.applications.MobileNetV2(
input_shape=INPUT_IMG_SHAPE,
include_top=False,
weights='imagenet',
pooling='avg'
)
Then (after training) the model is passed into convert
function I already shared. Let me know if this is helpful to you.
Hmmm, do you know where the list ['rock', 'paper', 'scissors']
I saw come from?
Also, do you know where the dict classLabel_probs
come from?
I guess it's coming from dataset itself.
I see. These list and dict are introduced by classifier indeed.
Please continue to workaround by converting without classifier_config
. We have several optimization passes that are vulnerable to list and dict, since they are expecting tensor:
Alright, thanks a lot for solving it! 🙏
🐞Describing the bug
With successfully converted model from Tenserflow to CoreML format, I wanted try to quantize model. I run snippet below with model in
.mlpackage
format but got an error.Stack Trace
To Reproduce
Repreduced by snippet with model attached below.
System environment (please complete the following information):
Additional info