#include <torch/nn/init.h>
#include <torch/nn/modules/linear.h>
+#include <torch/nn/modules/conv.h>
#include <test/cpp/api/init_baseline.h>
#include <test/cpp/api/support.h>
double gain =
torch::nn::init::calculate_gain(torch::nn::init::Nonlinearity::LeakyReLU);
ASSERT_DOUBLE_EQ(gain, std::sqrt(2.0 / (1 + pow(0.01, 2))));
+}
+
+TEST(InitTest, CanInitializeCnnWithOrthogonal) {
+ torch::nn::Conv2d conv_layer(torch::nn::Conv2dOptions(3, 2, 3).stride(2));
+ torch::nn::init::orthogonal_(conv_layer->named_parameters()["weight"]);
}
\ No newline at end of file
"Only tensors with 2 or more dimensions are supported");
const auto rows = tensor.size(0);
- const auto columns = tensor.size(1);
+ const auto columns = tensor.numel() / rows;
auto flattened = torch::randn({rows, columns});
if (rows < columns) {
raise ValueError("Only tensors with 2 or more dimensions are supported")
rows = tensor.size(0)
- cols = tensor[0].numel()
+ cols = tensor.numel() // rows
flattened = tensor.new(rows, cols).normal_(0, 1)
if rows < cols: