Developer’s Guide

Custom data types

All data types must define three interfaces:

template <typename T>
class

Public Functions

virtual nervana::interface::extractor::~extractor()
virtual std::shared_ptr<T> nervana::interface::extractor::extract(const void *, size_t) const
= 0
template <typename T, typename S>
class

Public Functions

virtual nervana::interface::transformer::~transformer()
virtual std::shared_ptr<T> nervana::interface::transformer::transform(std::shared_ptr<S>, std::shared_ptr<T>) const
= 0
template <typename T>
class

Public Functions

virtual nervana::interface::loader::~loader()
virtual void nervana::interface::loader::load(const std::vector<void *>&, std::shared_ptr<T>) const
= 0

and a configuration class inheriting from:

class

Inherits from nervana::json_configurable

Subclassed by nervana::audio::config, nervana::blob::config, nervana::boundingbox::config, nervana::char_map::config, nervana::image::config, nervana::label::config, nervana::label_map::config, nervana::loader_config, nervana::localization::rcnn::config, nervana::localization::ssd::config, nervana::provider_config, nervana::video::config

Public Functions

void nervana::interface::config::add_shape_type(const std::vector<size_t> &shape_, const std::string &output_type_)
void nervana::interface::config::add_shape_type(const std::vector<size_t> &shape_, const nervana::output_type &output_type_)
void nervana::interface::config::add_shape_type(const std::vector<size_t> &shape_, const std::vector<std::string> &names_, const nervana::output_type &output_type_)

The config should probably make use of the following three macros to define the entries that make up the configuration options.

ADD_SCALAR(var, mode, ...)
ADD_IGNORE(var)
ADD_DISTRIBUTION(var, mode, ...)

For example, in nervana::video::config, the following snippet adds the appropriate config options for frame and max_frame_count:

std::vector<std::shared_ptr<interface::config_info_interface>> config_list = {
    ADD_SCALAR(max_frame_count, mode::REQUIRED),
    ADD_IGNORE(frame)
};

Then in the config method, these attributes are then added using the add_shape_type method:

config(nlohmann::json js) :
frame(js["frame"])
{
    if(js.is_null()) {
        throw std::runtime_error("missing video config in json config");
    }

    for(auto& info : config_list) {
        info->parse(js);
    }
    verify_config("video", config_list, js);

    // channel major only
    add_shape_type({frame.channels, max_frame_count, frame.height, frame.width},
                    frame.type_string);
    }