Helper Utilities#

Input Helper#

Input helper is a tool to help user import list of images into the sample set from filesystem or add image into sample at inference.

void visionflow::helper::add_image_to_sample(ISample &sample, const Image &image, const std::string &input_tool_id, bool with_fingerprint = false, size_t thumbnail_long_side = 0)#

Add an image into the sample with the given Input tool id. This is just a user-friendly helper function, which is a simple encapsulation of the ISample interface. Users can also achieve the functionality provided by this function through the interface of the Sample object themselves, as shown in the code example below:

sample.get_or_create<props::Image>({input_tool_id, "image"})
    ->set_image(image);
sample
    .get_or_create<props::ViewList>({input_tool_id, "views"})
    ->add(
        TaggedView{{geometry::Matrix3f(1), geometry::Size2f{image.size()}}});
sample
    .get_or_create<props::RawImageInfo>(
        {input_tool_id, "image_info"})
    ->set_info_from_image(image, with_fingerprint, thumbnail_long_side);
Parameters:
  • sample – The sample to add the image into.

  • image – image to be added in.

  • input_tool_id – The Input tool id.

  • with_fingerprint – Save the image fingerprint or not. Typically, when importing images into the project, you should set this parameter to True. When deploying to a production environment, you can set this parameter to False to skip computing image fingerprints and improve speed.

  • thumbnail_long_side – The thumbnail long side length. If not specified, the thumbnail size will be zero and the thumbnail image will be empty.

struct InputHelperOptions#

The options for InputHelper.

Public Members

std::string sample_set_name = {}#

The name of sample_set, which will be the name of the main dataset of the project when it is empty or using the default value.

std::string input_tool_id = {}#

The Input tool name. If set to empty or using the default value, the importer will automatically look for the name of the Input tool in the project. If there is no Input tool or multiple Input tools in the project, an exception will be thrown. If the given tool name is not empty, you need to ensure that the tool exists and its type is “Input”, otherwise an exception will also be thrown.

bool auto_deduplication = true#

Whether to remove duplicate images automatically. When this option is set to true, the InputHelper will automatically removes duplicate images that are identical based on the fingerprint of the image, and images that have been previously imported into the dataset will not be re-imported too.

util::IProgressCallback *callback = nullptr#

The progress callback for importing the image.

size_t parallel_size = 0#

The number of threads to import images in parallel. The default value is 0. When set to 0, the executor will make an intelligent decision on the number of threads to parallelize. Generally, the default value of 0 is sufficient.

Tags tags = {}#

All samples imported by the InputHelper will be tagged with the given tags.

class InputHelper#

Utility for helping importing images into Input tool.

The common usage:

visionflow::helper::InputHelperOptions options;
options.input_tool_id = "InputTool";
visionflow::helper::InputHelper helper(project_ptr, options);
helper.add_images({image_files_path});
receipts = helper.commit();
for(const auto &receipt : receipts) {
    if(!receipt.is_success) {
        std::cout << receipt.error_message << std::endl;
    }
}
Get more option details in the InputHelperOptions.

Public Functions

const InputHelperOptions &options() const#

Get the final options information.

Returns:

const InputHelperOptions&

void add_image(const std::string &image_file)#

Record the image you want to add.

Parameters:

image_file – An image of a file

void add_image(const std::vector<std::string> &image_files)#

Record the image you want to add.

Parameters:

image_files – An image of multiple files

void add_images(const std::vector<std::string> &images_files)#

Record the images you want to add.

Parameters:

images_files – Multiple images, each consisting of a file.

void add_images(const std::vector<std::vector<std::string>> &images_files)#

Record the images you want to add.

Parameters:

images_files – Multiple images composed of multiple files.

const std::vector<InputHelper::Receipt> &commit()#

Adds the currently recorded image to input tool.

Note

1.The image needs to meet the input parameter requirements. 2.When an image is added, channel 4 is converted into channel 3 and channel 2 is converted into channel 1.

Returns:

const std::vector<InputHelper::Receipt>& Receipt information returned after importing the images, ordered by the order in which the images were added.

struct Receipt#

Receipt information returned after importing the images.

Public Members

std::vector<std::string> image_files#

File path in image.

bool is_success = false#

Check whether the image is successfully imported.

uint32_t sample_id#

Import image returns sample_id, if failed sample_id is 0.

std::string error_message#

Error infomation, json format, always contains “type” and “message” fields.

some common error will be like:

  1. The image is duplicated with someone in the dataset or add same image multiple times:

    {
        "type": "ImageDuplicated",
        "message": "The image already exists in the dataset.",
        "duplicate_sample": 123
    }
    
    Note that the “duplicate_sample” field will be 0 if the image is duplicated with someone added into this InputHelper instance multiple times.

  2. The image visual size is not match with the parameter requirements:

    {
        "type": "InvalidImageVisualSize",
        "message": "The visual_size is required to be {}, but get {}."
    }
    

  3. Other errors, always contains “type” and “message” fields.

LabelImg and LabelMe#

class LabelImg#

Public Functions

props::PolygonRegionList regions()#

Get LabelImg regions.

Returns:

props::PolygonRegionList

class LabelMe#

Public Functions

props::PolygonRegionList regions()#

Get LabelMe regions.

Returns:

props::PolygonRegionList

GPU Device Information#

We provide some interface to help to get the GPU information.

struct GpuDriverInfo#

The structure of GPU driver information.

Public Members

std::string driver_version#

The GPU driver version.

std::string nvml_version#

NVML library version.

struct GpuDeviceConstInfo#

The constant information of a gpu device, and you can get them only once as it will not be changed in running time.

Public Members

size_t device_id#

The device id, start from 0.

std::string device_name#

The gpu name, such as “GeForce GTX 1060 Ti”.

std::string architecture#

The GPU architecture, one of [Kepler, Maxwell, Pascal, Volta, Turing, Ampere, Ada, Unkown].

std::string driver_mode#

The gpu driver mode, the value should be one of “TCC”(Tesla Compute Cluster) and “WDDM”(Windows Display Driver Model).

Note

Only available on Windows, it will be empty on linux.

size_t core_count#

The gpu core count.

size_t total_memory#

Total available gpu memory.

struct GpuDeviceDynamicInfo#

The dynamic information of a gpu device, which will be changed in the running time.

GpuDriverInfo visionflow::helper::get_gpu_driver_info()#

Get GPU device information.

Returns:

GpuDriverInfo

std::vector<GpuDeviceConstInfo> visionflow::helper::get_gpu_device_const_info()#

Get the gpu device const information, include the gpu id, name and memory, etc.

Returns:

std::vector<GpuDeviceConstInfo> The vector of gpu device information, each element represent a gpu device.

std::vector<GpuDeviceDynamicInfo> visionflow::helper::get_gpu_device_dynamic_info()#

Get the gpu device dynamic information. such as memory usage, etc.

Returns:

std::vector<GpuDeviceDynamicInfo> The vector of gpu device information.