Maix_Toolbox icon indicating copy to clipboard operation
Maix_Toolbox copied to clipboard

tflite2kmodel : Error (Dimensions must be equal)

Open narduzzi opened this issue 5 years ago • 5 comments

Hello,

When trying to convert my tflite model, I'm running into this error:

Fatal: Dimensions must be equal.
System.InvalidOperationException: Dimensions must be equal.
   at NnCase.Converter.Model.InputConnector.SetConnection(OutputConnector from) in D:\Work\Repository\nncase\src\NnCase.Converter\Model\InputConnector.cs:line 32
   at NnCase.Converter.K210.Transforms.K210SeparableConv2dTransform.Process(TransformContext context) in D:\Work\Repository\nncase\src\NnCase.Converter.K210\Transforms\K210SeparableConv2dTransform.cs:line 89
   at NnCase.Converter.Transforms.Transform.Process(Graph graph, IReadOnlyList`1 transforms) in D:\Work\Repository\nncase\src\NnCase.Converter\Transforms\Transform.cs:line 77
   at NnCase.Cli.Program.Main(String[] args) in D:\Work\Repository\nncase\src\NnCase.Cli\Program.cs:line 235
   at NnCase.Cli.Program.<Main>(String[] args)

What could be the source of the problem?

Thank you for your help.

narduzzi avatar Jul 25 '19 06:07 narduzzi

NObody here to help with this?

Yhaw avatar May 17 '23 08:05 Yhaw

Hi @Yhaw, I think I ran into the same problem and solved it by using convolutions with "same" padding. Furthermore, check that each activation map does not exceed 2MB, as the chip will not be able to store it.

narduzzi avatar May 17 '23 08:05 narduzzi

Okk thank you..but canyou help me with cmd you used?lol

On Wed, 17 May 2023, 8:26 am Simon Narduzzi, @.***> wrote:

Hi @Yhaw https://github.com/Yhaw, I solved the problem by padding the inputs to "same". Furthermore, check that each activation map does not exceed 2MB, as the chip will not be able to store it.

— Reply to this email directly, view it on GitHub https://github.com/sipeed/Maix_Toolbox/issues/9#issuecomment-1550971799, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMOOJ4JH27ZW2U4W7CCWAH3XGSDU5ANCNFSM4IGXLUHQ . You are receiving this because you were mentioned.Message ID: @.***>

Yhaw avatar May 23 '23 10:05 Yhaw

Hi @Yhaw,

You have to modify the model to make sure every convolutional layer is using "same" as padding. One way to do it is to rewrite the model from scratch (which I did), another is to switch the padding of each layer (not sure it works). Something like:

model = tf.keras.models.load_model("my_model.h5")

for l in model.layers:
    l.padding="same"
 
 # recompile
 model.compile(...)

And then convert it again using tflite and nncase.

narduzzi avatar May 23 '23 10:05 narduzzi

By the way, I have just opened this issue about how to use the latest version of NNCase with the Maix M1 Dock. Hopefully it will solve your problem as well.

narduzzi avatar May 23 '23 10:05 narduzzi