Tipps for CNN-LSTMs in Video Classification

Christoph9402: <p>Hello,<br>
I am working on a pytorch project, where I’m using a webcam video stream. An object detector is used to find objects within the frame. Then, I want to analyse each bounding box with an CNN-LSTM and classify (binary classification)  the current frame based on the previous frame sequence of that box (for the last 5 frames). I want the program to run a close to real-time as possible.<br>
Currently I am stuck with the CNN-LSTM part of my problem - the detector works quite well already.<br>
I am a little bit clueless on how to approach this task. Here are the questions I have:</p>
<ol>
<li>
<p>How does inferencing work in this case? Do I have to save np arrays for each bounding box containing the last 5 frames, then add the current frame and delete the oldest one? Then use the model for each bounding box that is in the current frame. This way sounds very slow and inefficient. Is there a faster or easier way?</p>
</li>
<li>
<p>Do you have any tipps for creating the dataset? I have a couple of videos with bounding boxes and labels. Should I loop through the videos and save save each frame sequence for each bounding box in a new folder, together with a csv that contains the label? I have never worked with an CNN-LSTM, so I don’t know how to load the data for training.</p>
</li>
<li>
<p>Would it be possible to use the extracted features of the CNN in parallel? As mentioned above, The extracted features should be used by the LSTM for a binary classification problem. The classification is only needed for the current frame.  I would like to use an additional classifier (8 classes) based on the extracted CNN features, also only for the current frame. For this classifier, the LSTM is not needed.</p>
</li>
</ol>
<p>Since my explaining propably is very confusing, the following image hopefully helps with understanding  what I want to build (in this example only last 3 frames):</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/5/c5c8eafdf3025cccd50890ff714ba0301fe7ac48.png" data-download-href="https://discuss.pytorch.org/uploads/default/c5c8eafdf3025cccd50890ff714ba0301fe7ac48" title="Screenshot 2021-07-10 224041"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/c/5/c5c8eafdf3025cccd50890ff714ba0301fe7ac48_2_690x280.png" alt="Screenshot 2021-07-10 224041" data-base62-sha1="sdGwDnHPimVQjkqGMYUY3ZGWsEU" width="690" height="280" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/c/5/c5c8eafdf3025cccd50890ff714ba0301fe7ac48_2_690x280.png, https://discuss.pytorch.org/uploads/default/optimized/3X/c/5/c5c8eafdf3025cccd50890ff714ba0301fe7ac48_2_1035x420.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/c/5/c5c8eafdf3025cccd50890ff714ba0301fe7ac48_2_1380x560.png 2x" data-dominant-color="EDEDE5"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot 2021-07-10 224041</span><span class="informations">2169×882 44.1 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>This is the architecture I want to use. Is this possible using Pytorch? Any help is apprechiated <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>