You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As pointed out in Pytorch Forums post, CUDA is asynchronous so you will need some tools to measure time.
I then give a simple example which may be helpful:
fromtypingimportUnionimporttorchclassTracker(object):
# original code here.@propertydefis_using_cuda(self):
returnself.device!=torch.device("cpu")
def_init_timer(self):
ifself.is_using_cuda:
self._timer_start=torch.cuda.Event(enable_timing=True)
self._timer_stop=torch.cuda.Event(enable_timing=True)
self._timestamp=Nonedef_start_timing(self) ->Union[float, None]:
ifself.is_using_cuda:
self._timer_start.record()
timestamp=Noneelse:
timestamp=time.time()
self._timestamp=timestampreturntimestampdef_stop_timing(self) ->float:
ifself.is_using_cuda:
self._timer_stop.record()
torch.cuda.synchronize()
# cuda event record return duration in milliseconds.duration=self._timer_start.elapsed_time(
self._timer_stop
)
duration/=1000.0else:
duration=time.time() -self._timestampreturndurationdeftrack(...): # args are omitted here.self._init_timer()
# code for initialization is omitted.forf, img_fileinenumerate(img_files):
# code for data preparation is omitted.self._start_timing()
iff==0:
self.init(image, box)
times[f] =self._stop_timing()
iffail_count>=10andmethod=='restart'andfinrestart_flag:
# the tracker will be restarted when the cumulative number of failures reaches 10print('init again in %s'%f)
init_positions.append(f)
self.init(image, anno[f,:])
fail_count=0else:
frame_box=self.update(image)
frame_box=np.rint(frame_box)
times[f] =self._stop_timing()
# the rest code is omitted.
If you find this code snippet is helpful, you may consider update your toolkit.
The text was updated successfully, but these errors were encountered:
Timing in Tracker may not be accurate enough.
As pointed out in Pytorch Forums post, CUDA is asynchronous so you will need some tools to measure time.
I then give a simple example which may be helpful:
If you find this code snippet is helpful, you may consider update your toolkit.
The text was updated successfully, but these errors were encountered: