Repository: opencv
Issue: Some action recognition models cannot be run 
Labels: feature,category: dnn

##### System information (version)

- OpenCV => 4.5.x
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2017

##### Detailed description

Some Action Recognition Models like R3D, R2plus1D, I3D can not be run and cause exceptions. ResNet works perfectly.
[Details here](https://forum.opencv.org/t/dnn-action-recognition/6287)
The same video file is used, the models are always ONNX format.

Exceptions (depending the model)  are : 

OpenCV(4.5.2) Error: Assertion failed (srcMat.dims == 2 && srcMat.cols == weights.cols && dstMat.rows == srcMat.rows && dstMat.cols == weights.rows && srcMat.type() == weights.type() && weights.type() == dstMat.type() && srcMat.type() == CV_32F && (biasMat.empty() || (biasMat.type() == srcMat.type() && biasMat.isContinuous() && (int)biasMat.total() == dstMat.cols))) in cv::dnn::FullyConnectedLayerImpl::FullyConnected::run, file E:\Develop\opencv-4.5.2\modules\dnn\src\layers\fully_connected_layer.cpp, line 180

or :

OpenCV(4.5.2) Error: Assertion failed (total(os[i]) > 0) in cv::dnn::dnn4_v20210301::Net::Impl::getLayerShapesRecursively, file E:\Develop\opencv-4.5.2\modules\dnn\src\dnn.cpp, line 3534

##### Steps to reproduce (cpp code)

```
void test_simple()
{
    std::string f_classes("../models/action_recognition_fr.txt");
    vector<string>v_classes;
    std::ifstream ifs(f_classes);
    std::string line;
    while (std::getline(ifs, line))
    {
        v_classes.push_back(line);
    }
    
    //std::string f_onnx("../models/resnet-34_kinetics.onnx"); // OK
    //std::string f_onnx("../models/r3d18.onnx"); // NOT OK
    std::string f_onnx("../models/r2p1d18.onnx"); // NOT OK

    Net net = readNetFromONNX(std::string(f_onnx));
    net.setPreferableTarget(DNN_TARGET_CPU);
    net.setPreferableBackend(DNN_BACKEND_OPENCV);

    std::string f_video("e:/divx/boxe.mkv");
    VideoCapture cap(f_video);

    int sample_duration = 16;
    int sample_size = 112;

    vector<Mat>v_frames;
    v_frames.clear();

    Mat frame_bidon;
    cap >> frame_bidon;

    for (int i = 0; i < sample_duration; i++)
    {
        Mat frame, frame_resized, frame_f;
        cap >> frame;
        resize(frame, frame_resized, Size(sample_size, sample_size));
        frame_resized.convertTo(frame_f, CV_32FC3);
        v_frames.push_back(frame_f);
    }

    Mat blob = blobFromImages(v_frames, 1.0, Size(112, 112), (114.7748, 107.7354, 99.4750), true, true, CV_32F);
    
    // permutation
    Net permute;
    LayerParams lp;
    int order[] = { 1, 0, 2, 3 };
    lp.set("order", DictValue::arrayInt<int*>(&order[0], 4));
    permute.addLayerToPrev("perm", "Permute", lp);
    permute.setInput(blob);
    Mat input0 = permute.forward().clone();

    int sz[] = { 1, blob.size[1],blob.size[0], blob.size[2], blob.size[3] };
    cout << sz[0] << "," << sz[1] << "," << sz[2] << "," << sz[3] << "," << sz[4] << endl; // OK
    Mat newblob = Mat(5, sz, CV_32F, input0.ptr<float>(0));

    Sleep(300);
    net.setInput(newblob);
    Sleep(300);
    
    cout << "Fwd..." << endl;
    Mat score = net.forward();
    cout << "Done." << endl;

    Point pmin, pmax;
    double vmin, vmax;
    minMaxLoc(score, &vmin, &vmax, &pmin, &pmax);
    cout << "Action : " << v_classes[pmax.x] << endl;
}

```