ktl014
7/28/2017 - 4:54 PM

check run time for training network

check run time for training network

import timeit
    # Perform classification
    t1 = timeit.default_timer() # start timer
    output = net.forward()
    t2 = timeit.default_timer() # end timer
    print 'time is {}'.format(t2-t1)
#set CPU as the computing device
caffe.set_mode_cpu()
#compute the output
out = net.forward()

#now time it in CPU
t1 = timeit.default_timer()
out = net.forward()
t2 = timeit.default_timer()


#set GPU as the computing device
caffe.set_device(0)
caffe.set_mode_gpu()

#compute the output
out = net.forward()

#now time it again in GPU
t3 = timeit.default_timer()
out = net.forward()
t4 = timeit.default_timer()

print 'CPU Time : ', t2-t1
print 'GPU Time : ', t4-t3
print 'GPU is ', (t2-t1)/(t4-t3), ' times faster'