// // 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 "gtest/gtest.h"
#include "layer/eltwise.h"
#include "test_op.h"
#include <chrono>
#include <random>
using hobot::dnn::NDArray;
using hobot::dnn::TypeFlag;
TEST(round, eltwise_round_case1) {
std::cout<<"(1,3,240,360)--4d input float32"<<std::endl;
hobot::dnn::Eltwise Ele;
hobot::dnn::VarientMap in;
in["eltwise_type"] = 18;
in["num_args"] = 1;
Ele.Init(in);
std::vector<NDArray *> bottom_blobs;
std::vector<NDArray *> top_blobs;
// float arr1[] = {1, 2, 3, 4, 5, 6};
// float result[] = {1.54308, 3.7622, 10.0677, 27.3082, 74.21, 201.7156};
int nums=3*240*360;
std::vector<float> input(3*240*360);
// std::vector<float> result(3*240*360);
float min=-10;
float max=10;
for (size_t i = 0; i < input.size(); ++i) {
input[i] = min + static_cast<float>(std::rand()) / (static_cast<float>(RAND_MAX / (max - min)));
}
hobot::dnn::TShape shape{1, 3, 240, 360};
std::unique_ptr<NDArray> array1(new NDArray(input.data(), shape, TypeFlag::kFloat32));
std::unique_ptr<NDArray> array(new NDArray(shape, TypeFlag::kFloat32));
bottom_blobs.push_back(array1.get());
top_blobs.push_back(array.get());
clock_t time1=clock();
auto ret = Ele.Forward(bottom_blobs, top_blobs);
clock_t time2=clock();
std::cout<<"cost time: "<<(double)(time2-time1)/CLOCKS_PER_SEC*1000<<"ms"<<std::endl;
#ifdef DNN_X86
std::string output_path = "./Output/eltwise_round_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 < array->Size(); ++i) {
output_file << std::to_string(array->Dptr<float>()[i]) << "\n";
}
output_file.close();
std::cout << "Data saved to " << output_path << std::endl;
#else
std::string input_path = "./Output/eltwise_round_case1.txt";
std::ifstream input_file(input_path);
ASSERT_TRUE(input_file.is_open()) << "Failed to open file " << input_path << " for reading.";
std::vector<float> saved_data;
std::string value;
while (input_file >> value) {
saved_data.push_back(std::stof(value));
}
input_file.close();
std::vector<float> current_data(array->Dptr<float>(), array->Dptr<float>() + array->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(round, eltwise_round_case2) {
// int main(){
std::cout<<"(1,3,240,360)--4d input float64"<<std::endl;
hobot::dnn::Eltwise Ele;
hobot::dnn::VarientMap in;
in["eltwise_type"] = 18;
in["num_args"] = 1;
Ele.Init(in);
std::vector<NDArray *> bottom_blobs;
std::vector<NDArray *> top_blobs;
// float arr1[] = {1, 2, 3, 4, 5, 6};
// float result[] = {1.54308, 3.7622, 10.0677, 27.3082, 74.21, 201.7156};
int nums=3*240*360;
std::vector<double> input(3*240*360);
std::vector<double> result(3*240*360);
float min=-10;
float max=10;
for (size_t i = 0; i < input.size(); ++i) {
input[i] = min + static_cast<float>(std::rand()) / (static_cast<float>(RAND_MAX / (max - min)));
}
hobot::dnn::TShape shape{1, 3, 240, 360};
std::unique_ptr<NDArray> array1(new NDArray(input.data(), shape, TypeFlag::kFloat64));
std::unique_ptr<NDArray> array(new NDArray(shape, TypeFlag::kFloat64));
bottom_blobs.push_back(array1.get());
top_blobs.push_back(array.get());
clock_t time1=clock();
auto ret = Ele.Forward(bottom_blobs, top_blobs);
clock_t time2=clock();
std::cout<<"cost time: "<<(double)(time2-time1)/CLOCKS_PER_SEC*1000<<"ms"<<std::endl;
#ifdef DNN_X86
std::string output_path = "./Output/eltwise_round_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 < array->Size(); ++i) {
output_file << std::to_string(array->Dptr<double>()[i]) << "\n";
}
output_file.close();
std::cout << "Data saved to " << output_path << std::endl;
#else
std::string input_path = "./Output/eltwise_round_case2.txt";
std::ifstream input_file(input_path);
ASSERT_TRUE(input_file.is_open()) << "Failed to open file " << input_path << " for reading.";
std::vector<float> saved_data;
std::string value;
while (input_file >> value) {
saved_data.push_back(std::stof(value));
}
input_file.close();
std::vector<double> current_data(array->Dptr<double>(), array->Dptr<double>() + array->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(tan, eltwise_tan_case1) {
std::cout<<"(1,3,240,360)--4d input float32"<<std::endl;
hobot::dnn::Eltwise Ele;
hobot::dnn::VarientMap in;
in["eltwise_type"] = 7;
in["num_args"] = 1;
Ele.Init(in);
std::vector<NDArray *> bottom_blobs;
std::vector<NDArray *> top_blobs;
// float arr1[] = {1, 2, 3, 4, 5, 6};
// float result[] = {1.54308, 3.7622, 10.0677, 27.3082, 74.21, 201.7156};
int nums=3*240*360;
std::vector<float> input(3*240*360);
std::vector<float> result(3*240*360);
float min=-1.5;
float max=1.5;
for (size_t i = 0; i < input.size(); ++i) {
input[i] = min + static_cast<float>(std::rand()) / (static_cast<float>(RAND_MAX / (max - min)));
}
hobot::dnn::TShape shape{1, 3, 240, 360};
std::unique_ptr<NDArray> array1(new NDArray(input.data(), shape, TypeFlag::kFloat32));
std::unique_ptr<NDArray> array(new NDArray(shape, TypeFlag::kFloat32));
bottom_blobs.push_back(array1.get());
top_blobs.push_back(array.get());
clock_t time1=clock();
auto ret = Ele.Forward(bottom_blobs, top_blobs);
clock_t time2=clock();
std::cout<<"cost time: "<<(double)(time2-time1)/CLOCKS_PER_SEC*1000<<"ms"<<std::endl;
#ifdef DNN_X86
std::string output_path = "./Output/eltwise_tan_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 < array->Size(); ++i) {
output_file << std::to_string(array->Dptr<float>()[i]) << "\n";
}
output_file.close();
std::cout << "Data saved to " << output_path << std::endl;
#else
std::string input_path = "./Output/eltwise_tan_case1.txt";
std::ifstream input_file(input_path);
ASSERT_TRUE(input_file.is_open()) << "Failed to open file " << input_path << " for reading.";
std::vector<float> saved_data;
std::string value;
while (input_file >> value) {
saved_data.push_back(std::stof(value));
}
input_file.close();
std::vector<float> current_data(array->Dptr<float>(), array->Dptr<float>() + array->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(tan, eltwise_tan_case2) {
std::cout<<"(1,3,240,360)--4d input float64"<<std::endl;
hobot::dnn::Eltwise Ele;
hobot::dnn::VarientMap in;
in["eltwise_type"] = 7;
in["num_args"] = 1;
Ele
没有合适的资源?快使用搜索试试~ 我知道了~
testtesttesttesttesttesttesttesttesttest
共71个文件
cpp:68个
h:2个
bk:1个
需积分: 0 0 下载量 107 浏览量
2024-09-14
11:36:06
上传
评论
收藏 118KB ZIP 举报
温馨提示
testtesttesttesttesttesttesttesttesttest
资源推荐
资源详情
资源评论
收起资源包目录
TEST.zip (71个子文件)
TEST
test_op
test_sigmoid.cpp 3KB
test_softplus.cpp 3KB
test_softmax.cpp 10KB
test_thresholdedrelu.cpp 5KB
test_upsample.cpp 15KB
test_neg.cpp 14KB
test_ceil.cpp 5KB
test_sign.cpp 3KB
test_hardsigmoid.cpp 3KB
test_dequantize_linear.cpp 45KB
test_exp.cpp 3KB
test_elementwise_binary_broadcast.cpp 4KB
test_eyelike.cpp 16KB
test_reducel1.cpp 22KB
test_relu.cpp 3KB
test_reduction.cpp 44KB
test_tanh_time.cpp 3KB
test_batch_normalization.cpp 5KB
test_concat.cpp 7KB
test_normalize.cpp 3KB
test_identity.cpp 3KB
test_leakyrelu.cpp 5KB
test_averagepool.cpp 74KB
test_hz_channel_shuffle.cpp 5KB
test_reducel2.cpp 10KB
test_op.h 793B
test_scaledtanh_time.cpp 3KB
test_lp_normalization.cpp 13KB
test_erf.cpp 5KB
test_hardswish.cpp 3KB
test_cast.cpp 13KB
test_relux.cpp 3KB
test_log_softmax.cpp 3KB
test_nms_time.cpp 4KB
main.cpp 599B
test_elu.cpp 3KB
test_floor.cpp 3KB
test_selu.cpp 3KB
test_maxpool.cpp 48KB
test_prelu.cpp 11KB
test_dequantize.cpp 83KB
test_roipooling.cpp 3KB
test_lrn.cpp 3KB
test_global_lp_pool.cpp 11KB
test_crelu.cpp 5KB
test_log.cpp 2KB
test_expand.cpp 3KB
test_hz_rsqrt.cpp 7KB
test_axpy.cpp 4KB
test_quantize.cpp 45KB
test_quantize_linear.cpp 49KB
test_clip.cpp 31KB
test_power.cpp.bk 3KB
test_roi_pooling.cpp 6KB
test_hz_softmax.cpp 9KB
test_reshape.cpp 3KB
test_softsign.cpp 3KB
test_global_average_pool.cpp 3KB
test_mvn.cpp 3KB
test_reducelogsumexp.cpp 16KB
test_transpose.cpp 6KB
test_instance_normalization.cpp 4KB
test_eltwise_time.cpp 85KB
test_abs.cpp 3KB
908
test_upsample.cpp 15KB
test_global_max_pool.cpp 3KB
test_op.h 793B
main.cpp 599B
test_argmax.cpp 10KB
test_argmin.cpp 10KB
test_eltwise_time.cpp 85KB
共 71 条
- 1
资源评论
QQ1097964164
- 粉丝: 0
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- rust语言详细教程学习 rust重点知识总结.docx
- 艺术风格PPT模板+欧式复古+产品发布
- 博客系统-基于Diango开发的博客系统-附完整流程教程-优质项目实战.zip
- 往复升降机+进出加速段sw18可编辑-三维3D设计图纸.zip
- 《机器人SLAM导航》课件(完整版)-第1季:第1章-ROS入门必备知识
- 【Unity产品级射击游戏模板】Infinite Sci-Fi Shooter Package 搭建科幻风格射击游戏
- MyString.cpp
- C# opencv 100多个例子
- 毕业设计-使用yolov8开发的车辆计数项目-项目实战-项目源码-优质项目.zip
- 毕业设计-使用yolov5+deepsort实现高速移动车流人流量统计-项目实战-项目源码-优质项目.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功