| On this page |
This workflow covers the full computer vision process within Houdini using the top_computervision.hip example file. This process allows you to take a video, isolate an object of interest, train a model on that dataset, and then run the model on the video to isolate that object throughout the video.
At a high level, the workflow within Houdini is:
-
In the video, mask out selected frames by hand using the Paint 3D COP or other DCC programs.
-
Use the
ML Preprocess Computer Vision TOP to create a dataset on disk.
-
Train the model using that dataset with
ML Train Computer Vision TOP.
-
Use
ML Computer Vision Inference COP to apply the trained data to the video, masking out the object of interest in the remaining frames.
Prerequisites ¶
Locate the $HH/help/files/pdg_examples/top_computervision folder. You will find a top_computervision.hip file for Houdini and an input.mp4 as the video source.
If you want to use your own sources, you need:
-
A video source or image sequence that has a target object of interest.
-
A method to create a mask for selected frames. This can be done within Houdini or in another DCC program.
Preparing your images ¶
The first step is to mask out your object of interest from the video. The goal is to create enough examples for the model to learn from the object without hand masking the full video.
-
Before selecting your training frames, you may want to clean up the source footage. For example, crop out black borders or other unwanted image artifacts so the model trains on the actual content you want to detect.
-
Select a number of frames relative to your video length. In the example, the video is 10 seconds at 30fps and has 300 frames. A rough recommendation is to mask out at least 10 of these frames by hand to create a better and more accurate dataset.
-
Choose frames that represent a good range of cases the training model will see in the next stage. Good examples include frames where the object appears from different angles, close to the edge of the frame, or slightly cutoff.
-
The masks do not need to be a perfect one-to-one match to the object of interest. In the example, you can see the logo is roughly masked out using a brush stroke.
-
To prepare your images, you can use a node like
Paint 3D COP or a DCC software.
In the example file, open the training_data geometry node, then the copnet1 COP Network.
-
The
input.mp4file is connected to a batch of Time Shift COP node node to select the desired frames for the training stage.-
These frames are then masked out using a Paint 3D COP node at the position of the object of interest.
-
Preprocess for dataset generation ¶
The ML Preprocess Computer Vision TOP prepares image datasets for the computer vision training tasks. It prepares a
.json file that uses the same format as the COCO dataset to represent the images, sizes, and masks. The generated dataset folder that contains the source images, mask images, and COCO .json. These can then be trained using the ML Train Computer Vision TOP.
To generate a dataset:
-
In the example file, locate the
topnetTOP network. Then the Preprocess Computer Vision TOP node. -
Set the Object Classes. The example uses
Logoas the class for the blurred out logo.-
The Class Color is an optional setting and is more for visualization purposes.
-
-
Choose how to Input Images. There are multiple methods to input images such as dictionary attributes, multi-aov EXRs, and COP nodes. See Input Format for more information.
-
The example uses the
COP Nodesas the Input Source. The Source COP and Mask COP parameters point to the selected frames and masked out frames.
-
-
Set your Evaluating Using option. This example uses a Custom Range which allows for more control to set a single frame, frame range, or skip certain frames.
-
This can be useful to skip frames where your object of interest pans out of the camera in certain frames.
-
-
Cook the node.
-
Review the generated dataset folder.
-
It should contain the source images, mask images, and COCO format
.jsonfile. You will then use the generated dataset directory as the input dataset for the ML Train Computer Vision TOP node.
-
Train a Computer Vision model ¶
The ML Train Computer Vision TOP trains an object detection, masking, or keypoint detection model using a dataset prepared by the ML Preprocess Computer Vision TOP. This means the node uses the generated dataset folder including the COCO
.json, masks, and source images to train.
There are various parameters that change how your dataset is trained. You can read descriptions for each parameter in the node’s parameters section. Some of the tabs such as Checkpointing, Execution, and Schedulers are similar to other TOPs and ML nodes. Here’s a brief description of each tab:
Tab |
Description |
|---|---|
Data |
Defines the dataset directory, training output directory, image loading settings, input configuration, and input randomization. |
Network |
Controls the computer vision model setup. For most users, it’s recommended to choose a built-in preset using Pre-Trained Weights. Then use Download Weights if the preset weights are not already installed. |
Training |
Controls the training process including Max Epochs, log/config output, mixed precision, optimizer settings, and learning rate. |
Testing |
Controls validation and visual test output during training. Validation records numeric metrics, while testing generates image results that can be inspected in the Training Monitor. |
Checkpointing |
Controls PyTorch model checkpoints and ONNX export. The exported ONNX file is used later by the ML Computer Vision Inference COP node. |
Execution |
Controls the training runtime environment including Python/virtual environment settings, device selection, CPU thread count, and single work item training. |
Schedulers |
Controls PDG/TOP scheduling behavior, not the machine learning model itself. |
-
In the example file, locate the ML Train Computer Vision TOP node in the TOP network.
-
In the Input Data Source tab, you input your generated dataset from the previous stage here.
-
To get started, it’s recommended to use a pre-trained weight in the Network tab instead of setting things manually.
-
-
Cook the node.
-
Make sure you have your pre-trained weights downloaded or it may cause an error.
-
The results will be located in the folder specified in the Output Directory parameter. This folder contains the following:
config - Stores training configuration files and logs. Use it to inspect or reproduce the settings used for the run.
models - Stores model checkpoints and exported model files. PyTorch checkpoints can be used to resume or preserve training states. ONNX files are exported models that can be used for inference.
plots - Stores training-progress data used by the Training Monitor. These plots show values such as loss/error and validation metrics. This helps you judge whether training is improving.
tests - Stores visual test images generated during training. These images show what the model detected at different checkpoints making it easier to inspect false positives, missed objects, and overall model quality.
Validation outputs may also be written as CSV files. These store numerical validation metrics and are automatically detected by the Training Monitor.
Training monitor panel ¶
You can inspect the training progress using the PDG ML Training Monitor Panel or checking the output files on disk.
The monitor displays:
-
Loss and error graphs which should generally trend downwards towards zero.
-
Validation metrics which should improve upward over time.
-
Visual test results showing what the model detected at different training checkpoints.
Using the trained model: interactive or render to disk ¶
The example files provides two methods to use your trained data.
-
Use the
ROP Image Output TOP and
FFmpeg Encode Video TOP to render the inference result to disk.
-
Use the ML Computer Vision Inference COP interactively in Houdini.
These two methods use the same trained model and inference COP network. The difference is mainly where and how the result is viewed or written.
In the example TOP network, the _ROP Image Output TOP cooks the same inference COP network. The difference is that it runs the COP result as a PDG background task and writes the resulting frames to disk.
Then, the FFmpeg Encode Video TOP assembles those rendered frames into a final movie file, such as an .mp4.
Run inference on trained model using COPs ¶
The ML Computer Vision Inference COP applies an ONNX model trained using the ML Train Computer Vision TOP to detect and mask objects in an input image.
This is the final stage of the computer vision workflow. After the model has been trained and exported as an ONNX file, the inference COP applies that trained model back to the source video or image sequence to detect the target object in frames that were not manually masked.
-
In the example file, locate the
inferenceSOP network. Then select the ML Computer Vision Inference COP node.-
You can see a video or image sequence source is connected to the node. This is the same video generated using the FFMpeg method.
-
-
In the Model File parameter, select one of the
.onnxmodels generated in the earlier stages. -
Select the same Detect Type that matches the model. The example uses
Masks. -
Adjust the Minimum Confidence as needed.
-
This adjusts the minimum confidence value for detecting objects. Detections below this threshold will be discarded. If the confidence is too low, false positives may appear.
-
-
Set the display flag on the
blur1node.-
You can now see the video displayed in the viewport. Scrub the timeline to play back the video.
-