Deconvolution layer does not support weight as input tensor during prediction
🐞Describe the bug
I am writing my own converter using coreml.neural_network.NeuralNetworkBuilder. Some layers are deconv layers and take dynamic weight as the second input tensor. According to the coremltools document "For Core ML specification version >=4, W can be None. In this case, the convolution layer takes 2 inputs, where the 1st input represents the input feature map, the 2nd input represents the weight blob.", this is doable and actually I was able to successfully generate the model.
However, the model gives the following error when prediction is performed. "Error reading protobuf spec. validator error: Deconvolution Layer xxx does not support weight as input tensor."
I traced back and found the error came from the following line
https://github.com/apple/coremltools/blob/a629958de1181d11565fc1c2396ec25be9f7146c/mlmodel/src/Validation/NeuralNetwork/NeuralNetworkLayerValidator.cpp#L50
So it looks like the layer validator does not support deconvolution layer that takes dynamic weight as input tensor. There seems to be some inconsistency between NeuralNetworkBuilder's document and NeuralNetworkLayerValidator's implementation.
Trace
File "/usr/local/lib/python3.7/site-packages/coremltools/models/model.py", line 367, in predict raise self._framework_error File "/usr/local/lib/python3.7/site-packages/coremltools/models/model.py", line 113, in _get_proxy_and_spec return (_MLModelProxy(filename, use_cpu_only), specification, None) RuntimeError: Error compiling model: "Error reading protobuf spec. validator error: Deconvolution Layer '8x8/Conv0_up/conv' does not support weight as input tensor.".
https://github.com/apple/coremltools/blob/a629958de1181d11565fc1c2396ec25be9f7146c/mlmodel/src/Validation/NeuralNetwork/NeuralNetworkLayerValidator.cpp#L50
System environment (please complete the following information):
- coremltools version (e.g., 3.0b5): 4.0 built from source using cmake
- OS (e.g., MacOS, Linux): MacOS 11.1
- XCode version (if applicable): 12.3
- How you install python (anaconda, virtualenv, system): system using brew
- python version (e.g. 3.7): 3.7.9, tried 3.8, 3.9 as well, but all had the same problem
Additional context
The model I was trying to generate is stylegan2 face generator.