Added conv3d unit test
Signed-off-by: Chen Xin <jack.chen@verisilicon.com>
This commit is contained in:
parent
e9771746ba
commit
e62b62015d
|
|
@ -119,7 +119,7 @@ TEST(Conv3d, shape_1_1_2_3_3_float32_simple_cwhdn) {
|
|||
auto final_graph = tim::transform::LayoutInference(graph, ctx);
|
||||
|
||||
EXPECT_TRUE(final_graph.first->Compile());
|
||||
|
||||
|
||||
final_graph.second[input_tensor]->CopyDataToTensor(input_data.data());
|
||||
|
||||
EXPECT_TRUE(final_graph.first->Run());
|
||||
|
|
@ -133,4 +133,59 @@ TEST(Conv3d, shape_1_1_2_3_3_float32_simple_cwhdn) {
|
|||
for (uint32_t idx = 0; idx < golden.size(); idx++) {
|
||||
EXPECT_TRUE(std::abs(golden[idx] - output[idx]) < 0.01);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Conv3d, shape_4_2_2_2_1_float32_simple_whdcn) {
|
||||
auto ctx = tim::vx::Context::Create();
|
||||
auto graph = ctx->CreateGraph();
|
||||
|
||||
tim::vx::ShapeType input_shape({4, 2, 2, 2, 1}); //whdcn
|
||||
tim::vx::ShapeType weight_shape({2, 2, 2, 2, 2}); //whdIcOc
|
||||
tim::vx::ShapeType output_shape(
|
||||
{3, 1, 1, weight_shape[4], input_shape[4]}); //whdcn
|
||||
|
||||
tim::vx::TensorSpec input_spec(tim::vx::DataType::FLOAT32, input_shape,
|
||||
tim::vx::TensorAttribute::INPUT);
|
||||
tim::vx::TensorSpec weight_spec(tim::vx::DataType::FLOAT32, weight_shape,
|
||||
tim::vx::TensorAttribute::CONSTANT);
|
||||
tim::vx::TensorSpec output_spec(tim::vx::DataType::FLOAT32, output_shape,
|
||||
tim::vx::TensorAttribute::OUTPUT);
|
||||
|
||||
std::vector<float> input_data = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
|
||||
|
||||
std::vector<float> weight_data = {-1, -1, -1, -1, -1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, -1,
|
||||
1, -1, 1, 1, 1, 1, -1, 1, -1, -1, -1, 1, 1, -1, 1, -1};
|
||||
|
||||
// whdcn
|
||||
std::vector<float> golden = {26, 24, 22, -8, -6, -4};
|
||||
|
||||
auto input_tensor = graph->CreateTensor(input_spec);
|
||||
auto weight_tensor = graph->CreateTensor(weight_spec, weight_data.data());
|
||||
|
||||
auto output_tensor = graph->CreateTensor(output_spec);
|
||||
|
||||
std::array<int32_t, 3> stride({1, 1, 1});
|
||||
std::array<int32_t, 3> dilation({1, 1, 1});
|
||||
|
||||
auto conv3d = graph->CreateOperation<tim::vx::ops::Conv3d>(
|
||||
tim::vx::PadType::VALID, stride, dilation);
|
||||
(*conv3d)
|
||||
.BindInput(input_tensor)
|
||||
.BindInput(weight_tensor)
|
||||
.BindOutput(output_tensor);
|
||||
|
||||
EXPECT_TRUE(graph->Compile());
|
||||
|
||||
input_tensor->CopyDataToTensor(input_data.data());
|
||||
|
||||
EXPECT_TRUE(graph->Run());
|
||||
|
||||
uint32_t output_size = 1;
|
||||
for (auto i : output_tensor->GetShape()) {
|
||||
output_size *= i;
|
||||
}
|
||||
std::vector<float> output(output_size);
|
||||
EXPECT_TRUE(output_tensor->CopyDataFromTensor(output.data()));
|
||||
EXPECT_EQ(output,golden);
|
||||
}
|
||||
Loading…
Reference in New Issue