1 #include <api/CPP/memory.hpp> 2 #include <api/CPP/topology.hpp> 3 #include <api/CPP/reorder.hpp> 4 #include <api/CPP/input_layout.hpp> 5 #include <api/CPP/convolution.hpp> 6 #include <api/CPP/data.hpp> 7 #include <api/CPP/pooling.hpp> 8 #include <api/CPP/fully_connected.hpp> 9 #include <api/CPP/softmax.hpp> 10 #include <api/CPP/engine.hpp> 11 #include <api/CPP/network.hpp> 15 using namespace cldnn;
21 conv1_out_channels = 20,
22 conv2_out_channels = 50,
55 cldnn::data conv1_weights(
"conv1_weights", conv1_weights_mem );
81 layout conv2_weights_layout(data_type,
format::bfyx,{ conv2_out_channels, conv1_out_channels, conv_krnl_size, conv_krnl_size });
121 void copy_to_memory(
memory& mem,
const vector<float>& src)
124 std::copy(src.begin(), src.end(), dst.begin());
137 auto output =
outputs.at(
"softmax").get_memory();
143 auto max_element_pos = max_element(out_ptr.begin(), out_ptr.end());
144 return static_cast<int>(distance(out_ptr.begin(), max_element_pos));
150 vector<float> load_data(
const string&) {
return{ 0 }; }
161 vector<float> load_image_bfyx(
const string&,
int,
int) {
return{ 0 }; }
173 {1, input_channels, input_size, input_size}
177 layout conv1_weights_layout(data_type,
format::bfyx,{ conv1_out_channels, input_channels, conv_krnl_size, conv_krnl_size });
178 vector<float> my_own_buffer = load_data(
"conv1_weights.bin");
180 auto conv1_weights_mem =
memory::attach(conv1_weights_layout, my_own_buffer.data(), my_own_buffer.size());
190 copy_to_memory(conv1_bias_mem, load_data(
"conv1_bias.bin"));
216 for (
auto img_name : {
"one.jpg",
"two.jpg" })
219 copy_to_memory(input_memory, load_image_bfyx(
"one.jpg", in_layout.
size.
spatial[0], in_layout.
size.
spatial[1]));
220 auto result = recognize_image(
network, input_memory);
221 cout << img_name <<
" recognized as" << result << endl;
std::map< primitive_id, network_output > execute(const std::vector< event > &dependencies={}) const
Executes network and returns the list of network_output.
void set_input_data(const primitive_id &id, const memory &mem) const
Provides memory for input_layout primitives defined by user in source topology.
Performs forward fully connected layer (inner product). Also supports built-in Relu cldnn_activation_...
data_types data_type
Data type stored in memory (see. data_types)
Changes how data is ordered in memory. Value type is not changed & all information is preserved...
Provides input data to topology.
mutable_array_ref< value_type > spatial
Spatial dimensions.
tensor size
The size of the memory (excluding padding)
static memory attach(const cldnn::layout &layout, T *ptr, size_t size)
User selected list of program outputs.
Performs "pooling" operation which is a form of non-linear down-sampling.
Network topology to be defined by user.
void add(PType const &desc)
Adds a primitive to topology.
static memory allocate(const engine &engine, const layout &layout)
Allocate memory on engine using specified layout.
int32_t value_type
Values type stored in tensor.
Converts C++ type to data_types .
Executable network allocated from program.
Normalizes results so they sum to 1.
Represents clDNN engine object.
Helper class to get an access memory data.
Represents buffer with particular layout.
static std::shared_ptr< const build_option > optimize_data(bool enable=false)
Enable implicit reordering for user inputs (default: false).
Performs forward spatial convolution with weight sharing. Also supports built-in Relu cldnn_activatio...