![]() |
NeuZephyr
Simple DL Framework
|
Reconstructs spatial tensors from column matrices generated by im2col transformation. More...
Public Member Functions | |
Col2ImgNode (Node *input, Tensor::size_type outputHeight, Tensor::size_type outputWidth) | |
Constructor for the Col2ImgNode class. | |
void | forward () override |
Performs the forward propagation operation in the Col2ImgNode. | |
void | backward () override |
Performs the backward propagation operation in the Col2ImgNode. | |
![]() | |
virtual void | print (std::ostream &os) const |
Prints the type, data, and gradient of the node. | |
void | dataInject (Tensor::value_type *data, bool grad=false) const |
Injects data into a relevant tensor object, optionally setting its gradient requirement. | |
template<typename Iterator > | |
void | dataInject (Iterator begin, Iterator end, const bool grad=false) const |
Injects data from an iterator range into the output tensor of the InputNode, optionally setting its gradient requirement. | |
void | dataInject (const std::initializer_list< Tensor::value_type > &data, bool grad=false) const |
Injects data from a std::initializer_list into the output tensor of the Node, optionally setting its gradient requirement. | |
Reconstructs spatial tensors from column matrices generated by im2col transformation.
This node performs the inverse operation of Img2ColNode, converting (N, 1, Hout*Wout, Cout) tensors back to (N, Cout, Hout, Wout) spatial format. Essential for gradient propagation in convolution operations and feature map reconstruction.
Core functionality and characteristics:
Key implementation aspects:
Typical use cases:
Critical considerations:
nz::nodes::calc::Col2ImgNode::Col2ImgNode | ( | Node * | input, |
Tensor::size_type | outputHeight, | ||
Tensor::size_type | outputWidth ) |
Constructor for the Col2ImgNode class.
input | A pointer to the input Node (host-to-object). This node provides the necessary input data for the Col2ImgNode. |
outputHeight | The height of the output image in size_type (host-to-object). |
outputWidth | The width of the output image in size_type (host-to-object). |
This constructor initializes a Col2ImgNode object. It sets the output height, width, and number of channels based on the input node's output shape. It then adds the input node to the list of input nodes. A new Tensor object is created for the output, with its shape determined by the batch size from the input node's output, the number of output channels, the specified output height, and width. The output tensor also inherits the gradient requirement from the input node's output. Finally, the node type is set to "Col2Img".
Memory management strategy: The constructor uses std::make_shared
to allocate memory for the output tensor. The memory will be automatically managed by the smart pointer, and it will be released when the last reference to the tensor is removed. Exception handling mechanism: There is no explicit exception handling in this constructor. However, if memory allocation for the output tensor fails, a std::bad_alloc
exception may be thrown.
std::bad_alloc | If memory allocation for the output tensor fails. |
|
overridevirtual |
Performs the backward propagation operation in the Col2ImgNode.
None |
This function conducts the backward propagation step for the Col2ImgNode. It first checks if the output tensor of the input node requires gradient computation. If it does, the function calls iCol2imgBackward
, passing the gradient tensor of the input node's output, the gradient tensor of the output, the output height, output width, output channels, and the batch size from the input node's output. The iCol2imgBackward
function is responsible for computing the gradients and propagating them back to the input.
Memory management strategy: This function does not allocate or deallocate any memory directly. It operates on the existing gradient tensors of the input and output. Exception handling mechanism: There is no explicit exception handling in this function. If the iCol2imgBackward
function encounters an error, it may throw an exception, and the specific type of exception depends on the implementation of iCol2imgBackward
.
[Exception | type from iCol2imgBackward] If the iCol2imgBackward function encounters an error during execution. |
iCol2imgBackward
function. If the iCol2imgBackward
function has a time complexity of O(n), where n is the number of elements in the input or output gradient tensors, then this backward propagation step also has a time complexity of O(n).Implements nz::nodes::Node.
|
overridevirtual |
Performs the forward propagation operation in the Col2ImgNode.
None |
This function executes the forward propagation step for the Col2ImgNode. It calls the iCol2img
function, passing the output tensor's data, the input node's output tensor's data, the output height, output width, output channels, and the batch size from the input node's output. The iCol2img
function is responsible for converting the column - formatted data from the input to image - formatted data in the output.
Memory management strategy: This function does not allocate or deallocate any memory directly. It operates on the existing data pointers of the input and output tensors. Exception handling mechanism: There is no explicit exception handling in this function. If the iCol2img
function encounters an error, it may throw an exception, but the nature of the exception depends on the implementation of iCol2img
.
[Exception | type from iCol2img] If the iCol2img function encounters an error during execution. |
iCol2img
function. If the iCol2img
function has a time complexity of O(n), where n is the number of elements in the input or output tensors, then this forward propagation step also has a time complexity of O(n).Implements nz::nodes::Node.