Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance/add histogram sample #137

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions visualdl/server/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def get_invididual_image(storage, mode, tag, step_index, max_size=80):
shape = record.shape()

if shape[2] == 1:
shape = [shape[0], shape[1]]
shape = [shape[0], shape[1]]
data = np.array(record.data(), dtype='uint8').reshape(shape)
tempfile = NamedTemporaryFile(mode='w+b', suffix='.png')
with Image.fromarray(data) as im:
Expand All @@ -146,7 +146,7 @@ def get_histogram_tags(storage):
return get_tags(storage, 'histogram')


def get_histogram(storage, mode, tag):
def get_histogram(storage, mode, tag, num_samples=200):
with storage.mode(mode) as reader:
histogram = reader.histogram(tag)
res = []
Expand All @@ -171,7 +171,21 @@ def get_histogram(storage, mode, tag):
[instance.left(),
instance.right(),
instance.frequency()])
return res
if len(res) < num_samples:
return res

# sample some steps
span = float(len(res)) / (num_samples - 1)
span_offset = 0
data_idx = 0

sampled_data = []
while data_idx < num_samples:
sampled_data.append(res[len(res) - data_idx - 1])
Copy link
Member

Choose a reason for hiding this comment

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

  1. len(res)可以存下来使用
  2. 为啥从后往前抽数据最后在逆序?
  3. 不应该如下?
while span_offset < num_samples 

Copy link
Contributor Author

@Superjomn Superjomn Jan 14, 2018

Choose a reason for hiding this comment

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

逆序保证从最新的数据到最旧的数据

span_offset += 1
data_idx = int(span_offset * span)
sampled_data.append(res[0])
return sampled_data[::-1]


if __name__ == '__main__':
Expand Down