{"id":13823,"date":"2021-09-27T11:37:59","date_gmt":"2021-09-27T18:37:59","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cse\/?p=13823"},"modified":"2023-06-19T10:59:41","modified_gmt":"2023-06-19T17:59:41","slug":"archiving-footage-deep-dive","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/ise\/archiving-footage-deep-dive\/","title":{"rendered":"Detecting \u201cAction\u201d and \u201cCut\u201d in Archival Footage Using a Multi-model Computer Vision and Audio Approach with Azure Cognitive Services"},"content":{"rendered":"<p>This blog post was co-authored by Daniel Fatade, Sean Takafuji, Yana Valieva, and Nile Wilson. This deep dive is a follow-up to &#8220;<a href=\"https:\/\/devblogs.microsoft.com\/cse\/2021\/09\/20\/building-an-action-detection-scoring-pipeline-for-digital-dailies\/\">Building an Action Detection Scoring Pipeline for Digital Dailies<\/a>&#8221; by Samuel Mendenhall.<\/p>\n<h2>Introduction<\/h2>\n<p>While shooting a production, cameras are always on. The footage filmed for the entire day is called a \u201cdigital daily\u201d. It includes multiple takes of scenes, as well as unnecessary transitional data. All those digital dailies are then permanently archived to cloud storage in high resolution, and up to 80% of their content is redundant.\u00a0 Obviously, this approach results in unnecessarily expensive storage costs.<\/p>\n<p>Nowadays, archiving and later retrieval of digital dailies is a manual and time-consuming process. Archivists go through gigabytes of reels and identify which portions of content can be archived and\/or discarded.\u00a0 Metadata of each scene and take is annotated manually as well. Together with WarnerMedia, the Microsoft Commercial Software Engineering (CSE) team developed a solution that can significantly reduce the time spent on this process by WarnerMedia\u2019s archivists. While final review prior to deletion will have a \u2018human in the loop\u2019 editor, the automated prediction of discardable segments substantially reduces the time required.<\/p>\n<p>We took advantage of well-known \u201caction\u201d and \u201ccut\u201d filming protocols. The content between \u201caction\u201d and \u201ccut\u201d should be kept, the rest of the content can be archived or discarded. To identify the \u201caction\u201d and \u201ccut\u201d events, we took the approach of identifying visual and audio cues present in the footage as a means of demarcating the portions of content with filmed scenes to be stored, and portions of non-scene and take footage that can be discarded.<\/p>\n<p>Based on the source of the events that we needed to recognize, we identified the following workstreams:<\/p>\n<ul>\n<li><strong>\u201cAction\u201d detection: <\/strong>we used clapperboards for their primary purpose, to identify the beginning of each take. We summed the problem up to binary classification of video frames: a model should automatically detect whether a picture contains a clapperboard or not.<\/li>\n<li><strong>Metadata extraction:<\/strong> we managed to identify rolls, scenes, and several takes by using Optical Character Recognition (OCR) techniques for video frames, containing clapperboards.<\/li>\n<li><strong>\u201cCut\u201d detection:<\/strong> a clapperboard is not always presented at the end of a take, therefore we leveraged the video sound to recognize director commands. The end of a take is usually marked with a \u201ccut\u201d command. We used speech recognition techniques to transcribe the text and identify commands of interest.<\/li>\n<\/ul>\n<p>Our solution heavily leverages Azure Machine Learning as the main experimentation platform, which allows us to run experiments on a remote low-cost compute in parallel mode, log metrics, and track model performance and version models.<\/p>\n<h2>Dataset<\/h2>\n<p>WarnerMedia provided 45-hour long footage of an action film that was divided into 191 files. We then empirically split the dataset into train, validation and test sets based on qualitative aspects of each video (e.g., green screens, dim lighting, rain, etc.). We elected to selectively sample per the above guidelines over a random sampling to ensure there was a representative sample over the distribution of different types of footage in all three sets. Thus, we produced the following datasets:<\/p>\n<ul>\n<li>Train set: 128 files, 31 hours of content.<\/li>\n<li>Validation set: 32 files, 7 hours of content.<\/li>\n<li>Test set: 31 files, 7 hours of content.<\/li>\n<\/ul>\n<p>Frames extracted from this video dataset are referred to as the frame dataset.<\/p>\n<h2>\u201cAction\u201d Detection using Custom Vision<\/h2>\n<p>For clapperboard detection we took a <a href=\"https:\/\/www.customvision.ai\/\">Custom Vision<\/a> experimentation path. This service allowed us to customize model training with the frames dataset, build a strong baseline for clapperboard recognition, and iterate the model to improve recognition quality. However, we had to cut through several obstacles, such as unlabeled data, imbalanced data, and systematic errors. In this section we explain the challenges we faced and demonstrate how we managed to overcome them.<\/p>\n<h2>Labeling<\/h2>\n<p>Labeled data is a strong requirement for the Custom Vision service. Our attempt at manual labeling cost us 40 minutes per video on average. Continuing with this method would result in approximately 18 working days for an 84k images subset, not even considering that it\u2019s almost impossible to stare at the pictures more than 5 hours a day.<\/p>\n<p>When we look deeper into the data, we notice one thing typical for this media data; there are lots of very similar images. How can we group these similar images and label these few groups instead of keeping all the frames extracted from each video?<\/p>\n<p><figure id=\"attachment_13858\" aria-labelledby=\"figcaption_attachment_13858\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_01.png\"><img decoding=\"async\" class=\"size-large wp-image-13858\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_01-1024x312.png\" alt=\"Figure 1 - Semi-supervised image labeling workflow\" width=\"640\" height=\"195\" srcset=\"https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_01-1024x312.png 1024w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_01-300x91.png 300w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_01-768x234.png 768w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_01-1536x468.png 1536w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_01.png 1866w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><figcaption id=\"figcaption_attachment_13858\" class=\"wp-caption-text\"><strong>Figure 1<\/strong>. Semi-supervised image labeling workflow.<\/figcaption><\/figure><\/p>\n<p>In Figure 1 above, you can see our workflow. On the first step we have many unlabeled images. We then extract embeddings from these images using a commonly used lightweight <a href=\"https:\/\/arxiv.org\/abs\/1409.1556\">VGG16<\/a> neural network, pretrained on the <a href=\"http:\/\/image-net.org\/\">ImageNet<\/a> dataset. After that, we feed them into the clustering algorithm. In our case we use the <a href=\"https:\/\/www.aaai.org\/Papers\/KDD\/1996\/KDD96-037.pdf\">DBSCAN<\/a> algorithm, which finds core samples of high density in a multi-dimensional workspace using a distance function and expands clusters.<\/p>\n<p>For each video, we get a different small number of clusters and some of the noise points. Now we only need to manually assign labels to few clusters instead of to all the video frames. As a result, the time spent on labeling was reduced to 4-5 minutes per video, which resulted in needing only 2 working days for labeling.<\/p>\n<p>Important to note, this method produces some false positives and false negatives because of its unsupervised nature. However, the noise level in the labels estimated by the algorithm is appropriate for training deep neural networks and did not have a negative impact on the final solution.<\/p>\n<p>The code for the labeling tool has been operationalized as an Azure Search Power Skill and is available in the <a href=\"https:\/\/github.com\/Azure-Samples\/azure-search-power-skills\/tree\/main\/Vision\/ImageClusteringSkill\">Azure-Samples<\/a> repository.<\/p>\n<h2>Approach<\/h2>\n<p>Due to its nature, the frames dataset is highly imbalanced: the ratio between plain footage and footage containing clapperboards is skewed to the plain images (26:1). We decided to not proceed with standard balancing techniques such as randomly downsampling or upsampling the underrepresented class due to data loss and increased training time, respectively.<\/p>\n<p>Instead, we decided to go ahead with our dataset-specific approach. Frames extracted from the media data are almost always excessive: an extraction frames per second (fps) of 1 allows you not to miss any scene changes, but also provides you with a lot of redundant, nearly identical, images that do not contribute to the model quality. Hence, we decided to reuse the clustering approach described in the labeling section for the plain images class. From each cluster, we selected 5 images (core point and nearest to them) and added all the noise points. This approach enabled us to get a 1.5:1 ratio of the classes in the frames dataset.<\/p>\n<p>We also took the approach of data augmentation to address dataset imbalance. Even though Custom Vision provides some built-in augmentation techniques, the results of our experiments have shown that further augmentations might improve the model performance.<\/p>\n<p>Inspired by the augmentation heatmaps approach described in the <a href=\"https:\/\/arxiv.org\/abs\/2002.05709\">A Simple Framework for Contrastive Learning of Visual Representations<\/a> paper (Chen et al., 2020), we decided to adopt this approach to systematically study the impact of different augmentation techniques on the model performance. We reproduced this approach with a specific set of augmentation that we found to be useful for our task based on the analysis of systematic errors. We consider several common types of augmentations here:<\/p>\n<ul>\n<li>Spatial\/geometric transformation of data (e.g., crop, pad, rotate)<\/li>\n<li>Appearance transformation (e.g., blur, cutout)<\/li>\n<li>Color distortion (e.g., brightness, contract)<\/li>\n<li>Combo augmentations (a pipeline of augmentations applied to the same image)<\/li>\n<\/ul>\n<p><figure id=\"attachment_13861\" aria-labelledby=\"figcaption_attachment_13861\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_01.png\"><img decoding=\"async\" class=\"size-large wp-image-13861\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_01-1024x296.png\" alt=\"Table 1 - Comparison of models with different hypotheses applied.\" width=\"640\" height=\"185\" srcset=\"https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_01-1024x296.png 1024w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_01-300x87.png 300w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_01-768x222.png 768w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_01.png 1192w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><figcaption id=\"figcaption_attachment_13861\" class=\"wp-caption-text\"><strong>Table 1<\/strong>. Comparison of models with different hypotheses applied.<\/figcaption><\/figure><\/p>\n<p>To understand the effects of individual data augmentations and augmentation composition, we investigated the performance of our framework by applying augmentations individually or in pairs using heatmaps provided below. Based on these heatmaps we managed to select a release candidate with the best tradeoff between important business metrics: precision and recall. Please, find the comparison of the models in the table above.\u00a0 Red color means best individual metrics, green one highlights the release model we have chosen.<\/p>\n<p><figure id=\"attachment_13862\" aria-labelledby=\"figcaption_attachment_13862\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_02.png\"><img decoding=\"async\" class=\"size-large wp-image-13862\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_02-1024x476.png\" alt=\"Figure 2 - Heatmaps illustrating the impact of different augmentation techniques on the model performance.\" width=\"640\" height=\"298\" srcset=\"https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_02-1024x476.png 1024w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_02-300x140.png 300w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_02-768x357.png 768w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_02-1536x714.png 1536w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_02.png 1776w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><figcaption id=\"figcaption_attachment_13862\" class=\"wp-caption-text\"><strong>Figure 2<\/strong>. Heatmaps illustrating the impact of different augmentation techniques on the model performance.<\/figcaption><\/figure><\/p>\n<h2>Training Pipeline<\/h2>\n<p>We operationalized the Custom Vision training process by creating a reusable pipeline that consists of 4 steps. In the <strong>Image Augmentation Step<\/strong>, we applied the approach described in the previous section to generate an augmented dataset for further model training. This step takes a path to an augmentation configuration json file and saves the augmented dataset back to the Blob Storage. If the dataset that corresponds to the provided file already exists and no force flag is provided, the pipeline skips this step to spare computation time and resources.<\/p>\n<p>The <strong>Custom Vision Training Step<\/strong> creates a new Custom Vision project and uploads the specified dataset to the Custom Vision service. Once the training is completed, we provide the <strong>Evaluation Step<\/strong> with the trained model information to validate the quality of the model. In this step, we calculate metrics for the newly trained Custom Vision model and log them to both Azure Machine Learning Studio and Application Insights. Using Azure Machine Learning Studio, Data Scientists and Machine Learning engineers can easily get detailed reports on model performance and track model improvements. For this purpose, we log model metrics, model architecture, augmentations applied, model training time, etc. For business users we built PowerBI dashboards with a limited number of metrics corresponding to the business objectives. These reports reflect changes in model performance over time.<\/p>\n<p>Once the evaluation step is completed, we proceed to the <strong>Model Registration Step<\/strong>. This step is very important to ensure full model compatibility with the final solution scoring pipeline. Based on the artifacts produced by this step, the scoring pipeline will be able to fully reproduce the model and its parameters for further batch usage. To enable this compatibility, we save the following artifacts as a model to the model registry:<\/p>\n<ul>\n<li>The model itself. In this case, a model is represented by a <strong>.json<\/strong> file containing all the required properties to choose the right Custom Vision project and iteration (project name, iteration id).<\/li>\n<li>A <strong>.csv<\/strong> file containing the description of a dataset the model was trained on.<\/li>\n<li>A <strong>.json<\/strong> augmentation configuration file for a full reproduction of the dataset the model was trained on.<\/li>\n<li>A <strong>.csv<\/strong> file containing lists of False Positives, False Negatives for further systematic errors analysis.<\/li>\n<li>Hyperparameters of the model as registered model tags.<\/li>\n<\/ul>\n<p>All these artifacts guarantee full compatibility between the training pipeline and our final solution scoring pipeline.<\/p>\n<h2>Clapperboard Metadata Extraction using Azure Form Recognizer<\/h2>\n<p>Another key aspect of the solution was to effectively find a means of extracting text-based metadata from clapperboard images at scale in order to identify rolls, scenes, and takes. In order to effectively extract metadata from many clapperboard images at scale, we utilized an <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/machine-learning\/concept-model-management-and-deployment\">MLOps<\/a> solution which consisted of a series of steps:<\/p>\n<ol>\n<li><a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/custom-vision-service\/\">Azure Custom Vision Step<\/a>: Predict Clapperboard Images (as described in the previous section).<\/li>\n<li>Clapperboard Selection Step: Select the most \u201cinformative\u201d image from a batch of clapperboard images using <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/computer-vision\/overview-ocr\">Optical Character Recognition<\/a> (OCR).<\/li>\n<li>Azure <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Form Recognizer<\/a> Step: Run OCR on selected images and produce key-value pairs for predicted text elements.<\/li>\n<li>Postprocessing Step: Use a rule-based approach to improve results from the Azure <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Form Recognizer<\/a><\/li>\n<\/ol>\n<p>An illustration giving an overview of the vision portion of the solution is provided below:<\/p>\n<p><figure id=\"attachment_13864\" aria-labelledby=\"figcaption_attachment_13864\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_03.png\"><img decoding=\"async\" class=\"size-large wp-image-13864\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_03-1024x321.png\" alt=\"Figure 3 - Sample Diagram of OCR + Form Recognizer workstream. Clapperboard image provided by Harald M\u00fcller on Unsplash (https:\/\/unsplash.com\/photos\/ACAJGonG8rA).\" width=\"640\" height=\"201\" srcset=\"https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_03-1024x321.png 1024w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_03-300x94.png 300w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_03-768x241.png 768w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_03-1536x482.png 1536w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_03-2048x643.png 2048w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><figcaption id=\"figcaption_attachment_13864\" class=\"wp-caption-text\"><strong>Figure 3<\/strong>. Sample Diagram of OCR + Form Recognizer workstream. Clapperboard image provided by <a href=\"https:\/\/unsplash.com\/photos\/ACAJGonG8rA\">Harald M\u00fcller on Unsplash<\/a>.<\/figcaption><\/figure><\/p>\n<h2>Challenges<\/h2>\n<p>Initially, our research led us to believe that the Azure <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Form<\/a> Recognizer Cognitive Service would be sufficient to automate the process of extracting text and generating key-value pairs for clapperboard items such as roll, scene, take and more. However, after some experimentation, we realized that the default service was unable to meaningfully extract and map any values of interest. This was not unexpected given that the default model was trained to generalize as much as possible, specifically for key-value extraction with business cards, receipts and more.<\/p>\n<p>Nonetheless, we believed the service could still be of use given a custom approach. This led to the idea of training a custom model in <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/form-recognizer\/quickstarts\/label-tool?tabs=v2-1\">Azure Form <\/a>Recognizer Service by utilizing a representative sample of our clapperboard dataset. However, the cost of training and utilizing a custom model in <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/form-recognizer\/quickstarts\/label-tool?tabs=v2-1\">Azure Form Recognize<\/a>r service can be rather steep.<\/p>\n<p>The cost of running predictions on the custom service would amount to $50 per 1000 images. In comparison, the default service cost $10 per 1000 images processed. Given that we anticipate the service will process possibly millions of clapperboard images, it was imperative that we found a means to minimize cost. <strong>This is what led to the hypothesis of using the <\/strong><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/computer-vision\/concept-recognizing-text#:~:text=The%20Computer%20Vision%20Read%20API%20is%20Azure's%20latest,images%20and%20multi-page%20PDF%20documents%20with%20mixed%20languages.\"><strong>Azure Cognitive Services Computer Vision Read<\/strong><\/a><strong> API <\/strong><strong>(OCR) and a character-level frequency scoring function to select the most informative image from a set of similar images.<\/strong><\/p>\n<h2>Approach<\/h2>\n<p>For this workstream, we utilized OCR technology that was made available through the <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/computer-vision\/concept-recognizing-text#:~:text=The%20Computer%20Vision%20Read%20API%20is%20Azure's%20latest,images%20and%20multi-page%20PDF%20documents%20with%20mixed%20languages.\">Azure Cognitive Services Computer Vision Read API<\/a>. This technology was trained to interpret both handwritten and printed text. This was useful for metadata extraction given that the clapperboard images we worked with generally contained a mix of both printed and handwritten text. Generally, each of the video files contained a set of \u201caction\u201d events. Within each action event, we were provided with a set of clapperboard images, in which each of the images were visually similar to one another. We identified three possible types of images within each event:<\/p>\n<ul>\n<li>A blurry clapperboard image, where the clapperboard object is being brought into the frame.<\/li>\n<li>A still clapperboard image, where the image has successfully been brought into the frame.<\/li>\n<li>A blurry clapperboard image, where the clapperboard object is being taken out of the frame.<\/li>\n<\/ul>\n<p>From our findings, the blurry clapperboard images did not offer much value, given that the OCR service could barely detect any text within these images. The only meaningful image types were the still clapperboard images. As you can imagine, when extracting image frames from video, there will be multiple duplicate or similar frames depending on the number of frames extracted per second. In our case, we extracted one image frame per second (1 fps), as these were the input parameters specified to the Custom Vision step (please refer to the Custom Vision section for an explanation regarding clapperboard detection and the decision to use 1 fps for frame extraction purposes) With this, we identified that for each action event, there was at least more than one still image.<\/p>\n<p>Given that each still image in a respective action event essentially contains the same metadata we wish to extract from clapperboards, we decided to utilize only one of these images per action event. This presented the challenge of knowing how to select the best or the most informative clapperboard for each event, where the most informative clapperboard image is the image where the OCR model can extract the most meaningful text from.<\/p>\n<p>Since we were relying heavily on OCR for this workstream, we decided it would be a good approach to utilize a character-level frequency function to score and identify the most informative image. The idea is that the image with the most predictable text will have the highest character count. Thus, the image with the highest character count will be identified as the most informative.<\/p>\n<p>Conveniently, the OCR service was at a lower cost when compared to using a custom model in Azure <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Form Recognizer<\/a> (<strong>around $2.50 per 1000 images processed <\/strong>for standard pricing). Given this, we could afford to feed in millions of images into the service and filter out unnecessary images before sending results to the custom model in the Azure <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Form Recognizer<\/a> cognitive service.<\/p>\n<h2>Labeling<\/h2>\n<p>As mentioned earlier, utilizing a custom model in Azure Form Recognizer is expensive. However, by utilizing the clapperboard selection step, we can significantly reduce the costs incurred by the custom service given that only a subset of clapperboard images are fed into the model. In order to train a custom service, we aimed to:<\/p>\n<ol>\n<li>Select and make use of a representative set of clapperboard images to be used in training the custom model.<\/li>\n<li>Utilize the Azure <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Form Recognizer<\/a> sample-labeling tool to tag text artefacts from the representative dataset with appropriate labels.<\/li>\n<li>Train a custom model in Azure Form Recognizer using a set of asset files generated from the <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/form-recognizer\/quickstarts\/label-tool?tabs=v2-1\">sample labeling too<\/a><\/li>\n<li>Package the entire training process as a series of steps to be run within an <a href=\"https:\/\/azure.microsoft.com\/en-us\/free\/machine-learning\/search\/?OCID=AID2100131_SEM_0c83352903eb180886a0557bc145eab4:G:s&amp;ef_id=0c83352903eb180886a0557bc145eab4:G:s&amp;msclkid=0c83352903eb180886a0557bc145eab4\">Azure Machine Learning (AML)<\/a><\/li>\n<\/ol>\n<p>As described earlier in the Custom Vision workstream section, we implemented a density-based clustering algorithm to generate a representative sample of our clapperboard dataset. This representative dataset was then used within the Azure <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Form Recognizer<\/a> <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/form-recognizer\/quickstarts\/label-tool?tabs=v2-1\">sample labeling tool<\/a>.<\/p>\n<p>The Azure <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Form Recognizer<\/a> <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/form-recognizer\/quickstarts\/label-tool?tabs=v2-1\">sample labeling tool<\/a> is an application that provides a simple user interface, which we can use to manually label forms (documents or images) for the purpose of supervised learning. The tool reads in a set of documents or images from a specified blob storage container. From here, we can run OCR on all the read-in content and assign labels to predicted text artefacts. These set of labels can then be used to train a custom model in <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/form-recognizer\/quickstarts\/label-tool?tabs=v2-1\">Azure Form Recognizer<\/a>.<\/p>\n<p>Generally, the average clapperboard contains the following items:<\/p>\n<ul>\n<li><strong>Roll<\/strong> \u2013 The roll of film stock used for the current take.<\/li>\n<li><strong>Scene<\/strong> \u2013 The ID of the scene that is currently being shot\/filmed.<\/li>\n<li><strong>Take<\/strong> \u2013 The current take number for a particular scene.<\/li>\n<li><strong>Director<\/strong>&#8211; Director of the project.<\/li>\n<li><strong>Co-director<\/strong>\/<strong>camera<\/strong> \u2013 Co-director or the individual who filmed the scene.<\/li>\n<li><strong>Title<\/strong>\u2013 The title of the project. In this case, the title could be the name of your favorite movie, let\u2019s say for example, \u201cThe Dark Knight\u201d.<\/li>\n<li><strong>Description \u2013 <\/strong>Extra text\/information describing a particular scene in some cases.<\/li>\n<\/ul>\n<p>A set of asset files are required to effectively train the service. For each image, we need the following:<\/p>\n<ul>\n<li>An ocr.json file that contains information regarding all predicted text items and bounding boxes generated on a single image\/document.<\/li>\n<\/ul>\n<pre class=\"prettyprint\">{\r\n    \"status\": \"succeeded\",\r\n    \"createdDateTime\": \"2021-03-01T19:19:35Z\",\r\n    \"lastUpdatedDateTime\": \"2021-03-01T19:19:40Z\",\r\n    \"analyzeResult\": {\r\n        \"version\": \"2.0.0\",\r\n        \"readResults\": [\r\n            {\r\n                \"page\": 1,\r\n                \"angle\": 0.6682,\r\n                \"width\": 5398,\r\n                \"height\": 3648,\r\n                \"unit\": \"pixel\",\r\n                \"language\": \"en\",\r\n                \"lines\": [\r\n                    {\r\n                        \"boundingBox\": [ 3843, 1485, 3798, 1348, 3832, 1337, 3879, 1473],\r\n                        \"text\": \"dry erase\",\r\n                        \"words\": [\r\n                            {\r\n                                \"boundingBox\": [...],\r\n                                \"text\": \"dry\",\r\n                                \"confidence\": 0.648\r\n                            },\r\n                            {...}\r\n                        ]\r\n                    }\r\n                ]\r\n            }\r\n        ]\r\n    }\r\n}<\/pre>\n<ul>\n<li>A labels.json file containing information regarding assigned labels to predicted text artifacts within a single image\/document.<\/li>\n<\/ul>\n<pre class=\"prettyprint\">{\r\n    \"document\": \"image_1.jpg\",\r\n    \"labels\": [\r\n        {\r\n            \"label\": \"roll\",\r\n            \"key\": null,\r\n            \"value\": [\r\n                {\r\n                    \"page\": 1,\r\n                    \"text\": \"01\",\r\n                    \"boundingBoxes\": [\r\n                        [0.3356, 0.4564, 0.3884, 0.4547, 0.3892, 0.5032, 0.3366, 0.5052]\r\n                    ]\r\n                },\r\n                {\r\n                    \"page\": 1,\r\n                    \"text\": \"A\",\r\n                    \"boundingBoxes\": [\r\n                        [0.3021, 0.4665, 0.3147, 0.4665, 0.3142, 0.4942, 0.3017, 0.4939]\r\n                    ]\r\n                }\r\n            ]\r\n        },\r\n        {\r\n            \"label\": \"title\",\r\n            ...\r\n        }\r\n    ]\r\n}<\/pre>\n<p>In total, to successfully train a custom model in Azure <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Form Recognizer<\/a> service, we need the original image file, an ocr.json file and a labels.json file (examples shown above). These two asset files can be rather large and tricky to fill in manually. Luckily, the sample labeling tool automatically generates these asset files and stores them within the same storage container the images were read from. This means that once labeled, as long as a SAS URI pointing to the container is made available, the process of training the model can be automated by utilizing a Python script within an AML pipeline.<\/p>\n<h2>Character-Level Frequency Scoring<\/h2>\n<p>We managed to achieve an average accuracy of around 80% across all classes, with the addition of a postprocessing step, by utilizing a small sample of around 300 clapperboard images. This implies that a relatively small dataset can be used to achieve fairly good results.<\/p>\n<p><figure id=\"attachment_13871\" aria-labelledby=\"figcaption_attachment_13871\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_02.png\"><img decoding=\"async\" class=\" wp-image-13871\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_02.png\" alt=\"Table 2 - Accuracy across different classes from the custom trained in Azure Form Recognizer.\" width=\"409\" height=\"200\" srcset=\"https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_02.png 762w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_02-300x146.png 300w\" sizes=\"(max-width: 409px) 100vw, 409px\" \/><\/a><figcaption id=\"figcaption_attachment_13871\" class=\"wp-caption-text\"><strong>Table 2<\/strong>. Accuracy across different classes from the custom trained in Azure Form Recognizer.<\/figcaption><\/figure><\/p>\n<p>One thing to note is that the Azure <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Form Recognizer<\/a> uses the same OCR technology as the Azure Cognitive Services Computer Vision Read API. As a result, any predictions the OCR service fails to make will be reflected in the results of the custom model trained with Azure <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Form Recognizer<\/a> service; i.e, if the OCR fails to pick up a \u201cscene\u201d item, the Azure <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Form Recognizer<\/a> service will output and empty key-value pair for \u201cscene\u201d.<\/p>\n<h2>End of Scene Detection using Custom Speech from Azure Cognitive Services<\/h2>\n<p>A key aspect of the solution is to note where the end of a scene occurs. In a majority of cases, the only indication of the end of a scene is an utterance of the word \u201ccut\u2019 by the director. As a result this requires a speech recognition solution to detect this keyword. Our baseline model was the \u201cout-of-the-box\u201d variant of <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/speech-to-text\/\">Speech to Text from Azure Cognitive Services<\/a>. Our initial assessment was that Speech to Text was producing too many false negatives, resulting in low recall scores and leading us to experiment with custom modeling approaches. The custom modeling approaches we experimented with were an adoption of <a href=\"https:\/\/arxiv.org\/abs\/2001.07685\">FixMatch<\/a> for the audio space, <a href=\"https:\/\/tfhub.dev\/google\/vggish\/1\">VGGish Embeddings<\/a> trained on the benchmark dataset <a href=\"http:\/\/research.google.com\/youtube8m\/\">Youtube-8M<\/a>, and <a href=\"https:\/\/tfhub.dev\/google\/speech_embedding\/1\">Speech Embeddings<\/a> trained on the benchmark dataset <a href=\"https:\/\/arxiv.org\/abs\/1804.03209\">Speech Commands<\/a>. Of the three approaches, Speech Embeddings had the best performance metrics for our task.<\/p>\n<p>Within the training pipeline of our final solution, we utilize <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/speech-service\/custom-speech-overview\">Custom Speech<\/a> from Azure Cognitive Services for the task of detecting \u201ccut\u201d utterances.<\/p>\n<p><figure id=\"attachment_13872\" aria-labelledby=\"figcaption_attachment_13872\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_03.png\"><img decoding=\"async\" class=\"size-full wp-image-13872\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_03.png\" alt=\"Table 3 - Key milestone metrics for &quot;cut&quot; detection during the project.\" width=\"1520\" height=\"196\" srcset=\"https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_03.png 1520w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_03-300x39.png 300w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_03-1024x132.png 1024w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Table_03-768x99.png 768w\" sizes=\"(max-width: 1520px) 100vw, 1520px\" \/><\/a><figcaption id=\"figcaption_attachment_13872\" class=\"wp-caption-text\"><strong>Table 3<\/strong>. Key milestone metrics for &#8220;cut&#8221; detection during the project.<\/figcaption><\/figure><\/p>\n<p>In Table 3, we note the key milestones where an improvement to the audio aspect of the solution was made. Note that Table 3 refers to the metrics regarding \u201ccut\u201d detection while our final business metrics are for the task of identifying portions of footage \u201cto archive\u201d or \u201cto discard\u201d. To increase our final business metrics, it is desirable to prioritize having a higher recall even if it means a loss of precision and a reduction of our overall f1-score. This is due to the following outcomes of postprocessing:<\/p>\n<ol>\n<li>Multiple false positive \u201ccuts\u201d can be reduced by grouping predictions to each other that are nearby in time.<\/li>\n<li>A false positive \u201ccut\u201d that occurs between a true positive \u201caction\u201d and \u201ccut\u201d is completely ignored as we will mark the entire section as \u201cto archive\u201d.<\/li>\n<\/ol>\n<p>As a result of the above postprocessing steps, the final business metrics on the classification of footage \u201cto archive\u201d and \u201cto discard\u201d has performance metrics of 0.96 precision and recall.<\/p>\n<h2>Challenges<\/h2>\n<p>The key challenges with the audio detection of the utterance of \u201ccut\u201d were due to the nature of the microphone capture.<\/p>\n<ul>\n<li><strong>Challenge #1: No Transcription Provided.<\/strong> The provided videos were not equipped with an accompanied transcription nor information on key timestamps where a scene began and ended. As a result, to treat this as a supervised classification problem, we would first need to undergo a manual labeling process to build a training set.<\/li>\n<li><strong>Challenge #2: Distant Speaker<\/strong>. The primary microphone capture for the footage we worked with is for the actors and the environmental sounds within a scene. As a result, the director and their crew were always a secondary capture, comparable to background speakers. Thus, our speech recognition task focused on correctly identifying when a soft and distant speaker uttered the word \u201ccut\u201d.<\/li>\n<\/ul>\n<h2>Labeling<\/h2>\n<p>To address <strong>Challenge #1: No Transcription Provided, <\/strong>we underwent a manual labeling effort throughout the lifetime of the project, with labels \u201caction-utterance-action\u201d and \u201ccut-utterance-cut\u201d.<\/p>\n<p>To gain a precise start and end timestamp we utilized a tool called <a href=\"https:\/\/www.audacityteam.org\/\">Audacity\u00ae<\/a>, which is an open-source and cross-platform audio editor. When opening a file in Audacity\u00ae, we can add labels to a label track as seen in <strong>Figure 4<\/strong>.\u00a0Per our label schema, whenever a \u201ccut\u201d that indicated the end of a scene was uttered, we would add the label \u201ccut-utterance-cut\u201d. All the labels on the label track can then be exported as a txt file which is then converted to a csv format during the preprocessing step of the training pipeline. The label files are than aggregated for the files in the train, validation, and test sets.<\/p>\n<p><figure id=\"attachment_13874\" aria-labelledby=\"figcaption_attachment_13874\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_06.png\"><img decoding=\"async\" class=\"size-full wp-image-13874\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_06.png\" alt=\"Figure 6 - Minimal example of label assets on an mp4 file (Left) Adding labels in Audacity at the appropriate timestamps using a bounding box around the waveform. (Right) The label track exported as a txt file with start and end timestamps in seconds. (Bottom) The csv label file generated from the txt file.\" width=\"624\" height=\"338\" srcset=\"https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_06.png 624w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_06-300x163.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/a><figcaption id=\"figcaption_attachment_13874\" class=\"wp-caption-text\"><strong>Figure 4<\/strong>. Minimal example of label assets on an mp4 file. <strong>(Left)<\/strong> Adding labels in Audacity\u00ae at the appropriate timestamps using a bounding box around the waveform. <strong>(Right)<\/strong> The label track exported as a txt file with start and end timestamps in seconds. <strong>(Bottom)<\/strong> The csv label file generated from the txt file.<\/figcaption><\/figure><\/p>\n<h3>Dynamic Range Compression<\/h3>\n<p>The preprocessing step also addresses <strong>Challenge #2: Distant Speaker<\/strong> through the usage of dynamic range compression. Dynamic range compression is an audio signal processing operation that reduces the difference between the smallest and largest value in the signal, reducing the volume of louder noises while increasing softer ones. This brings the director and film crew\u2019s utterances of \u201ccut\u201d that were soft and, in some cases, nearly inaudible close to the forefront of the audio signal.<\/p>\n<pre class=\"prettyprint\">for step in step_order:\r\n    t_start_step = datetime.now()\r\n\r\n    output_audio_dir = join(output_audio_dir, step)\r\n    input_audio_filepath = output_audio_filepath\r\n    output_audio_filepath = join(output_audio_dir, audio_filename)\r\n\r\n    # Dynamic Range Compression\r\n    if step == \"compress\":\r\n        run_ffpmeg_dynaudnorm(\r\n            input_audio_filepath, output_audio_filepath, overwrite=overwrite\r\n        )\r\n\r\n    # Denoising\r\n    elif step == \"denoise\":\r\n        denoise_audio(\r\n            input_audio_filepath,\r\n            output_audio_filepath,\r\n            overwrite=overwrite\r\n        )\r\n    # Format Audio for Custom Speech Service\r\n    elif step == \"reformat\":\r\n        reformat_audio_for_custom_speech(\r\n            input_audio_filepath, output_audio_filepath, overwrite=overwrite\r\n        )\r\n    runtime[step] += (datetime.now() - t_start_step).total_seconds()<\/pre>\n<p>The above code block shows a preprocessing loop. To allow flexibility with the order of these preprocessing steps during experimentation, the step_order is defined as a list such as [&#8220;denoise&#8221;, &#8220;compress&#8221;, &#8220;reformat&#8221;] and the functions will be applied in that order. More information about Dynamic Range Compression available in the <a href=\"https:\/\/ffmpeg.org\/ffmpeg-filters.html#dynaudnorm\">ffmpeg documentation<\/a>.<\/p>\n<h3>Formatting the Training Dataset for Custom Speech<\/h3>\n<p>After reformatting the audio files per Custom Speech requirements, the training dataset requires additional handling via extracting only the segments captured in the bounding box labels. These segments are written out as individual 2 second duration wav files with the pattern {filename}-{word}-{id}.wav. If the bounding box was for less than 2 seconds, the waveform is right padded with zeroes. To reduce the number of false positives, we additionally added samples of similar sounding words such as \u201cbut\u201d and \u201ccat\u201d alongside the \u201ccut\u201d audio samples. Accompanying these files is a single transcription file, Trans.txt, where each line is the filename followed by a machine-friendly English transcription of the words spoken in the file. The segments and transcription file are written out to a single directory which is then archived to be uploaded to Custom Speech\u2019s datasets.<\/p>\n<h2>Training and Evaluation<\/h2>\n<p>To utilize Custom Speech, we leveraged the <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/speech-service\/swagger-documentation#generating-code-from-the-swagger-specification\">Python Swagger SDK<\/a> variant to make API calls.<\/p>\n<p>For the AML step \u201ctrain_and_evaluate\u201d in the following intermediate steps occur:<\/p>\n<ol>\n<li>The training and validation datasets are registered on Custom Speech.<\/li>\n<li>A baseline Speech to Text model is selected to finetune based on our training data.<\/li>\n<li>The model undergoes training.<\/li>\n<li>The model transcribes each wav file in the validation dataset.<\/li>\n<li>The transcriptions for each wav file are retrieved from Custom Speech and parsed for any detection of \u201ccut\u201d.<\/li>\n<li>The classification metrics are computed and aggregated across all files in the validation dataset.<\/li>\n<li>The classification metrics, dataset IDs, and model ID are logged to the AML experiment.<\/li>\n<li>Through the Azure DevOps pipeline that triggers the AML pipeline, a newly trained model can be marked as the one for production.<\/li>\n<\/ol>\n<h3>Selecting the Baseline Speech to Text Model<\/h3>\n<p>When training a Custom Speech model, a Speech to Text model is used as the initial baseline to train from. Whenever the training pipeline runs, the newest available model is always utilized. As the mechanism to mark a model for production requires human approval, this automatic change would only be released if a data scientist marks the model for use in the final solution scoring pipeline.<\/p>\n<h3>Evaluation on the Validation Dataset<\/h3>\n<p>When custom speech evaluates an audio file, it creates a JSON transcription (as seen below). For each entry in recognized phrases, we parse the results in \u201cnBest\u201d followed by each word in \u201cwords\u201d to determine if a \u201ccut\u201d was detected in the transcription. For clearer insight at this stage of the evaluation, we do not factor in the confidence score of \u201ccut\u201d when comparing the predictions against the ground truth.<\/p>\n<pre class=\"prettyprint\">{\r\n    \"source\": \"test_1.wav\",\r\n    \"timestamp\": \"2020-09-18T12:29:49Z\",\r\n    \"durationInTicks\": 6120600000,\r\n    \"duration\": \"PT10M12.065\",\r\n    \"recognizedPhrases\": [\r\n        {\r\n            \"recognitionStatus\": \"Success\",\r\n            \"channel\": 0,\r\n            \"offsetInTicks\": 100000000.0,\r\n            \"durationInTicks\": 120000000.0,\r\n            \"nBest\": [\r\n                {\r\n                    \"confidence\": 0.53361744,\r\n                    \"lexical\": \"cut\",\r\n                    \"itn\": \"cut\",\r\n                    \"maskedITN\": \"\",\r\n                    \"display\": \"cut\",\r\n                    \"words\": [\r\n                        {\r\n                            \"word\": \"cut\",\r\n                            \"offset\": \"PT1.54S\",\r\n                            \"duration\": \"PT0.23S\",\r\n                            \"offsetInTicks\": 15400000.0,\r\n                            \"durationInTicks\": 2300000.0,\r\n                            \"confidence\": 0.53361744\r\n                        }\r\n                    ]\r\n                }\r\n            ]\r\n        }\r\n    ]\r\n}<\/pre>\n<p>The above code block shows an example transcription created by Custom Speech on a validation \/ scoring wav file input.<\/p>\n<h3>Metrics Calculation<\/h3>\n<p>For the classification metrics, when comparing the predictions against the ground truth we allow the timestamps to differ by an amount \u201cts_threshold\u201d. This allows a slight discrepancy in the timestamp of detection from the transcription and our ground truth label to still be classified as a true positive. In our reported metrics, we used a \u201cts_threshold\u201d value of 3 seconds meaning a detected \u201ccut\u201d can differ from the ground truth timestamp by +\/- 3 seconds. Ultimately, as detecting \u201ccut\u201d is an auxiliary task for finding the ending timestamp of a scene, being a few seconds off has a negligible effect as it is expected the \u201cto archive\u201d section will retain a few seconds before and after the precise scene.<\/p>\n<h2>Final Solution: The Scoring Pipeline<\/h2>\n<p>Our final solution consolidates the \u201caction\u201d event detection, clapperboard metadata extraction, and \u201ccut\u201d utterance detection work into a multi-model batch scoring pipeline deployed through Azure Machine Learning. In Figure 5, we see a representation of the full scoring pipeline which includes the previously described workstreams, as well as a report compilation step which will be discussed further in this section.<\/p>\n<p><figure id=\"attachment_13877\" aria-labelledby=\"figcaption_attachment_13877\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_09.png\"><img decoding=\"async\" class=\"size-full wp-image-13877\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_09.png\" alt=\"Figure 9 - The multi-model scoring pipeline developed as the project solution.\" width=\"808\" height=\"878\" srcset=\"https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_09.png 808w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_09-276x300.png 276w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_09-768x835.png 768w\" sizes=\"(max-width: 808px) 100vw, 808px\" \/><\/a><figcaption id=\"figcaption_attachment_13877\" class=\"wp-caption-text\"><strong>Figure 5<\/strong>. The multi-model scoring pipeline developed as the project solution.<\/figcaption><\/figure><\/p>\n<p>The raw video data is passed from Azure Blob Storage into the vision and audio workstreams in parallel. The metadata extraction workstream relies on output from the vision workstream whereas the audio workstream acts independently. Once these three workstreams are complete, a final report compilation step is triggered. This final report builds upon the outputs from the vision, metadata extraction, and audio workstreams to provide timestamp ranges of \u201cto archive\u201d and \u201cto discard\u201d footage from the input video.<\/p>\n<p>In the following subsections, we tie together each workstream\u2019s contribution to the final solution.<\/p>\n<h2>Vision Workstream<\/h2>\n<p>In the vision workstream, the first step is the <strong>Frame Extraction Step<\/strong>. We use ffmpeg (fps = 1) and the same augmentation methods applied with the registered model during training parameters here that we carefully logged in the model registration step.<\/p>\n<p>Like in the training pipeline, we have a <strong>Custom Vision Step<\/strong> here that is used to predict whether the pictures extracted by the previous step contain a clapperboard or not.<\/p>\n<p>The <strong>Timestamp generation Step<\/strong> here requires additional attention as it is not enough to only get binary labels for the pictures extracted from the videos. We also produce \u201caction\u201d event timestamps. In fact, each picture represents one second of the video. Therefore, we get a sequence of seconds labeled with \u201cplain\u201d and \u201cclapperboard\u201d timestamps. For this purpose, we merge all the detected neighboring clapperboards into one event with the tolerance of 2 seconds. For example:<\/p>\n<ul>\n<li>\u201cclapperboard, clapperboard, clapperboard\u201d sequence will result in one \u201caction\u201d event with the first detected clapperboard timestamp marked as the resulting timestamp.<\/li>\n<li>\u201cclapperboard, plain, clapperboard\u201d sequence will result in one \u201caction\u201d event with the first detected clapperboard timestamp marked as the resulting timestamp, as we have a tolerance of 2 seconds defined.<\/li>\n<li>\u201cclapperboard, plain, plain, clapperboard\u201d sequence will result in two \u201caction\u201d events with the first detected clapperboard timestamp marked as the resulting timestamps respectively.<\/li>\n<\/ul>\n<p>Once the timestamps are ready, we feed them into the <strong>Final Report Compilation step <\/strong>to merge them with the events detected by the other workstreams.<\/p>\n<h2>Metadata Extraction<\/h2>\n<p>Once the vision workstream custom vision step completes, the metadata extraction workstream begins. This workstream extracts relevant metadata from the detected clapperboards, such as scene and take.<\/p>\n<p>As described in the vision workstream, clapperboards appear in the footage in a series of consecutive frames, leading to redundant images. By utilizing OCR to select the best clapperboard, we were able to:<\/p>\n<ul>\n<li>Reduce the number of calls made to the Azure <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Form Recognizer<\/a> cognitive service by 73%, effectively reducing the cost of utilizing the service.<\/li>\n<li>Reduce the time spent on predictions as we were feeding in less images to the cognitive service.<\/li>\n<li>Reduce time spent on proceeding steps that were dependent on the Azure <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Form Recognizer<\/a> step since they were processing less files.<\/li>\n<\/ul>\n<p>Utilizing OCR and a character-level frequency scoring function played a key role in the cost optimization for our operationalized multi-model service. In the context of WarnerMedia, the implementation of clapperboard selection allows them to effectively minimize cost as much as possible while delivering on their business needs. We have high confidence that this pairing can be utilized across a multitude of reels where we expect to see a large number and variety of clapperboard images.<\/p>\n<h2>Audio Workstream<\/h2>\n<p>In tandem with the vision workstream, the raw video data from Azure Blob Storage is passed into the audio workstream. The first step is to extract and process the audio in the same fashion as in the training pipeline for \u201ccut\u201d utterance detection.<\/p>\n<p>Like for the other workstreams, the scoring pipeline retrieves the latest \u2013 in this case, audio \u2013 model from the AML model registry with the tag \u201cstatus: production\u201d. The scoring pipeline then generates a csv of predictions as seen in Figure 6.<\/p>\n<p><figure id=\"attachment_13878\" aria-labelledby=\"figcaption_attachment_13878\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_10.png\"><img decoding=\"async\" class=\"size-full wp-image-13878\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_10.png\" alt=\"Figure 10 - CSV Scoring output from the audio workflow in the scoring pipeline.\" width=\"378\" height=\"300\" srcset=\"https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_10.png 378w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_10-300x238.png 300w\" sizes=\"(max-width: 378px) 100vw, 378px\" \/><\/a><figcaption id=\"figcaption_attachment_13878\" class=\"wp-caption-text\"><strong>Figure 6<\/strong>. CSV Scoring output from the audio workflow in the scoring pipeline.<\/figcaption><\/figure><\/p>\n<p>The \u201ccut\u201d utterance timestamps are then fed into the report compilation step to help identify the ends of takes, ultimately assisting in identifying portions of film as \u201cto archive\u201d or \u201cto discard\u201d.<\/p>\n<h2>Archival and Performance Report Generation<\/h2>\n<p>With the custom vision, metadata extraction, and audio workstreams complete, the final report compilation step can begin. This step consolidates the \u201caction\u201d event timestamps provided from the vision workstream and \u201ccut\u201d event timestamps provided from the audio workstream to identify portions of the input video as \u201cto archive\u201d or \u201cto discard\u201d (see Figure 7).<\/p>\n<p><figure id=\"attachment_13879\" aria-labelledby=\"figcaption_attachment_13879\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_11.png\"><img decoding=\"async\" class=\"size-full wp-image-13879\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_11.png\" alt=\"Figure 11 - Portions of the input footage are labeled as \u201cto archive\u201d or \u201cto discard\u201d depending on the \u201caction\u201d and \u201ccut\u201d events detected by the multi-model scoring pipeline. This example is for a single video from a larger input reel.\" width=\"1248\" height=\"286\" srcset=\"https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_11.png 1248w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_11-300x69.png 300w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_11-1024x235.png 1024w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_11-768x176.png 768w\" sizes=\"(max-width: 1248px) 100vw, 1248px\" \/><\/a><figcaption id=\"figcaption_attachment_13879\" class=\"wp-caption-text\"><strong>Figure 7<\/strong>. Portions of the input footage are labeled as \u201cto archive\u201d or \u201cto discard\u201d depending on the \u201caction\u201d and \u201ccut\u201d events detected by the multi-model scoring pipeline. This example is for a single video from a larger input reel.<\/figcaption><\/figure><\/p>\n<p>The timestamps and labels for each input video are organized into a single final report json file. Following this, three thumbnails are generated for each detected \u201caction\u201d event to allow for easy review.<\/p>\n<p>In the below section, we go into detail on the benchmarks report compilation step.<\/p>\n<h3>Benchmark Report Compilation<\/h3>\n<p>One of the key objectives was to improve observability regarding pipeline performance and to automatically log metrics useful for cost estimation into a single, convenient report. This insight into compute costs and potential storage cost savings empowers business executives to make informed decisions regarding the archiving process.<\/p>\n<p>The PipelineBenchmarker is a lightweight and generalizable framework that enables automatic logging of metrics relevant to pipeline performance evaluation. While existing tools built-in to Azure Machine Learning enable ML model metric tracing, this framework focuses on metrics relevant to resource decision making.<\/p>\n<p><figure id=\"attachment_13880\" aria-labelledby=\"figcaption_attachment_13880\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_12.png\"><img decoding=\"async\" class=\"size-full wp-image-13880\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_12.png\" alt=\"Figure 12 - The Pipeline Benchmarking framework can be applied to existing Azure Machine Learning pipelines. Only a few additional lines of code are needed per pipeline step and the addition of a final benchmark report generation step.\" width=\"624\" height=\"356\" srcset=\"https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_12.png 624w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_12-300x171.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/a><figcaption id=\"figcaption_attachment_13880\" class=\"wp-caption-text\"><strong>Figure 8<\/strong>. The Pipeline Benchmarking framework can be applied to existing Azure Machine Learning pipelines. Only a few additional lines of code are needed per pipeline step and the addition of a final benchmark report generation step.<\/figcaption><\/figure><\/p>\n<p>By tracking values such as compute configuration (e.g., compute target name tied to specific AML cluster size and type), number of nodes used, and the time to complete each step and the total pipeline, we gained a clear understanding of (1) what steps are the most computationally heavy and (2) what parameters and compute configurations could be optimized for either cost or speed.<\/p>\n<h4>Azure Cognitive Services Consumption<\/h4>\n<p>In addition to basic compute configuration and duration benchmarks, we were interested in logging Azure Cognitive Services consumption throughout our solution pipeline for cost estimation. As described above, the final scoring pipeline solution consists of an audio workstream which calls the Custom Speech service and a vision workstream which calls the Custom Vision, OCR, and Form Recognizer services.<\/p>\n<p>These Cognitive Services consumption metrics written to the final benchmark report provide the customer with an understanding of approximate cost and allow them to estimate future costs. This also allows them to break down the costs by service called, which is helpful in cases like ours where one service (i.e., Form Recognizer) is notably more expensive.<\/p>\n<p>Figure 9 below displays the total number of hours spent running the entire MLOps solution. In the figure, you will notice that the number of API calls made to the <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Azure<\/a> Form Recognizer are significantly much less than the number of calls made to the OCR service. Furthermore, time spent running the <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\">Azure Form Recognizer<\/a> step was less than that of the Clapperboard Selection step (OCR step). This was a great improvement given that on average,<strong> the custom model trained in <\/strong><a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/form-recognizer\/\"><strong>Azure Form Recognizer<\/strong><\/a><strong> takes around 3 or 4 times longer than the <\/strong><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/computer-vision\/concept-recognizing-text#:~:text=The%20Computer%20Vision%20Read%20API%20is%20Azure's%20latest,images%20and%20multi-page%20PDF%20documents%20with%20mixed%20languages.\"><strong>Azure Cognitive Services Computer Vision Read API<\/strong><\/a><strong> to process an image file.<\/strong><\/p>\n<p><figure id=\"attachment_13881\" aria-labelledby=\"figcaption_attachment_13881\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_13.png\"><img decoding=\"async\" class=\"size-full wp-image-13881\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_13.png\" alt=\"Figure 13 - Screenshot describing pipeline run time and frequency of Cognitive Service calls.\" width=\"462\" height=\"200\" srcset=\"https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_13.png 462w, https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2021\/09\/ArchiveFootageDeepDive_Figure_13-300x130.png 300w\" sizes=\"(max-width: 462px) 100vw, 462px\" \/><\/a><figcaption id=\"figcaption_attachment_13881\" class=\"wp-caption-text\"><strong>Figure 9<\/strong>. Screenshot describing pipeline run time and frequency of Cognitive Service calls.<\/figcaption><\/figure><\/p>\n<h4>Labeling Production Footage for Discard<\/h4>\n<p>Building upon the basic pipeline benchmarking framework, we also log data addressing our main goal of identifying discardable footage.<\/p>\n<p>The input to the pipeline is a directory of video files which are then split into audio and images by the pipeline to extract scenes, beginning with clapperboard image detection for \u201caction\u201d and ending with \u201ccut\u201d utterances from the director.<\/p>\n<p>We modify the benchmark report generation step such that the resultant report structure separates individual video metrics from aggregate metrics. For any individual video, information such as what percentage or duration to archive or discard is included alongside the path to a detailed report file containing the specific timestamps for these archive\/discard labels.<\/p>\n<h4>Impact of the Benchmarking Framework<\/h4>\n<p>This framework allows the user to easily evaluate the effect of compute configuration on step and whole pipeline duration, as well as log information relevant to cost estimation, including but not limited to Azure Cognitive Services consumption and storage costs.<\/p>\n<p>With the generated benchmark report, WarnerMedia was able to estimate potential storage cost savings of implementing this multi-model ML solution in labeling portions of production footage to review for discard.<\/p>\n<h2>Conclusion<\/h2>\n<p>In partnership with WarnerMedia, we developed an operationalized multi-model approach to identify discardable portions of digital dailies, at scale, to assist archivists in processing large reels of footage. Our solution utilizes various Azure Cognitive Services as well as custom code executed in the Azure Machine Learning platform to identify and label segments of digital dailies as \u201cto archive\u201d or \u201cto discard\u201d as part of a comprehensive scoring pipeline.<\/p>\n<p>While these models were trained and tested on the digital dailies provided to us, the solution itself is a generalizable approach and may aid in archiving efforts for many more films under WarnerMedia.<\/p>\n<p>Ultimately, our scoring pipeline was able to identify over an hour of discardable footage in the provided reel using the combined custom vision and audio approach, leading to a 44% reduction in the archival storage cost. Here, we have demonstrated that this Machine Learning-powered and automated approach can aid archivists in efficiently processing digital dailies while preserving footage of interest for any given film.<\/p>\n<h2>Acknowledgements<\/h2>\n<p>Thank you to everyone involved in this collaboration between Microsoft CSE and WarnerMedia.\u00a0Special thanks to Michael Green and David Sugg from WarnerMedia.<\/p>\n<p>Contributors to the solution from the Microsoft team listed in alphabetical order by last name: Sergii\u00a0Baidachnyi, Andy Beach, Kristen DeVore, Daniel Fatade, Geisa Faustino, Moumita Ghosh, Vlad Kolesnikov, Bryan Leighton, Vito Flavio Lorusso, Patty Ryan, Samuel Mendenhall, Simon Powell, Sean Takafuji, Yana Valieva, and Nile Wilson.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Movies and TV shows require multiple takes per scene and may have a substantial amount of archival footage as a result. Here, we use Azure Cognitive Services and custom code to develop a multi-model Machine Learning (ML) solution to automatically detect discardable footage to save media companies manual archiving hours and storage space.<\/p>\n","protected":false},"author":43597,"featured_media":13887,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[14,1,19],"tags":[60,81,127,239,250,268],"class_list":["post-13823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cognitive-services","category-cse","category-machine-learning","tag-azure","tag-azure-machine-learning-ml-studio","tag-computer-vision","tag-machine-learning-ml","tag-microsoft-cognitive-services","tag-natural-language-processing"],"acf":[],"blog_post_summary":"<p>Movies and TV shows require multiple takes per scene and may have a substantial amount of archival footage as a result. Here, we use Azure Cognitive Services and custom code to develop a multi-model Machine Learning (ML) solution to automatically detect discardable footage to save media companies manual archiving hours and storage space.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/posts\/13823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/users\/43597"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/comments?post=13823"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/posts\/13823\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/media\/13887"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/media?parent=13823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/categories?post=13823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/tags?post=13823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}