Skip to content

Commit 6d25060

Browse files
danthe3rdfacebook-github-bot
authored andcommitted
Lazy imports in detectron2
Summary: This should reduce most of the import time for `detectron2.engine` (which is about 0.7s currently, see https://fburl.com/scuba/import_prof/6tywe8xm) Reviewed By: ppwwyyxx Differential Revision: D26072937 fbshipit-source-id: d34aae9c974f4a3d8ec97595ab6f216094d86f15
1 parent 82b9b21 commit 6d25060

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

detectron2/utils/events.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import time
77
from collections import defaultdict
88
from contextlib import contextmanager
9-
import torch
109
from fvcore.common.history_buffer import HistoryBuffer
1110

1211
from detectron2.utils.file_io import PathManager
@@ -198,6 +197,8 @@ def __init__(self, max_iter):
198197
self._last_write = None
199198

200199
def write(self):
200+
import torch
201+
201202
storage = get_event_storage()
202203
iteration = storage.iter
203204
if iteration == self._max_iter:
@@ -343,6 +344,8 @@ def put_histogram(self, hist_name, hist_tensor, bins=1000):
343344
into a histogram.
344345
bins (int): Number of histogram bins.
345346
"""
347+
import torch
348+
346349
ht_min, ht_max = hist_tensor.min().item(), hist_tensor.max().item()
347350

348351
# Create a histogram with PyTorch

0 commit comments

Comments
 (0)