# 打开一个文件 scales = ["服务过程","管理过程","生产过程","研发过程"] results = [] for s in scales: results.append({}) f = open("../%s.txt"%s, encoding = "utf-8") string = f.readlines() words = string[0].split("、") for w in words: results[-1][w] = [] for i in range(10): f = open("../年报/%d.txt.txt"%(i+2011), "r",encoding='utf-8') target = "" string = f.readlines() for line in string: target += line target = target.replace(" ","") for j in range(len(scales)): fkey = open("../%s.txt"%scales[j], encoding = "utf-8") s = fkey.readlines() words = s[0].split("、") for w in range(len(words)): num = target.count(words[w]) results[j][words[w]].append(num) for i in range(len(results)): r = pd.DataFrame(results[i]) r.to_excel("%s_词频统计.xlsx"%scales[i],index_label = ["2011","2012","2013","2014","2015","2016","2017","2018","2019","2020"])

时间: 2023-07-21 22:04:12 浏览: 61
你的代码看起来是用来读取一些文件,并统计其中关键词的词频,然后将结果保存到Excel文件中。这个代码有几个问题需要注意一下。 首先,在打开文件时,最好使用上下文管理器(`with`语句)来确保文件能够正确关闭,以避免资源泄漏。这样可以替代你使用`open()`打开文件的方式。类似于这样: ```python with open("../%s.txt" % s, encoding="utf-8") as f: string = f.readlines() ``` 其次,在统计关键词的词频时,你可以使用Python的`collections.Counter`类来简化代码。例如: ```python from collections import Counter # ... for w in range(len(words)): counter = Counter(target) num = counter[words[w]] results[j][words[w]].append(num) ``` 最后,你需要导入`pandas`库,因为你的代码中使用了`pd.DataFrame()`和`to_excel()`方法。确保在代码开头添加`import pandas as pd`。 希望这些修改对你有帮助!如果你还有其他问题,请随时提出。
相关问题

解释代码: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 表示处理成功。 通过这样的处理过程,可以从模型输出的特征图中提取出有效的目标检测结果,并进行非极大值抑制操作,最终生成包含检测框位置、大小、类别和置信度的结果。

Fine-Grained Feature Enhancement for Object Detection in Remote Sensing Images

Object detection in remote sensing images is a challenging task due to the complex backgrounds, diverse object shapes and sizes, and varying imaging conditions. To address these challenges, fine-grained feature enhancement can be employed to improve object detection accuracy. Fine-grained feature enhancement is a technique that extracts and enhances features at multiple scales and resolutions to capture fine details of objects. This technique includes two main steps: feature extraction and feature enhancement. In the feature extraction step, convolutional neural networks (CNNs) are used to extract features from the input image. The extracted features are then fed into a feature enhancement module, which enhances the features by incorporating contextual information and fine-grained details. The feature enhancement module employs a multi-scale feature fusion technique to combine features at different scales and resolutions. This technique helps to capture fine details of objects and improve the accuracy of object detection. To evaluate the effectiveness of fine-grained feature enhancement for object detection in remote sensing images, experiments were conducted on two datasets: the NWPU-RESISC45 dataset and the DOTA dataset. The experimental results demonstrate that fine-grained feature enhancement can significantly improve the accuracy of object detection in remote sensing images. The proposed method outperforms state-of-the-art object detection methods on both datasets. In conclusion, fine-grained feature enhancement is an effective technique to improve the accuracy of object detection in remote sensing images. This technique can be applied to a wide range of applications, such as urban planning, disaster management, and environmental monitoring.

相关推荐

对上述代码进行如下修改,是否改变基本功能: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; }

最新推荐

recommend-type

地县级城市建设道路清扫保洁面积 道路清扫保洁面积道路机械化清扫保洁面积 省份 城市.xlsx

数据含省份、行政区划级别(细分省级、地级市、县级市)两个变量,便于多个角度的筛选与应用 数据年度:2002-2022 数据范围:全693个地级市、县级市、直辖市城市,含各省级的汇总tongji数据 数据文件包原始数据(由于多年度指标不同存在缺失值)、线性插值、回归填补三个版本,提供您参考使用。 其中,回归填补无缺失值。 填补说明: 线性插值。利用数据的线性趋势,对各年份中间的缺失部分进行填充,得到线性插值版数据,这也是学者最常用的插值方式。 回归填补。基于ARIMA模型,利用同一地区的时间序列数据,对缺失值进行预测填补。 包含的主要城市: 通州 石家庄 藁城 鹿泉 辛集 晋州 新乐 唐山 开平 遵化 迁安 秦皇岛 邯郸 武安 邢台 南宫 沙河 保定 涿州 定州 安国 高碑店 张家口 承德 沧州 泊头 任丘 黄骅 河间 廊坊 霸州 三河 衡水 冀州 深州 太原 古交 大同 阳泉 长治 潞城 晋城 高平 朔州 晋中 介休 运城 永济 .... 等693个地级市、县级市,含省级汇总 主要指标:
recommend-type

从网站上学习到了路由的一系列代码

今天的学习圆满了
recommend-type

基于AT89C51单片机的可手动定时控制的智能窗帘设计.zip-11

压缩包构造:程序、仿真、原理图、pcb、任务书、结构框图、流程图、开题文档、设计文档、元件清单、实物图、焊接注意事项、实物演示视频、运行图片、功能说明、使用前必读。 仿真构造:AT89C51,LCD液晶显示器,5功能按键,步进器,灯。 代码文档:代码1024行有注释;设计文档18819字。 功能介绍:系统具有手动、定时、光控、温控和湿度控制五种模式。在手动模式下,两个按钮可控制窗帘的开合;定时模式下,根据预设时间自动开合窗帘;光控模式下,当光照超过设定阈值时,窗帘自动开启;低于阈值时,窗帘自动关闭;温控模式下,当温度超过设定阈值时,窗帘自动开启;低于阈值时,窗帘自动关闭;湿度控制模式下,当湿度超过设定阈值时,窗帘自动开启;低于阈值时,窗帘自动关闭。按钮可用于调节阈值、选择模式、设置时间等。
recommend-type

007_insert_seal_approval_cursor.sql

007_insert_seal_approval_cursor.sql
recommend-type

springboot072基于JavaWeb技术的在线考试系统设计与实现.zip

java基于SpringBoot+vue在线考试系统源码 带毕业论文+PPT 【资源说明】 1、开发环境:SpringBoot框架;内含Mysql数据库;VUE技术;内含说明文档 2、该资源包括项目的全部源码,下载可以直接使用! 3、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 4、本资源作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。
recommend-type

基于嵌入式ARMLinux的播放器的设计与实现 word格式.doc

本文主要探讨了基于嵌入式ARM-Linux的播放器的设计与实现。在当前PC时代,随着嵌入式技术的快速发展,对高效、便携的多媒体设备的需求日益增长。作者首先深入剖析了ARM体系结构,特别是针对ARM9微处理器的特性,探讨了如何构建适用于嵌入式系统的嵌入式Linux操作系统。这个过程包括设置交叉编译环境,优化引导装载程序,成功移植了嵌入式Linux内核,并创建了适合S3C2410开发板的根文件系统。 在考虑到嵌入式系统硬件资源有限的特点,通常的PC机图形用户界面(GUI)无法直接应用。因此,作者选择了轻量级的Minigui作为研究对象,对其实体架构进行了研究,并将其移植到S3C2410开发板上,实现了嵌入式图形用户界面,使得系统具有简洁而易用的操作界面,提升了用户体验。 文章的核心部分是将通用媒体播放器Mplayer移植到S3C2410开发板上。针对嵌入式环境中的音频输出问题,作者针对性地解决了Mplayer播放音频时可能出现的不稳定性,实现了音乐和视频的无缝播放,打造了一个完整的嵌入式多媒体播放解决方案。 论文最后部分对整个项目进行了总结,强调了在嵌入式ARM-Linux平台上设计播放器所取得的成果,同时也指出了一些待改进和完善的方面,如系统性能优化、兼容性提升以及可能的扩展功能等。关键词包括嵌入式ARM-Linux、S3C2410芯片、Mplayer多媒体播放器、图形用户界面(GUI)以及Minigui等,这些都反映出本文研究的重点和领域。 通过这篇论文,读者不仅能了解到嵌入式系统与Linux平台结合的具体实践,还能学到如何在资源受限的环境中设计和优化多媒体播放器,为嵌入式技术在多媒体应用领域的进一步发展提供了有价值的经验和参考。
recommend-type

管理建模和仿真的文件

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

Python字符串为空判断的动手实践:通过示例掌握技巧

![Python字符串为空判断的动手实践:通过示例掌握技巧](https://img-blog.csdnimg.cn/72f88d4fc1164d6c8b9c29d8ab5ed75c.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBASGFyYm9yIExhdQ==,size_20,color_FFFFFF,t_70,g_se,x_16) # 1. Python字符串为空判断的基础理论 字符串为空判断是Python编程中一项基本且重要的任务。它涉及检查字符串是否为空(不包含任何字符),这在
recommend-type

box-sizing: border-box;作用是?

`box-sizing: border-box;` 是 CSS 中的一个样式属性,它改变了元素的盒模型行为。默认情况下,浏览器会计算元素内容区域(content)、内边距(padding)和边框(border)的总尺寸,也就是所谓的"标准盒模型"。而当设置为 `box-sizing: border-box;` 后,元素的总宽度和高度会包括内容、内边距和边框的总空间,这样就使得开发者更容易控制元素的实际布局大小。 具体来说,这意味着: 1. 内容区域的宽度和高度不会因为添加内边距或边框而自动扩展。 2. 边框和内边距会从元素的总尺寸中减去,而不是从内容区域开始计算。
recommend-type

经典:大学答辩通过_基于ARM微处理器的嵌入式指纹识别系统设计.pdf

本文主要探讨的是"经典:大学答辩通过_基于ARM微处理器的嵌入式指纹识别系统设计.pdf",该研究专注于嵌入式指纹识别技术在实际应用中的设计和实现。嵌入式指纹识别系统因其独特的优势——无需外部设备支持,便能独立完成指纹识别任务,正逐渐成为现代安全领域的重要组成部分。 在技术背景部分,文章指出指纹的独特性(图案、断点和交叉点的独一无二性)使其在生物特征认证中具有很高的可靠性。指纹识别技术发展迅速,不仅应用于小型设备如手机或门禁系统,也扩展到大型数据库系统,如连接个人电脑的桌面应用。然而,桌面应用受限于必须连接到计算机的条件,嵌入式系统的出现则提供了更为灵活和便捷的解决方案。 为了实现嵌入式指纹识别,研究者首先构建了一个专门的开发平台。硬件方面,详细讨论了电源电路、复位电路以及JTAG调试接口电路的设计和实现,这些都是确保系统稳定运行的基础。在软件层面,重点研究了如何在ARM芯片上移植嵌入式操作系统uC/OS-II,这是一种实时操作系统,能够有效地处理指纹识别系统的实时任务。此外,还涉及到了嵌入式TCP/IP协议栈的开发,这是实现系统间通信的关键,使得系统能够将采集的指纹数据传输到远程服务器进行比对。 关键词包括:指纹识别、嵌入式系统、实时操作系统uC/OS-II、TCP/IP协议栈。这些关键词表明了论文的核心内容和研究焦点,即围绕着如何在嵌入式环境中高效、准确地实现指纹识别功能,以及与外部网络的无缝连接。 这篇论文不仅深入解析了嵌入式指纹识别系统的硬件架构和软件策略,而且还展示了如何通过结合嵌入式技术和先进操作系统来提升系统的性能和安全性,为未来嵌入式指纹识别技术的实际应用提供了有价值的研究成果。