2 Replies
      Latest reply: Aug 18, 2017 2:36 PM by Guohui Wang RSS
      Guohui Wang Level 1 Level 1 (0 points)

        I have a model converted from Caffe, and is compiled on-the-fly when the application is initialized.


        The last few layer information printed out by CoreML compiler is as follow:

        Neural Network compiler 55: 100 , name = score, output shape : (C,H,W) = (5, 28, 16) 
        Neural Network compiler 56: 100 , name = score_full, output shape : (C,H,W) = (5, 232, 136) 
        Neural Network compiler 57: 175 , name = softmax, output shape : (C,H,W) = (5, 232, 136) 


        In my code, my output is a multiarray. So I expect the shape of the multiarray to be [5, 232, 136].

        However, When I run the model, I got an output multiarray with the shape [1, 1, 5, 232, 136]. Why do we get a 5-dimension array instead of a 3-dimension array?


        The debug screenshot is here: https://ibb.co/kjR6wa


        Anyone can help?


        • Re: Output MLMultiArray shape is strange
          kerfuffle Level 2 Level 2 (80 points)

          The Core ML model specification says:


          * At runtime, all data blobs are internally represented
          * as 5-dimensional blobs
          * with the shape ``[Seq_length, Batch, C, H, W]``.


          So I guess that is what you're seeing here. I don't think it really matters much, since an array with shape [1, 1, 5, 232, 136] contains the exact same data as an array with shape [5, 232, 136].


          Unfortunately, MLMultiArray has no "reshape" function, but I wrote a simple Swift wrapper that makes it a little easier to read from the array. You can find it in the CoreMLHelpers repo on GitHub.

            • Re: Output MLMultiArray shape is strange
              Guohui Wang Level 1 Level 1 (0 points)

              Thanks for the response.

              It is true that the data array is the same. However, I also want to capture the output dimension values from this shape data structure. For example, we want to assign NCHW values to my own Dimension data structure.


              However, if the Shape of the MLMultiArry is not predictable, how can I know which the batch, height, width and channels are?

              Based on my experiments, for different models, the structure of the shape is not consistent. Sometimes, it has the same organization as the Network compiler's print, sometimes it is different (as in the above example). So, I cannot rely on the shape to get all those NCHW values.