我们如何计算深度神经网络的训练时间?
how we can compute the training time of deep neural networks?
我目前正在研究深度神经网络,但我对如何计算深度神经网络的训练时间感到困惑。我如何知道我的神经网络与其他深度神经网络相比花费的时间更少。
期待您的帮助和任何文章推荐。
ML 模型的比较不应基于训练时间,因为所花费的时间可能因许多因素而异:
- Same code show variable time taken when ran several time, depending upon instantaneous CPU load and performance.
- Size of Dataset taken to train the model.
- Some other factors too, like no of neural network layers, no of neurons in each layer, complexity of activation function used, etc.
但是如果您使用多线程/多处理来训练您的模型,并且想知道这是否有帮助,您可以使用 python.[=27 提供的计时函数=]
1。使用来自时间模块 perf_counter() 的
from time import perf_counter, sleep
start = perf_counter()
# Some Code
end = perf_counter()
print(f"Time taken to execute code : {end-start}")
2。在 .ipynb 笔记本中使用 %%time
%%time
# Some Code
- 如果您使用的是 jupyter 笔记本或任何使用 .ipynb 文件的笔记本,那么您可以使用:
%%time
,计算 运行 单元格的时间。
- 如果您打算使用 .py 代码并且只想计算代码 运行s 的时间,您可以在代码的训练部分之前和之后使用
time
库,你可以使用下面的方法
from time import time
start = time()
"Your code"
print(time()-start)
我目前正在研究深度神经网络,但我对如何计算深度神经网络的训练时间感到困惑。我如何知道我的神经网络与其他深度神经网络相比花费的时间更少。
期待您的帮助和任何文章推荐。
ML 模型的比较不应基于训练时间,因为所花费的时间可能因许多因素而异:
- Same code show variable time taken when ran several time, depending upon instantaneous CPU load and performance.
- Size of Dataset taken to train the model.
- Some other factors too, like no of neural network layers, no of neurons in each layer, complexity of activation function used, etc.
但是如果您使用多线程/多处理来训练您的模型,并且想知道这是否有帮助,您可以使用 python.[=27 提供的计时函数=]
1。使用来自时间模块 perf_counter() 的
from time import perf_counter, sleep
start = perf_counter()
# Some Code
end = perf_counter()
print(f"Time taken to execute code : {end-start}")
2。在 .ipynb 笔记本中使用 %%time
%%time
# Some Code
- 如果您使用的是 jupyter 笔记本或任何使用 .ipynb 文件的笔记本,那么您可以使用:
%%time
,计算 运行 单元格的时间。 - 如果您打算使用 .py 代码并且只想计算代码 运行s 的时间,您可以在代码的训练部分之前和之后使用
time
库,你可以使用下面的方法
from time import time
start = time()
"Your code"
print(time()-start)