mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
torch::nn::FractionalMaxPool{2,3}d module and functional
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/29933 Test Plan: Imported from OSS Differential Revision: D18548174 Pulled By: yf225 fbshipit-source-id: 070776db6e8b7ad94d9b7cbd82b3d6966f061a46
This commit is contained in:
committed by
Facebook Github Bot
parent
ec52d911bd
commit
bb1d9b238d
@@ -147,6 +147,48 @@ TEST_F(FunctionalTest, AvgPool3d) {
|
||||
ASSERT_EQ(y.sizes(), std::vector<int64_t>({2, 2, 2, 2}));
|
||||
}
|
||||
|
||||
TEST_F(FunctionalTest, FractionalMaxPool2d) {
|
||||
auto x = torch::ones({2, 5, 5});
|
||||
auto y = F::fractional_max_pool2d(x, F::FractionalMaxPool2dFuncOptions(3).output_size(2));
|
||||
|
||||
ASSERT_EQ(y.ndimension(), 3);
|
||||
ASSERT_TRUE(torch::allclose(y, torch::ones({2, 2, 2})));
|
||||
ASSERT_EQ(y.sizes(), std::vector<int64_t>({2, 2, 2}));
|
||||
|
||||
auto y_with_indices = F::fractional_max_pool2d_with_indices(x, F::FractionalMaxPool2dFuncOptions(3).output_size(2));
|
||||
ASSERT_TRUE(torch::equal(y, std::get<0>(y_with_indices)));
|
||||
ASSERT_TRUE(torch::allclose(
|
||||
std::get<1>(y_with_indices),
|
||||
torch::tensor({{{ 0, 2},
|
||||
{10, 12}},
|
||||
{{ 0, 2},
|
||||
{10, 12}}})));
|
||||
ASSERT_EQ(std::get<1>(y_with_indices).sizes(), std::vector<int64_t>({2, 2, 2}));
|
||||
}
|
||||
|
||||
TEST_F(FunctionalTest, FractionalMaxPool3d) {
|
||||
auto x = torch::ones({2, 5, 5, 5});
|
||||
auto y = F::fractional_max_pool3d(x, F::FractionalMaxPool3dFuncOptions(3).output_size(2));
|
||||
|
||||
ASSERT_EQ(y.ndimension(), 4);
|
||||
ASSERT_TRUE(torch::allclose(y, torch::ones({2, 2, 2, 2})));
|
||||
ASSERT_EQ(y.sizes(), std::vector<int64_t>({2, 2, 2, 2}));
|
||||
|
||||
auto y_with_indices = F::fractional_max_pool3d_with_indices(x, F::FractionalMaxPool3dFuncOptions(3).output_size(2));
|
||||
ASSERT_TRUE(torch::equal(y, std::get<0>(y_with_indices)));
|
||||
ASSERT_TRUE(torch::allclose(
|
||||
std::get<1>(y_with_indices),
|
||||
torch::tensor({{{{ 0, 2},
|
||||
{10, 12}},
|
||||
{{50, 52},
|
||||
{60, 62}}},
|
||||
{{{ 0, 2},
|
||||
{10, 12}},
|
||||
{{50, 52},
|
||||
{60, 62}}}})));
|
||||
ASSERT_EQ(std::get<1>(y_with_indices).sizes(), std::vector<int64_t>({2, 2, 2, 2}));
|
||||
}
|
||||
|
||||
TEST_F(FunctionalTest, LPPool1d) {
|
||||
int norm_type = 2;
|
||||
int stride = 2;
|
||||
|
||||
Reference in New Issue
Block a user