Skip to content

Draft: DataFormat::Default behavior with transposing

Context

The dataFormat in aidge is set to Default, by convention meaning NCHW, when it's 4D tensors. However, no solution is assigned to it when it comes to transposing it. cf. DataFormat.hpp

#define LIST_DATAFORMAT_ATTR(X) \
    X(Default, “Default”, 0, PERM(), “Unspecified format: interpretation is implementation-dependent”), \
    X(Any, “Any”, 0, PERM(), “Any format is valid”), \
    X(NCHW, “NCHW”, 4, PERM(0, 1, 2, 3), “4D format: [batch][channel][height][width]”), \
    X(NHWC, “NHWC”, 4, PERM(0, 2, 3, 1), “4D format: [batch][height][width][channel]”), \
...

The solution proposed by this Merge Request is to define the behavior of Default Tensors with a map according to the number of dimensions in this way:

//const if we do not create the function setDefaultBehavior
std::map<std::int, string> defaultBehaviour= {
        {0, “”},  
        {1, C}, //Channels, mainly for bias
        {2, NC}, //Batch,Channels
        {3, NHW}, //Batch, Height, Width
        {4, NCHW}, 
        {5, NCDHW}, 
    };

In my case, only the 4D tensors matter, but I think it would be interesting to think together about the behavior for tensors of size [0-3] and 5.

Also, this MR can resolve the issue #259 (moved)

Involved files

  • DataFormat.hpp and DataFormat.cpp, to define the behavior;
  • Test_TransposeImpl.cpp, because the tests will no longer work as before (cf:b3ebbf15) ;
  • Maybe Transpose.cpp

TODO

  • New Units Test
  • Map in DataFormat.hpp
  • Function to retrives the df from the nbDims
  • Update DataFormat getTransposedDataFormat(const DataFormat inputDataFormat, const std::array<std::size_t, 5> outputDimsOrder); (Also the doxygen)
  • setDefaultBehavior (to discuss)

EDIT

With this MR to create a new Producer with df NHWC will be like that

                                                                                // N  C  H   W
std::shared_ptr<Tensor> input = std::make_shared<Tensor>(std::vector<std::size_t>({16,3,224,450}));
input->setDataFormat(Aidge::DataFormat::NHWC);
// setDataFormat converts and transpose this producer from Default to NHWC taking inton consideration that default is NCHW

And not like that :

                                                                                // N   H   W  C
std::shared_ptr<Tensor> input = std::make_shared<Tensor>(std::vector<std::size_t>({16,224,450,3}));
input->setDataFormat(Aidge::DataFormat::NHWC);
Edited by Wissam Boussella

Merge request reports

Loading