首页下载资源前端水水水水水水水水水水水水水水水水

ZIP水水水水水水水水水水水水水水水水

QQ109796416431.6KB需要积分:1

资源文件列表:

op_zxh.zip 大约有20个文件
  1. layer_rvv/
  2. layer_rvv/dequantize.h 2.41KB
  3. layer_rvv/scatter_elements.h 1.63KB
  4. layer_rvv/quantize.cpp 16.28KB
  5. layer_rvv/dequantize_linear.cpp 17.07KB
  6. layer_rvv/quantize_linear.cpp 26.54KB
  7. layer_rvv/dequantize_linear.h 1.59KB
  8. layer_rvv/quantize.h 1.49KB
  9. layer_rvv/quantize_linear.h 1.57KB
  10. layer_rvv/dequantize.cpp 16.71KB
  11. layer_rvv/scatter_elements.cpp 8.83KB
  12. test_op/
  13. test_op/test_dequantize_linear.cpp 44.52KB
  14. test_op/test_quantize_linear.cpp 49.41KB
  15. test_op/test_quantize.cpp 45.26KB
  16. test_op/main.cpp 599B
  17. test_op/test_op.h 804B
  18. test_op/test_dequantize.cpp 83.35KB
  19. test_op/rvv1.0_op/
  20. test_op/rvv1.0_op/test_scatter_elements.cpp 13.6KB

资源介绍:

水水水水水水水水水水水水水水水水
// Copyright (c) 2020 Horizon Robotics.All Rights Reserved. // // The material in this file is confidential and contains trade secrets // of Horizon Robotics Inc. This is proprietary information owned by // Horizon Robotics Inc. No part of this work may be disclosed, // reproduced, copied, transmitted, or used in any way for any purpose, // without the express written permission of Horizon Robotics Inc. #include "layer/dequantize.h" #include "test_op.h" #include "gtest/gtest.h" using hobot::dnn::NDArray; using hobot::dnn::TShape; using hobot::dnn::TypeFlag; TEST(Dequantize, Dequantize_case1) { std::cout << "input(24,24), int8->float32, scale" << std::endl; hobot::dnn::Dequantize DequantizeOp; hobot::dnn::VarientMap attr_dict; attr_dict["num_args"] = 2; DequantizeOp.Init(attr_dict); std::vector bottom_blobs; std::vector top_blobs; std::vector x(24 * 24); //std::srand(static_cast(std::time(nullptr))); for (size_t i = 0; i < x.size(); ++i) { x[i] = static_cast(static_cast(std::rand()) / static_cast(RAND_MAX) * 255 - 128); } std::vector scale = {1.5f}; hobot::dnn::TShape shape{24, 24}; hobot::dnn::TShape shape1{1}; std::unique_ptr x_nd( new NDArray(x.data(), shape, TypeFlag::kInt8)); std::unique_ptr scale_nd( new NDArray(scale.data(), shape1, TypeFlag::kFloat32)); std::unique_ptr y_nd(new NDArray(shape, TypeFlag::kFloat32)); bottom_blobs.push_back(x_nd.get()); bottom_blobs.push_back(scale_nd.get()); top_blobs.push_back(y_nd.get()); clock_t start_time = clock(); DequantizeOp.Forward(bottom_blobs, top_blobs); clock_t end_time = clock(); double cost_time = (double) (end_time - start_time) / CLOCKS_PER_SEC * 1000; std::cout << "cost time:" << cost_time << "ms" << std::endl; #ifdef DNN_X86 std::string output_path = "./Output/Dequantize_case1.txt"; std::ofstream output_file(output_path); ASSERT_TRUE(output_file.is_open()) << "Failed to open file " << output_path << " for writing."; for (size_t i = 0; i < y_nd->Size(); ++i) { output_file << std::to_string(y_nd->Dptr()[i]) << "\n"; //std::cout << std::to_string(y_nd->Dptr()[i]) << std::endl; } output_file.close(); std::cout << "Data saved to " << output_path << std::endl; #else std::string input_path = "./Output/Dequantize_case1.txt"; std::ifstream input_file(input_path); ASSERT_TRUE(input_file.is_open()) << "Failed to open file " << input_path << " for reading."; std::vector saved_data; std::string value; while (input_file >> value) { saved_data.push_back(std::stof(value)); } input_file.close(); std::vector current_data(y_nd->Dptr(), y_nd->Dptr() + y_nd->Size()); for (size_t i = 0; i < current_data.size(); ++i) { ASSERT_NEAR(saved_data[i], current_data[i], 0.0001) << "Difference at index " << i << ": saved_data = " << saved_data[i] << ", current_data = " << current_data[i]; } #endif } TEST(Dequantize, Dequantize_case2) { std::cout << "input(24,24), int8->float32, scale_zero" << std::endl; hobot::dnn::Dequantize DequantizeOp; hobot::dnn::VarientMap attr_dict; attr_dict["num_args"] = 3; DequantizeOp.Init(attr_dict); std::vector bottom_blobs; std::vector top_blobs; std::vector x(24 * 24); //std::srand(static_cast(std::time(nullptr))); for (size_t i = 0; i < x.size(); ++i) { x[i] = static_cast(static_cast(std::rand()) / static_cast(RAND_MAX) * 255 - 128); } std::vector scale = {1.5f}; std::vector zero_point = {2}; hobot::dnn::TShape shape{24, 24}; hobot::dnn::TShape shape1{1}; std::unique_ptr x_nd( new NDArray(x.data(), shape, TypeFlag::kInt8)); std::unique_ptr scale_nd( new NDArray(scale.data(), shape1, TypeFlag::kFloat32)); std::unique_ptr zero_point_nd( new NDArray(zero_point.data(), shape1, TypeFlag::kInt8)); std::unique_ptr y_nd(new NDArray(shape, TypeFlag::kFloat32)); bottom_blobs.push_back(x_nd.get()); bottom_blobs.push_back(scale_nd.get()); bottom_blobs.push_back(zero_point_nd.get()); top_blobs.push_back(y_nd.get()); clock_t start_time = clock(); DequantizeOp.Forward(bottom_blobs, top_blobs); clock_t end_time = clock(); double cost_time = (double) (end_time - start_time) / CLOCKS_PER_SEC * 1000; std::cout << "cost time:" << cost_time << "ms" << std::endl; #ifdef DNN_X86 std::string output_path = "./Output/Dequantize_case2.txt"; std::ofstream output_file(output_path); ASSERT_TRUE(output_file.is_open()) << "Failed to open file " << output_path << " for writing."; for (size_t i = 0; i < y_nd->Size(); ++i) { output_file << std::to_string(y_nd->Dptr()[i]) << "\n"; //std::cout << std::to_string(y_nd->Dptr()[i]) << std::endl; } output_file.close(); std::cout << "Data saved to " << output_path << std::endl; #else std::string input_path = "./Output/Dequantize_case2.txt"; std::ifstream input_file(input_path); ASSERT_TRUE(input_file.is_open()) << "Failed to open file " << input_path << " for reading."; std::vector saved_data; std::string value; while (input_file >> value) { saved_data.push_back(std::stof(value)); } input_file.close(); std::vector current_data(y_nd->Dptr(), y_nd->Dptr() + y_nd->Size()); for (size_t i = 0; i < current_data.size(); ++i) { ASSERT_NEAR(saved_data[i], current_data[i], 0.0001) << "Difference at index " << i << ": saved_data = " << saved_data[i] << ", current_data = " << current_data[i]; } #endif } TEST(Dequantize, Dequantize_case3) { std::cout << "input(3,224,224), int16->float32, scale" << std::endl; hobot::dnn::Dequantize DequantizeOp; hobot::dnn::VarientMap attr_dict; attr_dict["num_args"] = 2; DequantizeOp.Init(attr_dict); std::vector bottom_blobs; std::vector top_blobs; std::vector x(3 * 224 * 224); //std::srand(static_cast(std::time(nullptr))); for (size_t i = 0; i < x.size(); ++i) { x[i] = static_cast(static_cast(std::rand()) / static_cast(RAND_MAX) * 2000 - 1000); } std::vector scale = {1.5f}; hobot::dnn::TShape shape{3, 224, 224}; hobot::dnn::TShape shape1{1}; std::unique_ptr x_nd( new NDArray(x.data(), shape, TypeFlag::kInt16)); std::unique_ptr scale_nd( new NDArray(scale.data(), shape1, TypeFlag::kFloat32)); std::unique_ptr y_nd(new NDArray(shape, TypeFlag::kFloat32)); bottom_blobs.push_back(x_nd.get()); bottom_blobs.push_back(scale_nd.get()); top_blobs.push_back(y_nd.get()); clock_t start_time = clock(); DequantizeOp.Forward(bottom_blobs, top_blobs); clock_t end_time = clock(); double cost_time = (double) (end_time - start_time) / CLOCKS_PER_SEC * 1000; std::cout << "cost time:" << cost_time << "ms" << std::endl; #ifdef DNN_X86 std::string output_path = "./Output/Dequantize_case3.txt"; std::ofstream output_file(output_path); ASSERT_TRUE(output_file.is_open()) << "Failed to open file " << output_path << " for writing."; for (size_t i = 0; i < y_nd->Size(); ++i) { output_file << std::to_string(y_nd->Dptr()[i]) << "\n"; //std::cout << std::to_string(y_nd->Dptr()[i]) << std::endl; } output_file.close(); std::cout << "Data saved to " << output_path << std::endl; #else std::string input_path = "./Output/Dequantize_case3.txt"; std::ifstream input_file(input_path); ASSERT_TRUE(input_file.is_open()) << "Failed to open file " << input_path << " for reading."; std::vector saved_data; std::string value; while (input_file >> value) { saved_data.push_back(std::stof(value)); } input_file.
100+评论
captcha