Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion visualdl/logic/sdk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ std::string LogReader::GenReadableTag(const std::string& mode,

bool LogReader::TagMatchMode(const std::string& tag, const std::string& mode) {
if (tag.size() <= mode.size()) return false;
return tag.substr(0, mode.size()) == mode;
return tag.substr(0, mode.size()) == mode &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tag mode caption之间是什么关系?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • mode 类似 train/test/valid
  • tag 就是组件的标志(key)
  • caption 是组件的名字,不设置则=tag
(tag[mode.size()] == '/' || tag[mode.size()] == '%');
}

namespace components {
Expand Down
16 changes: 16 additions & 0 deletions visualdl/python/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

dtypes = ("float", "double", "int32", "int64")

def check_tag_name_valid(tag):
assert '%' not in tag, "character % is a reserved word, it is not allowed in tag."

def check_mode_name_valid(tag):
for char in ['%', '/']:
assert char not in tag, "character %s is a reserved word, it is not allowed in mode." % char

class LogReader(object):
"""LogReader is a Python wrapper to read and analysis the data that
Expand Down Expand Up @@ -31,13 +37,15 @@ def mode(self, mode):
generated during testing can be marked test.
:return: the reader itself
"""
check_mode_name_valid(mode)
self.reader.set_mode(mode)
return self

def as_mode(self, mode):
"""
create a new LogReader with mode and return it to user.
"""
check_mode_name_valid(mode)
tmp = LogReader(dir, self.reader.as_mode(mode))
return tmp

Expand All @@ -60,6 +68,7 @@ def scalar(self, tag, type='float'):
"""
Get a scalar reader with tag and data type
"""
check_tag_name_valid(tag)
type2scalar = {
'float': self.reader.get_scalar_float,
'double': self.reader.get_scalar_double,
Expand All @@ -71,6 +80,7 @@ def image(self, tag):
"""
Get a image reader with tag
"""
check_tag_name_valid(tag)
return self.reader.get_image(tag)

def histogram(self, tag, type='float'):
Expand All @@ -82,6 +92,7 @@ def histogram(self, tag, type='float'):
'double': self.reader.get_histogram_double,
'int': self.reader.get_histogram_int,
}
check_tag_name_valid(tag)
return type2scalar[type](tag)

def __enter__(self):
Expand All @@ -105,20 +116,23 @@ def __init__(self, dir, sync_cycle, writer=None):
self.writer = writer if writer else core.LogWriter(dir, sync_cycle)

def mode(self, mode):
check_mode_name_valid(mode)
self.writer.set_mode(mode)
return self

def as_mode(self, mode):
"""
create a new LogWriter with mode and return it.
"""
check_mode_name_valid(mode)
LogWriter.cur_mode = LogWriter(self.dir, self.sync_cycle, self.writer.as_mode(mode))
return LogWriter.cur_mode

def scalar(self, tag, type='float'):
"""
Create a scalar writer with tag and type to write scalar data.
"""
check_tag_name_valid(tag)
type2scalar = {
'float': self.writer.new_scalar_float,
'double': self.writer.new_scalar_double,
Expand All @@ -130,13 +144,15 @@ def image(self, tag, num_samples, step_cycle):
"""
Create an image writer that used to write image data.
"""
check_tag_name_valid(tag)
return self.writer.new_image(tag, num_samples, step_cycle)

def histogram(self, tag, num_buckets, type='float'):
"""
Create a histogram writer that used to write
histogram related data.
"""
check_tag_name_valid(tag)
types = {
'float': self.writer.new_histogram_float,
'double': self.writer.new_histogram_double,
Expand Down