w = model.__sizeof__(3)

时间: 2024-05-06 12:17:26 浏览: 7
`__sizeof__` 方法返回 Python 对象所占用的内存大小,以字节为单位。但是它需要一个整数参数,用于指定对象的深度,即要计算的对象嵌套层数的上限。这个参数不是必需的,默认值为 0,表示只计算直接包含在对象中的内存大小。在你的代码中,`model.__sizeof__(3)` 的语法是错误的,因为 `__sizeof__` 方法不应该有参数。你应该使用 `sys.getsizeof` 函数来获取对象的内存大小: ```python import sys size = sys.getsizeof(model) print(size) ``` 这将打印出模型对象 `model` 占用的内存大小,以字节为单位。注意,这个结果只是一个估计值,它并不包括模型所引用的其他对象的内存大小。
相关问题

解释代码:int post_process(int8_t* input0, int8_t* input1, int8_t* input2, int model_in_h, int model_in_w, float conf_threshold, float nms_threshold, float scale_w, float scale_h, std::vector<int32_t>& qnt_zps, std::vector<float>& qnt_scales, detect_result_group_t* group) { static int init = -1; if (init == -1) { int ret = 0; ret = loadLabelName(LABEL_NALE_TXT_PATH, labels); if (ret < 0) { return -1; } init = 0; } memset(group, 0, sizeof(detect_result_group_t)); std::vector<float> filterBoxes; std::vector<float> objProbs; std::vector<int> classId; // stride 8 int stride0 = 8; int grid_h0 = model_in_h / stride0; int grid_w0 = model_in_w / stride0; int validCount0 = 0; validCount0 = process(input0, (int*)anchor0, grid_h0, grid_w0, model_in_h, model_in_w, stride0, filterBoxes, objProbs, classId, conf_threshold, qnt_zps[0], qnt_scales[0]); // stride 16 int stride1 = 16; int grid_h1 = model_in_h / stride1; int grid_w1 = model_in_w / stride1; int validCount1 = 0; validCount1 = process(input1, (int*)anchor1, grid_h1, grid_w1, model_in_h, model_in_w, stride1, filterBoxes, objProbs, classId, conf_threshold, qnt_zps[1], qnt_scales[1]); // stride 32 int stride2 = 32; int grid_h2 = model_in_h / stride2; int grid_w2 = model_in_w / stride2; int validCount2 = 0; validCount2 = process(input2, (int*)anchor2, grid_h2, grid_w2, model_in_h, model_in_w, stride2, filterBoxes, objProbs, classId, conf_threshold, qnt_zps[2], qnt_scales[2]); int validCount = validCount0 + validCount1 + validCount2; // no object detect if (validCount <= 0) { return 0; } std::vector<int> indexArray; for (int i = 0; i < validCount; ++i) { indexArray.push_back(i); } quick_sort_indice_inverse(objProbs, 0, validCount - 1, indexArray); std::set<int> class_set(std::begin(classId), std::end(classId)); for (auto c : class_set) { nms(validCount, filterBoxes, classId, indexArray, c, nms_threshold); } int last_count = 0; group->count = 0; /* box valid detect target */ for (int i = 0; i < validCount; ++i) { if (indexArray[i] == -1 || last_count >= OBJ_NUMB_MAX_SIZE) { continue; } int n = indexArray[i]; float x1 = filterBoxes[n * 4 + 0]; float y1 = filterBoxes[n * 4 + 1]; float x2 = x1 + filterBoxes[n * 4 + 2]; float y2 = y1 + filterBoxes[n * 4 + 3]; int id = classId[n]; float obj_conf = objProbs[i]; group->results[last_count].box.left = (int)(clamp(x1, 0, model_in_w) / scale_w); group->results[last_count].box.top = (int)(clamp(y1, 0, model_in_h) / scale_h); group->results[last_count].box.right = (int)(clamp(x2, 0, model_in_w) / scale_w); group->results[last_count].box.bottom = (int)(clamp(y2, 0, model_in_h) / scale_h); group->results[last_count].prop = obj_conf; char* label = labels[id]; strncpy(group->results[last_count].name, label, OBJ_NAME_MAX_SIZE); // printf("result %2d: (%4d, %4d, %4d, %4d), %s\n", i, group->results[last_count].box.left, // group->results[last_count].box.top, // group->results[last_count].box.right, group->results[last_count].box.bottom, label); last_count++; } group->count = last_count; return 0; }

这段代码实现了目标检测的后处理函数,对模型输出的特征图进行处理,并生成检测结果。具体解释如下: 函数参数: - `input0`、`input1`、`input2`:三个特征图的指针,分别对应 stride 为 8、16、32 的特征图。 - `model_in_h`、`model_in_w`:输入模型的高度和宽度。 - `conf_threshold`:目标置信度的阈值。 - `nms_threshold`:非极大值抑制的阈值。 - `scale_w`、`scale_h`:图像的缩放因子。 - `qnt_zps`、`qnt_scales`:量化参数。 - `group`:存储检测结果的指针。 函数功能: 1. 首先,检查是否需要初始化标签名,如果是第一次调用函数,则加载标签名并保存在全局变量 `labels` 中。 2. 初始化存储检测结果的 `group` 结构体,并将其内存清零。 3. 创建用于存储过滤后的检测框位置和大小的向量 `filterBoxes`,以及存储目标置信度和类别编号的向量 `objProbs` 和 `classId`。 4. 对 stride 为 8 的特征图进行处理,计算有效目标数目,并将结果保存在 `validCount0` 中。 5. 对 stride 为 16 和 32 的特征图进行类似的处理,计算有效目标数目并分别保存在 `validCount1` 和 `validCount2` 中。 6. 计算总的有效目标数目 `validCount`,如果没有检测到目标,则直接返回。 7. 创建一个索引数组 `indexArray`,用于排序和非极大值抑制操作。 8. 使用快速排序算法 `quick_sort_indice_inverse` 对目标置信度 `objProbs` 进行降序排序,并记录索引的变化情况。 9. 创建一个集合 `class_set`,用于存储所有出现的类别编号。 10. 针对每个类别对目标框进行非极大值抑制操作,剔除重叠度较高的重复框,保留置信度最高的框。 11. 初始化最终检测结果计数器 `last_count` 和 `group->count`。 12. 遍历排序后的索引数组 `indexArray`,获取每个目标框的位置、大小、类别编号和置信度,并进行一些后处理操作。 13. 将检测结果转换为图像坐标,并保存在 `group->results` 中。 14. 更新最终检测结果计数器 `last_count`。 15. 将最终的检测结果数目保存在 `group->count` 中。 16. 返回 0 表示处理成功。 通过这样的处理过程,可以从模型输出的特征图中提取出有效的目标检测结果,并进行非极大值抑制操作,最终生成包含检测框位置、大小、类别和置信度的结果。

对上述代码进行如下修改,是否改变基本功能:tatic int process(int8_t* input, int point_cnt, int height, int width, int stride, std::vector<float>& boxes, std::vector<float>& objProbs, std::vector<int>& classId, float threshold, int32_t zp, float scale) { int validCount = 0; float thres = unsigmoid(threshold); int8_t thres_i8 = qnt_f32_to_affine(thres, zp, scale); for (int a = 0; a < point_cnt; a++){ int8_t maxClassProbs = 0; int maxClassId = 0; for (int k = 1; k < OBJ_CLASS_NUM; ++k) { int8_t prob = input[(3+k) * point_cnt + a]; if (prob > maxClassProbs) { maxClassId = k; maxClassProbs = prob; } } if (maxClassProbs >= thres_i8) { int8_t rx = input[0 * point_cnt + a]; int8_t ry = input[1 * point_cnt + a]; int8_t rw = input[2 * point_cnt + a]; int8_t rh = input[3 * point_cnt + a]; float box_x = sigmoid(deqnt_affine_to_f32(rx, zp, scale)) * 2.0 - 0.5; float box_y = sigmoid(deqnt_affine_to_f32(ry, zp, scale)) * 2.0 - 0.5; float box_w = sigmoid(deqnt_affine_to_f32(rw, zp, scale)) * 2.0; float box_h = sigmoid(deqnt_affine_to_f32(rh, zp, scale)) * 2.0; objProbs.push_back(sigmoid(deqnt_affine_to_f32(maxClassProbs, zp, scale))); classId.push_back(maxClassId); validCount++; boxes.push_back(box_x); boxes.push_back(box_y); boxes.push_back(box_w); boxes.push_back(box_h); } } return validCount; } int post_process(int8_t* input0, int model_in_h, int model_in_w, float conf_threshold, float nms_threshold, float scale_w, float scale_h, std::vector<int32_t>& qnt_zps, std::vector<float>& qnt_scales, detect_result_group_t* group) { static int init = -1; if (init == -1) { int ret = 0; ret = loadLabelName(LABEL_NALE_TXT_PATH, labels); if (ret < 0) { return -1; } init = 0; } memset(group, 0, sizeof(detect_result_group_t)); std::vector<float> filterBoxes; std::vector<float> objProbs; std::vector<int> classId; // stride 6 int stride0 = 4 + OBJ_CLASS_NUM; int point_cnt = 8400; int validCount0 = 0; validCount0 = process(input0, point_cnt, model_in_h, model_in_w, stride0, filterBoxes, objProbs, classId, conf_threshold, qnt_zps[0], qnt_scales[0]); int validCount = validCount0; // no object detect if (validCount <= 0) { return 0; } std::vector<int> indexArray; for (int i = 0; i < validCount; ++i) { indexArray.push_back(i); } quick_sort_indice_inverse(objProbs, 0, validCount - 1, indexArray); std::set<int> class_set(std::begin(classId), std::end(classId)); for (auto c : class_set) { nms(validCount, filterBoxes, classId, indexArray, c, nms_threshold); } int last_count = 0; group->count = 0; /* box valid detect target */ for (int i = 0; i < validCount; ++i) { if (indexArray[i] == -1 || last_count >= OBJ_NUMB_MAX_SIZE) { continue; } int n = indexArray[i]; float x1 = filterBoxes[n * 4 + 0]; float y1 = filterBoxes[n * 4 + 1]; float x2 = x1 + filterBoxes[n * 4 + 2]; float y2 = y1 + filterBoxes[n * 4 + 3]; int id = classId[n]; float obj_conf = objProbs[i]; group->results[last_count].box.left = (int)(clamp(x1, 0, model_in_w) / scale_w); group->results[last_count].box.top = (int)(clamp(y1, 0, model_in_h) / scale_h); group->results[last_count].box.right = (int)(clamp(x2, 0, model_in_w) / scale_w); group->results[last_count].box.bottom = (int)(clamp(y2, 0, model_in_h) / scale_h); group->results[last_count].prop = obj_conf; char* label = labels[id]; strncpy(group->results[last_count].name, label, OBJ_NAME_MAX_SIZE); // printf("result %2d: (%4d, %4d, %4d, %4d), %s\n", i, group->results[last_count].box.left, // group->results[last_count].box.top, // group->results[last_count].box.right, group->results[last_count].box.bottom, label); last_count++; } group->count = last_count; return 0; }

对于第一个修改的代码块 `static int process(int8_t* input, int point_cnt, int height, int width, int stride, std::vector<float>& boxes, std::vector<float>& objProbs, std::vector<int>& classId, float threshold, int32_t zp, float scale)`,基本功能并没有改变。该函数仍然实现了目标检测的后处理,根据输入的 int8_t 类型指针和相关参数,提取有效的目标检测结果,并将检测框的位置、大小、目标置信度和类别编号存储在相应的向量中。 第二个修改的代码块 `int post_process(int8_t* input0, int model_in_h, int model_in_w, float conf_threshold, float nms_threshold, float scale_w, float scale_h, std::vector<int32_t>& qnt_zps, std::vector<float>& qnt_scales, detect_result_group_t* group)`,基本功能也没有改变。该函数仍然实现了目标检测的后处理,根据输入的特征图和相关参数,提取有效的目标检测结果,并将检测框的位置、大小、目标置信度和类别信息存储在 `detect_result_group_t` 结构体中。 两个修改的代码块主要对输入参数进行了调整,其中 `point_cnt` 表示检测点的数量,通过调整 `stride0` 的计算方式来确定。这些修改可能是为了适应不同的检测模型或数据集,但并没有改变基本的目标检测后处理逻辑。

相关推荐

#define _USE_MATH_DEFINES #include <cstdlib> #include <cmath> #include <iostream> #include <GL/glew.h> #include <GL/freeglut.h> // Globals. static float R = 40.0; // Radius of circle. static float X = 50.0; // X-coordinate of center of circle. static float Y = 50.0; // Y-coordinate of center of circle. static const int numVertices = 50; // Number of vertices on circle. static int verticesColors[6 * numVertices]; void generateVertices() { float t = 0; // Angle parameter. for (int i = 0; i < 6*numVertices; i+=6) { verticesColors[] = X + R * cos(t); //x verticesColors[] = Y + R * sin(t); //y verticesColors[] = 0.0; //z verticesColors[] = 1.0; //r verticesColors[] = 0.0; //g verticesColors[] = 0.0; //b t += 2 * M_PI / numVertices; //angle } } // Drawing routine. void drawScene(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1, 0, 0); glLineWidth(5); glDrawArrays(GL_LINE_LOOP, 0, 50); glFlush(); } // Initialization routine. void setup(void) { glClearColor(1.0, 1.0, 1.0, 0.0); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), &verticesColors[0]); glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), &verticesColors[3]) } // OpenGL window reshape routine. void resize(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 100.0, 0.0, 100.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } // Keyboard input processing routine. void keyInput(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; default: break; } } // Main routine. int main(int argc, char** argv) { generateVertices(); glutInit(&argc, argv); glutInitContextVersion(4, 3); glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); glutInitWindowSize(500, 500); glutInitWindowPosition(100, 100); glutCreateWindow("circle.cpp"); glutDisplayFunc(drawScene); glutReshapeFunc(resize); glutKeyboardFunc(keyInput); glewExperimental = GL_TRUE; glewInit(); setup(); glutMainLoop(); }怎么修改

#define _USE_MATH_DEFINES #include <cstdlib> #include <cmath> #include <iostream> #include <GL/glew.h> #include <GL/freeglut.h> // Globals. static float R = 40.0; // Radius of circle. static float X = 50.0; // X-coordinate of center of circle. static float Y = 50.0; // Y-coordinate of center of circle. static const int numVertices = 50; // Number of vertices on circle. static int verticesColors[6 * numVertices]; void generateVertices() { float t = 0; // Angle parameter. for (int i = 0; i < 6 * numVertices; i += 6) { verticesColors[i] = X + R * cos(t); //x verticesColors[i] = Y + R * sin(t); //y verticesColors[i] = 0.0; //z verticesColors[i] = 1.0; //r verticesColors[i] = 0.0; //g verticesColors[i] = 0.0; //b t += 2 * M_PI / numVertices; //angle } } // Drawing routine. void drawScene(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1, 0, 0); glLineWidth(5); glDrawArrays(GL_POLYGON, 0, numVertices); glFlush(); } // Initialization routine. void setup(void) { glClearColor(1.0, 1.0, 1.0, 0.0); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glColorPointer(3, GL_FLOAT, 6 * sizeof(float), &verticesColors[0]); glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), &verticesColors[3]); } // OpenGL window reshape routine. void resize(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 100.0, 0.0, 100.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } // Keyboard input processing routine. void keyInput(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; default: break; } } // Main routine. int main(int argc, char** argv) { generateVertices(); glutInit(&argc, argv); glutInitContextVersion(4, 3); glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); glutInitWindowSize(500, 500); glutInitWindowPosition(100, 100); glutCreateWindow("circle.cpp"); glutDisplayFunc(drawScene); glutReshapeFunc(resize); glutKeyboardFunc(keyInput); glewExperimental = GL_TRUE; glewInit(); setup(); glutMainLoop(); }为什么输出什么也看不到

最新推荐

recommend-type

406_智能小区管家服务系统的设计与实现-源码.zip

提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。
recommend-type

毕业设计+项目编程实战+基于BS架构的ASP.NET的新闻管理系统(含程序源代码+毕业设计文档)

前言……………………………………………………………………………….2 第1章 ASP简介…………………………………………………………….…..1 1.1ASP的特点………………………………………………………….1 1.2ASP的优势………………………………………………………….2 1.3 ASP与HTML……………………………………………………….3 1.4 ASP的内置对象……………………………………………………..4 1.4.1 Request对象………………………………………………….4 1.4.2 Response对象………………………………………………..4 第2章 为什么要开发一个新闻发布系统…………………………………………….6 第3章 Access数据库……………………………………………………………8 3.1 数据库概念………………………………………………………….8 3.2 Access数据库特点………………………………………………….8 3.3
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

hive中 的Metastore

Hive中的Metastore是一个关键的组件,它用于存储和管理Hive中的元数据。这些元数据包括表名、列名、表的数据类型、分区信息、表的存储位置等信息。Hive的查询和分析都需要Metastore来管理和访问这些元数据。 Metastore可以使用不同的后端存储来存储元数据,例如MySQL、PostgreSQL、Oracle等关系型数据库,或者Hadoop分布式文件系统中的HDFS。Metastore还提供了API,使得开发人员可以通过编程方式访问元数据。 Metastore的另一个重要功能是跟踪表的版本和历史。当用户对表进行更改时,Metastore会记录这些更改,并且可以让用户回滚到
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

MATLAB柱状图在数据分析中的作用:从可视化到洞察

![MATLAB柱状图在数据分析中的作用:从可视化到洞察](https://img-blog.csdnimg.cn/img_convert/1a36558cefc0339f7836cca7680c0aef.png) # 1. MATLAB柱状图概述** 柱状图是一种广泛用于数据可视化的图表类型,它使用垂直条形来表示数据中不同类别或组别的值。在MATLAB中,柱状图通过`bar`函数创建,该函数接受数据向量或矩阵作为输入,并生成相应的高度条形。 柱状图的优点在于其简单性和易于理解性。它们可以快速有效地传达数据分布和组别之间的比较。此外,MATLAB提供了广泛的定制选项,允许用户调整条形颜色、
recommend-type

软件工程每个学期的生活及学习目标

软件工程每个学期的生活及学习目标可能包括以下内容: 1. 学习软件开发的基本理论和实践知识,掌握常用的编程语言和开发工具。 2. 熟悉软件开发的流程和方法,了解软件工程的标准和规范。 3. 掌握软件需求分析、设计、开发、测试、部署和维护的技能,能够独立完成简单的软件开发任务。 4. 培养团队合作的能力,学会与他人进行有效的沟通和协作,共同完成软件开发项目。 5. 提高自己的计算机技术水平,了解最新的软件开发技术和趋势,积极参与开源社区和技术交流活动。 6. 注重学习方法和习惯的培养,养成良好的学习和生活习惯,保持健康的身心状态。 7. 积极参加校内外的实践活动和比赛,拓展自己的视