当前位置:网站首页>写代码复现论文的几点建议!
写代码复现论文的几点建议!
2022-06-12 00:45:00 【Datawhale】

不知道大家有时候会不会有一个很好的idea,但是就是写不出来具体的代码,或者写的代码不够高效。
其实这种情况所有人都会遇到:
场景1:比赛期间有一个新特征的方法,但是用pandas实现太慢,时间复杂度太高。场景2:科研或工作遇到一个新问题,进入一个新领域,不知道如何开始。场景3:复现别人的深度学习论文,但就是没法成功。
场景1:代码太慢
现在不管是比赛还是常见的数据处理,都会遇到大规模的文件。此时如果你代码写的不够高效,代码肯定会运行的很慢很慢,基本上没法满足要求。
步骤1:写出基础代码
使用少量数据集来实践你的思路,代码可以不用很优化,优先写出来即可。写完后建议封装为函数,方便调用。
步骤2:优化代码逻辑
在不断增加数据量的过程中,你会发现代码越来越慢,逐渐达到你的预期上限。此时你应该尝试去优化你的代码了。
优化代码有一些基础的逻辑:
代码本身足够高效吗?
代码是否利用了所有的CPU/GPU?
例如在使用Pandas时,如果不了解具体的语法,很容易将代码写成for循环,可以参考以下优化过程。
下标循环
df1 = df
for i in range(len(df)):
if df.iloc[i]['test'] != 1:
df1.iloc[i]['test'] = 0Iterrows循环
i = 0
for ind, row in df.iterrows():
if row['test'] != 1:
df1.iloc[i]['test'] = 0
i += 1Apply循环
df1['test'] = df['test'].apply(lambda x: x if x == 1 else 0)内置函数
res = df.sum()Numpy函数
df_values = df.values
res = np.sum(df_values)步骤3:提高资源利用率
当你逐步对Pandas和Numpy的熟悉过程中,你会发现自己的代码也运行的越来越快。如果最终代码都是用内置函数实现,基本上已经很好了。
但也可以进一步优化,因为Pandas很多操作都是串行单线程执行,所以可以手动开多线程进一步加速数据的计算过程,把所有CPU用上,或使用cuDF利用GPU加速。
场景2:新领域无从下手
阅读已有新工作的必经之路,所以努力要站在巨人的肩膀上。
阅读目标领域内近3-5年顶会论文,特别是综述论文。
收集公开赛事或榜单上学习Top名次的解决方案,包含思路和代码。
无他唯孰能尔,多收集多整理,理解领域思路和套路。
场景3:复现别人的论文
科研并不是从0到1,一定要多去了解已有的工作,以及已有的论文代码。在阅读完论文代码后,可以按照如下步骤逐步复现:
步骤1:找到有开源代码的论文
在Github上找到历史的有代码的论文,这些论文项目虽然比较旧,但参考价值很大。
步骤2:整理好数据集的加载
搞清楚数据集怎么制作怎么加载怎么输入怎么计算怎么输出,数据集如何处理,如何编码。
步骤3:搭建论文模型
基于论文思路整理好模型结构,有多少层,每层的细节,每层的维度,一步一步搭建。保证模型可以正常训练和预测。
步骤4:确定训练细节
根据论文实验部分的细节,确定具体的batch、epoch、学习率和优化器,确定训练的流程没有问题。

整理不易,点赞三连↓
边栏推荐
- [answer] what does UML use to represent hexagonal architecture
- Lambda快速入门
- Lambda intermediate operation skip
- 2022 edition of global and Chinese on silicon liquid crystal market supply and demand research and prospect Trend Forecast Report
- Invalid spacing setting before WPS Title segment solution
- What does the Red Cross of win10 folder status indicate
- Month selector disable data after the current month to include the current month
- 2022 edition of global and Chinese hexamethylene chloride industry dynamic research and investment prospect forecast report
- Xiaomu's interesting PWN
- 2023 spring recruit | ant group middleware Intern Recruitment
猜你喜欢

KV storage separation principle and performance evaluation of nebula graph

Exploration of qunar risk control safety products

'virtue and art' in the field of recurrent+transformer video recovery

2022 Tibet latest special worker (construction elevator) simulation test question bank and answers

System.CommandLine选项Option

模块八-设计消息队列存储消息数据的 MySQL 表格

LabVIEW Arduino电子称重系统(项目篇—1)

Industrial control system ICs

Visitors push e-commerce express without tossing about personal payment codes

How to uninstall pscs6 in win10 system
随机推荐
Devops landing practice drip and pit stepping records - (1)
Bgfx multithreaded rendering
UVM: transaction level modeling (TLM) 1.0 communication standard
2022 edition of global and Chinese high purity silicon carbide powder operation research and investment strategy analysis report
Experiment 6 constructor + copy construction
Virtual human appears on the stage of the Winter Olympic Games, connecting elements of the meta universe
C language pointer and array - learning 23
Explore table component virtualization
Lambda中间操作limit
语义向量检索入门教程
DDD exaggeration, Eric Evans made a bad start
Xiaomu's interesting PWN
Characteristics of JS logical operators
How to optimize the opening speed of website pages to improve the experience?
ironSource  New functions are released, and developers can adjust advertising strategies in real time in the same session
KV storage separation principle and performance evaluation of nebula graph
At the digital data nextionbi online conference, traditional enterprises showed their in-depth understanding of data analysis
Lambda中间操作map
模块八-设计消息队列存储消息数据的 MySQL 表格
1、 Getting started with flutter learn to write a simple client