Hello everyone. I have implemented a custom cnn using libtorch. Here is it:
class ConvnetImpl : public torch::nn::Module
{
private:
torch::nn::Sequential model;
public:
ConvnetImpl()
{
model = torch::nn::Sequential(
torch::nn::Conv2d(torch::nn::Conv2dOptions(/input channel/ 1, /output channel/ 16, /kernel_size=/3)),
torch::nn::ReLU(true),
torch::nn::MaxPool2d(torch::nn::MaxPool2dOptions(/kernel/ {3, 3}).stride({2, 2})),
torch::nn::Conv2d(torch::nn::Conv2dOptions(/*input channel*/ 16, /*output channel*/ 32, /*kernel_size=*/3)),
torch::nn::ReLU(true),
torch::nn::MaxPool2d(torch::nn::MaxPool2dOptions(/*kernel*/ {3, 3}).stride({2, 2})),
torch::nn::Conv2d(torch::nn::Conv2dOptions(/*input channel*/ 32, /*output channel*/ 64, /*kernel_size=*/3)),
torch::nn::ReLU(true),
torch::nn::MaxPool2d(torch::nn::MaxPool2dOptions(/*kernel*/ {3, 3}).stride({2, 2})),
torch::nn::Conv2d(torch::nn::Conv2dOptions(64, 128, 3)),
torch::nn::ReLU(true),
torch::nn::MaxPool2d(torch::nn::MaxPool2dOptions(/*kernel*/ {3, 3}).stride({2, 2}))
);
register_module("convnet", model);
};
torch::Tensor forward(torch::Tensor &input_image)
{
torch::Tensor features = model->forward(input_image);
features = features.permute({0, 2, 3, 1}); //(batch_size, height, width, features)
return features;
}
};
TORCH_MODULE(Convnet);
How can i extract the output of each conv layers and visualize it ?