Skip to content

Commit

Permalink
s2ms (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenYuhan authored Sep 3, 2020
1 parent 52f2626 commit b5026ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
16 changes: 10 additions & 6 deletions visualdl/server/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
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')
Expand Down Expand Up @@ -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


Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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),
Expand All @@ -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


Expand Down Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions visualdl/writer/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def add_meta(self, tag='meta_data_tag', display_name='', step=0, walltime=None):
"""
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))
Expand All @@ -159,7 +159,7 @@ def add_scalar(self, tag, value, step, walltime=None):
"""
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))

Expand All @@ -182,7 +182,7 @@ def add_image(self, tag, img, step, walltime=None):
"""
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))

Expand All @@ -207,7 +207,7 @@ def add_embeddings(self, tag, labels, hot_vectors, walltime=None):
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!")
Expand All @@ -216,7 +216,7 @@ def add_embeddings(self, tag, labels, hot_vectors, walltime=None):
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,
Expand Down Expand Up @@ -260,7 +260,7 @@ def add_audio(self,
"""
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(
Expand Down Expand Up @@ -297,7 +297,7 @@ def add_histogram(self,
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,
Expand Down Expand Up @@ -338,7 +338,7 @@ def add_pr_curve(self,
"""
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,
Expand Down

0 comments on commit b5026ee

Please sign in to comment.