From b5026ee09eb0af5d727ea97dd2eacb4cee23fb57 Mon Sep 17 00:00:00 2001 From: ShenYuhan Date: Thu, 3 Sep 2020 10:18:21 +0800 Subject: [PATCH] s2ms (#781) --- visualdl/server/lib.py | 16 ++++++++++------ visualdl/writer/writer.py | 16 ++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/visualdl/server/lib.py b/visualdl/server/lib.py index 660b1ae6..00ee9550 100644 --- a/visualdl/server/lib.py +++ b/visualdl/server/lib.py @@ -22,6 +22,10 @@ from visualdl.io import bfile from visualdl.utils.string_util import encode_tag, decode_tag +def s2ms(timestamp): + return timestamp * 1000 if timestamp < 2000000000 else timestamp + + def get_components(log_reader): components = log_reader.components(update=True) components.add('graph') @@ -77,7 +81,7 @@ def get_scalar(log_reader, run, tag): log_reader.load_new_data() records = log_reader.data_manager.get_reservoir("scalar").get_items( run, decode_tag(tag)) - results = [[item.timestamp, item.id, item.value] for item in records] + results = [[s2ms(item.timestamp), item.id, item.value] for item in records] return results @@ -92,7 +96,7 @@ def get_image_tag_steps(log_reader, run, tag): run, decode_tag(tag)) result = [{ "step": item.id, - "wallTime": item.timestamp + "wallTime": s2ms(item.timestamp) } for item in records] return result @@ -116,7 +120,7 @@ def get_audio_tag_steps(log_reader, run, tag): run, decode_tag(tag)) result = [{ "step": item.id, - "wallTime": item.timestamp + "wallTime": s2ms(item.timestamp) } for item in records] return result @@ -152,7 +156,7 @@ def get_pr_curve(log_reader, run, tag): pr_curve = item.pr_curve length = len(pr_curve.precision) num_thresholds = [float(v) / length for v in range(1, length + 1)] - results.append([item.timestamp, + results.append([s2ms(item.timestamp), item.id, list(pr_curve.precision), list(pr_curve.recall), @@ -171,7 +175,7 @@ def get_pr_curve_step(log_reader, run, tag=None): log_reader.load_new_data() records = log_reader.data_manager.get_reservoir("pr_curve").get_items( run, decode_tag(tag)) - results = [[item.timestamp, item.id] for item in records] + results = [[s2ms(item.timestamp), item.id] for item in records] return results @@ -213,7 +217,7 @@ def get_histogram(log_reader, run, tag): histogram_data = [] for index in range(len(hist)): histogram_data.append([bin_edges[index], bin_edges[index+1], hist[index]]) - results.append([item.timestamp, item.id, histogram_data]) + results.append([s2ms(item.timestamp), item.id, histogram_data]) return results diff --git a/visualdl/writer/writer.py b/visualdl/writer/writer.py index fed40d59..140c244d 100644 --- a/visualdl/writer/writer.py +++ b/visualdl/writer/writer.py @@ -138,7 +138,7 @@ class LogWriter(object): """ if '%' in tag: raise RuntimeError("% can't appear in tag!") - walltime = round(time.time()) if walltime is None else walltime + walltime = round(time.time() * 1000) if walltime is None else walltime self._get_file_writer().add_record( meta_data(tag=tag, display_name=display_name, step=step, walltime=walltime)) @@ -159,7 +159,7 @@ class LogWriter(object): """ if '%' in tag: raise RuntimeError("% can't appear in tag!") - walltime = round(time.time()) if walltime is None else walltime + walltime = round(time.time() * 1000) if walltime is None else walltime self._get_file_writer().add_record( scalar(tag=tag, value=value, step=step, walltime=walltime)) @@ -182,7 +182,7 @@ class LogWriter(object): """ if '%' in tag: raise RuntimeError("% can't appear in tag!") - walltime = round(time.time()) if walltime is None else walltime + walltime = round(time.time() * 1000) if walltime is None else walltime self._get_file_writer().add_record( image(tag=tag, image_array=img, step=step, walltime=walltime)) @@ -207,7 +207,7 @@ class LogWriter(object): labels = ["label_1", "label_2", "label_3", "label_4", "label_5"] writer.add_embedding(labels=labels, vectors=hot_vectors, - walltime=round(time.time())) + walltime=round(time.time() * 1000)) """ if '%' in tag: raise RuntimeError("% can't appear in tag!") @@ -216,7 +216,7 @@ class LogWriter(object): if isinstance(labels, np.ndarray): labels = labels.tolist() step = 0 - walltime = round(time.time()) if walltime is None else walltime + walltime = round(time.time() * 1000) if walltime is None else walltime self._get_file_writer().add_record( embedding( tag=tag, @@ -260,7 +260,7 @@ class LogWriter(object): """ if '%' in tag: raise RuntimeError("% can't appear in tag!") - walltime = round(time.time()) if walltime is None else walltime + walltime = round(time.time() * 1000) if walltime is None else walltime if isinstance(audio_array, list): audio_array = np.array(audio_array) self._get_file_writer().add_record( @@ -297,7 +297,7 @@ class LogWriter(object): if '%' in tag: raise RuntimeError("% can't appear in tag!") hist, bin_edges = np.histogram(values, bins=buckets) - walltime = round(time.time()) if walltime is None else walltime + walltime = round(time.time() * 1000) if walltime is None else walltime self._get_file_writer().add_record( histogram( tag=tag, @@ -338,7 +338,7 @@ class LogWriter(object): """ if '%' in tag: raise RuntimeError("% can't appear in tag!") - walltime = round(time.time()) if walltime is None else walltime + walltime = round(time.time() * 1000) if walltime is None else walltime self._get_file_writer().add_record( pr_curve( tag=tag, -- GitLab