I am currently working on a deep neural network, but i am confused about how we can compute the training time of a deep neural network. How i will know that my neural network takes less time compared to other deep neural networks.
I am looking forward to your help and any article recommendation.
CodePudding user response:
Comparison of ML Models shouldn't be on the basis of training time, as time taken can differ on many factors:
- 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.
But if you're using Multi-Threading / Multi-Processing to train your model, and want to know if that is helping or not, you can use timing functions provided by python.
1. Using perf_counter() from time module
from time import perf_counter, sleep
start = perf_counter()
# Some Code
sleep(1)
sleep(0.2)
end = perf_counter()
print(f"Time taken to execute code : {end-start}")
2. Using %%time in .ipynb notebooks
%%time
# Some Code
import time
time.sleep(1)
time.sleep(0.2)
CodePudding user response:
- If you are using a jupyter notebook or any notebook using a .ipynb file then you can use the:
%%time
, to calculate the time to run the cell. - If you are planning to use a .py code and just want to calculate the time the code runs you can utilise the
time
library before and after the training portion of the code, you could use the following method
from time import time
start = time()
"Your code"
print(time()-start)