File size: 563 Bytes
2a2ae9a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import threading
from tensorboardX import SummaryWriter
class SingleSummaryWriter(SummaryWriter):
_instance_lock = threading.Lock()
def __init__(self, logdir=None, **kwargs):
super().__init__(logdir, **kwargs)
def __new__(cls, *args, **kwargs):
if not hasattr(SingleSummaryWriter, "_instance"):
with SingleSummaryWriter._instance_lock:
if not hasattr(SingleSummaryWriter, "_instance"):
SingleSummaryWriter._instance = object.__new__(cls)
return SingleSummaryWriter._instance
|