Search code examples
pytorchcntkonnx

CNTK: "inferred dimension cannot be calculated from input and new shape size."


I've set up a model for CIFAR-10 using Pytorch, and saved it as an ONNX file.

But it looks like I can't load it from CNTK.

Architecture

I've already loaded another ONNX file from the same source code (by mistake), so the dependencies look OK. The problem occurs when I call Function.Load()

var deviceDescriptor = DeviceDescriptor.CPUDevice; ;
var function = Function.Load(ONNX_PATH, deviceDescriptor, ModelFormat.ONNX);

I get this exception (Unhandled exception):

   System.ApplicationException : 'Reshape: inferred dimension cannot be calculated from input and new shape size.

    [CALL STACK]
    - CNTK::TrainingParameterSchedule::  GetMinibatchSize
    - CNTK::  XavierInitializer (x6)
    - CNTK::Function::Load
    - CSharp_CNTK_Function__Load__SWIG_0
    - 00007FFB0C41C307 (SymFromAddr() error: Le module spécifié est introuvable.)

Solution

  • It looks like this model can't be loaded in CNTK. CNTK has good support for exporting (saving) to ONNX, importing (loading) can be problematic for some operations.

    CNTK development is frozen, what's your motivation to use it?

    The recommended way now is to use ONNX Runtime https://github.com/microsoft/onnxruntime for inference, it has first-class support for ONNX.