Эх сурвалжийг харах

refactored utils.SacredPlotter

Dimitri Korsch 3 жил өмнө
parent
commit
76bcfdeca4

+ 4 - 8
cvfinetune/utils/sacred_plotter.py

@@ -5,6 +5,7 @@ import warnings
 from datetime import datetime
 
 from matplotlib.gridspec import GridSpec
+from chainer_addons.utils.sacred import MPIExperiment
 
 def parse_date(date, fmt="{:d}-{:02d}-{:02d} 00:00:00"):
 	if isinstance(date, str):
@@ -25,15 +26,10 @@ def query_to_str(query):
 
 class SacredPlotter(object):
 
-	@staticmethod
-	def auth_url(creds, host="localhost"):
-		url = "mongodb://{user}:{password}@{host}:27017/{db_name}?authSource=admin".format(
-			host=host, **creds)
-		return url
-
-	def __init__(self, creds):
+	def __init__(self, creds, host=None, port=None):
 		super(SacredPlotter, self).__init__()
-		self.client = pym.MongoClient(SacredPlotter.auth_url(creds))
+		auth_url = MPIExperiment.auth_url(creds, host=host, port=port)
+		self.client = pym.MongoClient(auth_url)
 
 		self.db = self.client[creds["db_name"]]
 		self.metrics = self.db["metrics"]