Abstract

The DIGITS Tutorial provides step-by-step instructions for writing a custom plugin.

1. Overview of DIGITS

The NVIDIA® Deep Learning GPU Training System (DIGITS™) puts the power of deep learning into the hands of engineers and data scientists.

DIGITS is not a framework. DIGITS is a wrapper for Caffe, Torch, and TensorFlow; which provides a graphical web interface to those frameworks rather than dealing with them directly on the command-line.

DIGITS can be used to rapidly train highly accurate deep neural network (DNNs) for image classification, segmentation, object detection tasks, and more. DIGITS simplifies common deep learning tasks such as managing data, designing and training neural networks on multi-GPU systems, monitoring performance in real time with advanced visualizations, and selecting the best performing model from the results browser for deployment. DIGITS is completely interactive so that data scientists can focus on designing and training networks rather than programming and debugging.

2. Writing a DIGITS Plugin

DIGITS supports ingesting data from a limited number of data sources (list of supported image file formats).

DIGITS data plug-ins enable a mechanism by which you can extend DIGITS to ingest data from custom sources.

Likewise, DIGITS offers a number of model output visualization types such as Image Classification, Object Detection or Image Segmentation. DIGITS visualization plug-ins make it possible to visualize the output of non-standard models.

This section walks you through the process of adding your own plugin.

2.1. Reading Data from DICOM Files

In this example, we will implement a data plugin for image segmentation that reads images from DICOM files and their ground-truth from text files. This plugin has already been featured in the medical imaging example. This plugin is referred to as the Sunnybrook plugin, from the name of the corresponding dataset. The full code is available here.

DIGITS may use a data plugin in the following situations:
  • when creating a new dataset, in order to create a database,
  • when performing inference, in order to feed data to a model.
Note: Most of the concepts we need to understand to create a data plugin also apply to writing visualization plugins.

Upon installation of the plugin, DIGITS begins to show a corresponding menu on the main page. For example:

Figure 1. DIGITS main page DIGITS main page

Optionally, if your data module has indicated that it can also ingest data during inference, you will see a Visualization Options menu on the model page.

2.1.1. Data Plugin File Tree

Below is an example file tree for a data plugin:
sunnybook/
├── digitsDataPluginSunnybrook/
│   ├── templates
│   │   ├── dataset_template.html
│   │   └── inference_template.html
│   ├── __init__.py
│   ├── data.py
│   └── forms.py
├── MANIFEST.in
└── setup.py

In the following sections, each of the important files are defined which need to be created in order to write a plugin.

2.1.1.1. setup.py

The setup.py file specifies how to install the plugin. The main section of interest here is the invocation of the setup command from setuptools package:
setup(
    name="digits_sunnybrook_data_plugin",
    version="0.0.1",
    author="Greg Heinrich",
    description=("A data ingestion plugin for the Sunnybrook cardiac dataset"),
    long_description=read('README'),
    license="Apache",
    packages=find_packages(),
    entry_points={
        DIGITS_PLUGIN_GROUP: [
        'class=digitsDataPluginSunnybrook:DataIngestion',
        ]},
    include_package_data=True,
    install_requires=['pydicom'],
)

Upon installation, the Python package will export entry points (entry_points). The sample code is assigning the DataIngestionclass from the digitsDataPluginSunnybrook package to the DIGITS_PLUGIN_GROUP entry point group. This will make it possible for DIGITS to discover installed plugins on startup.

In the install_requires argument we specify the list of Python package dependencies for this plugin. In this case, the plugin requires the pydicom package.

2.1.1.2. MANIFEST.in

The MANIFEST.in file specifies the resource files to include in the plugin package. In this sample, we are recursively including all .html files within the digitsDataPluginSunnybrook folder. If you are writing your own plugin, ensure these files are located inside the package folder.
recursive-include digitsDataPluginSunnybrook *.html

2.1.1.3. init.py

The digitsDataPluginSunnybrook/init.py file indicates that the digitsDataPluginSunnybrook folder is a Python package. In most cases, the digitsDataPluginSunnybrook folder can be left empty. In our case, because we are creating a shortcut to the DataIngestion member of data.py file, we can refer to it as digitsDataPluginSunnybrook:DataIngestion in the setup.py file.

2.1.1.4. data.py

The digitsDataPluginSunnybrook/data.py file implements a DataIngestion class, which implements a DIGITS data extension database (interface.py). Ensure you review the interface API and its docstrings.

The DataIngestion class is the only interface between DIGITS and the Sunnybrook plugin. Familiarize yourself with the interface for details about the required methods to implement in this class. The most important ones are:
get_dataset_form
This is a static method that returns a form (a child of flask.ext.wtf.Form) which contains all the fields required to create a dataset. For example, a form may include text fields to allow users to specify file names or various dataset options.
get_dataset_template
This is a static method that returns a Jinja template for the form to display in the DIGITS web user interface; this method also returns a dictionary of context variables that should include all the variables that are referenced in the Jinja template. For example, the Sunnybrook plugin provides the form as context because the Jinja template references this variable to render the form into the web user interface.
get_inference_form
This is similar to get_dataset_form but this is used when showing data ingestion options during inference.
Note: This method may return None to indicate that your data plugin cannot be operated during inference. In this case, it is expected that the regular image inference option in DIGITS will work for the model you are training.
get_inference_template
This is similar to get_dataset_template but this is used during inference.
__init__
This is the initialization routine used to create an instance of the class. During initialization this is provided with two parameters. The first parameter is named is_inference_db and indicates whether this instance is going to be used during inference. The second parameter is a dictionary that contains all the form fields that were specified by the user either during the dataset creation or when specifying data options for inference.
itemize_entries
This method parses form fields in order to generate a list of data sample identifiers. For example, if your data plugin needs to encode all the files in a directory, then the itemized entries could be a list of all the filenames.
encode_entry
This method is the core of the data plugin. It reads data associated with one of the identifiers returned in itemize_entries and converts the data into a 3-dimensional NumPy array. This function also returns a label, which may be either a scalar or another 3-dimensional NumPy array. Note: The process of reading an image in a DICOM file is relatively straightforward:
f = dicom.read_file(full_path)
img = f.pixel_array.astype(np.int)

2.1.1.5. form.py

The digitsDataPluginSunnybrook/form.py file is where we define:
  • the DatasetForm class to use to specify a dataset, and
  • optionally, the InferenceForm class to specify inference data

In the Sunnybrook example, instances of these classes are created and returned in DataIngestion:get_dataset_form and DataIngestion:get_inference_form, respectively. These classes are children of flask.ext.wtf.Form. For more information, see WTForms doc.

2.1.1.6. dataset_template.py

The digitsDataPluginSunnybrook/templates/dataset_template.py file is a Jinja template that defines what you will see in the Web user interface. For more information, see Jinja doc.
Note: The Sunnybrook template references the form variable which was given as context in DataIngestion:get_dataset_template. For example:
{{ form.image_folder.label }}

2.1.1.7. inference_template.py

The digitsDataPluginSunnybrook/templates/inference_template.py file is the Jinja template to show inference data options.

2.1.2. Installing the Plugin

In order to install the plugin, you need to run the following command from the directory that includes your data plugin setup.py file.
$ pip install .
Next, restart DIGITS for the changes to take effect.

Your plugin is installed.

2.2. Visualization Plugin

Visualization plugins work in a similar way as data plugins. The main difference is that visualization plugins implement the view interface. Refer to the inline docstrings in this file for more information on usage.

3. Troubleshooting

3.1. Support

For the latest Release Notes, see the DIGITS Release Notes Documentation website.

For more information about DIGITS, see:
Note: There may be slight variations between the NVIDIA-docker images and this image.

Notices

Notice

THE INFORMATION IN THIS GUIDE AND ALL OTHER INFORMATION CONTAINED IN NVIDIA DOCUMENTATION REFERENCED IN THIS GUIDE IS PROVIDED “AS IS.” NVIDIA MAKES NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE INFORMATION FOR THE PRODUCT, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. Notwithstanding any damages that customer might incur for any reason whatsoever, NVIDIA’s aggregate and cumulative liability towards customer for the product described in this guide shall be limited in accordance with the NVIDIA terms and conditions of sale for the product.

THE NVIDIA PRODUCT DESCRIBED IN THIS GUIDE IS NOT FAULT TOLERANT AND IS NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE IN CONNECTION WITH THE DESIGN, CONSTRUCTION, MAINTENANCE, AND/OR OPERATION OF ANY SYSTEM WHERE THE USE OR A FAILURE OF SUCH SYSTEM COULD RESULT IN A SITUATION THAT THREATENS THE SAFETY OF HUMAN LIFE OR SEVERE PHYSICAL HARM OR PROPERTY DAMAGE (INCLUDING, FOR EXAMPLE, USE IN CONNECTION WITH ANY NUCLEAR, AVIONICS, LIFE SUPPORT OR OTHER LIFE CRITICAL APPLICATION). NVIDIA EXPRESSLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR SUCH HIGH RISK USES. NVIDIA SHALL NOT BE LIABLE TO CUSTOMER OR ANY THIRD PARTY, IN WHOLE OR IN PART, FOR ANY CLAIMS OR DAMAGES ARISING FROM SUCH HIGH RISK USES.

NVIDIA makes no representation or warranty that the product described in this guide will be suitable for any specified use without further testing or modification. Testing of all parameters of each product is not necessarily performed by NVIDIA. It is customer’s sole responsibility to ensure the product is suitable and fit for the application planned by customer and to do the necessary testing for the application in order to avoid a default of the application or the product. Weaknesses in customer’s product designs may affect the quality and reliability of the NVIDIA product and may result in additional or different conditions and/or requirements beyond those contained in this guide. NVIDIA does not accept any liability related to any default, damage, costs or problem which may be based on or attributable to: (i) the use of the NVIDIA product in any manner that is contrary to this guide, or (ii) customer product designs.

Other than the right for customer to use the information in this guide with the product, no other license, either expressed or implied, is hereby granted by NVIDIA under this guide. Reproduction of information in this guide is permissible only if reproduction is approved by NVIDIA in writing, is reproduced without alteration, and is accompanied by all associated conditions, limitations, and notices.

Trademarks

NVIDIA, the NVIDIA logo, and cuBLAS, CUDA, cuDNN, cuFFT, cuSPARSE, DIGITS, DGX, DGX-1, Jetson, Kepler, NVIDIA Maxwell, NCCL, NVLink, Pascal, Tegra, TensorRT, and Tesla are trademarks and/or registered trademarks of NVIDIA Corporation in the Unites States and other countries. Other company and product names may be trademarks of the respective companies with which they are associated.