Converted Network Usage - DigitalMediaProfessionals/dv-sdk GitHub Wiki

This chapter shows how to use a converted network in your application.

How to use network in your application

Here is the short example of CaffeMobileNet. Typically, one only needs to follow these steps to run a converted network:

#include "CaffeMobileNet_gen.h"
// Define and initialize the network object
CCaffeMobileNet network;
if (!network.Initialize())
  return -1;
if (!network.LoadWeights(FILENAME_WEIGHTS))
  return -1;
if (!network.Commit())
  return -1;

// Get input buffer address
void* ddr_buf_a_cpu = network.get_network_input_addr_cpu();

// Copy image data to input buffer @1
memcpy(ddr_buf_a_cpu, imgProc, IMAGE_W * IMAGE_H * 3 * 2);

// Running the network
network.RunNetwork();

// Get the result
std::vector<float> networkOutput;
network.get_final_output(networkOutput);

Note: It is not guaranteed an input buffer is not changed after network.RunNetwork().

Note: some networks may have more than one output buffers. In this case, one need to pass the index as the secondary parater to get_final_output() method, as follows:

// Get number of network output layers
count = network.get_output_layer_count();
//...
network.get_final_output(networkOutput, index);

The generated doxygen document will also give informations of index and output buffer mapping.

See Network API for details of the each functions.

Build an application

This section shows how to build your application which uses network with an example of dv-sdk/application/CaffeMobileNet of sample applications.

The CaffeMobileNet application mainly consists of CaffeMobileNet_gen.cpp (network part) and mobileNet.cpp (application part). In addition, CaffeMobileNet_gen.cpp depends on dv-sdk/application/common/src/dmp_network.cpp. Therefore you can build the application by compiling these three sources and linking them. Of course, you can make the application by building shared libraries for each sources as the sample application does.

On compiling each source code, please make the compiler include header files of SDK user-space driver and dmp_network.h by specifying options such as -I../common/include. CaffeMobileNet_gen.cpp and dmp_network.cpp depends on dmp_network.h and headers of the driver respectively. You can build the application by linking the object files with linker option such as -ldmpdv to enable SDK user-space driver linked dynamically, after the compilation.

⚠️ **GitHub.com Fallback** ⚠️