storage_mock.py 1.4 KB
Newer Older
S
superjom 已提交
1 2
import random
import time
S
superjom 已提交
3 4 5 6
import unittest

import numpy as np

S
superjom 已提交
7

S
superjom 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
def add_scalar(writer, mode, tag, num_steps, skip):
    my_writer = writer.as_mode(mode)
    scalar = my_writer.scalar(tag)
    for i in range(num_steps):
        if i % skip == 0:
            scalar.add_record(i, random.random())


def add_image(writer,
              mode,
              tag,
              num_samples,
              num_passes,
              step_cycle,
              shape=[50, 50, 3]):
S
superjom 已提交
23
    writer_ = writer.as_mode(mode)
S
superjom 已提交
24
    image_writer = writer_.image(tag, num_samples, step_cycle)
S
superjom 已提交
25 26 27

    for pass_ in xrange(num_passes):
        image_writer.start_sampling()
S
superjom 已提交
28
        for ins in xrange(2 * num_samples):
S
superjom 已提交
29
            print '.',
S
superjom 已提交
30
            index = image_writer.is_sample_taken()
S
superjom 已提交
31 32 33 34 35 36
            if index != -1:
                data = np.random.random(shape) * 256
                data = np.ndarray.flatten(data)
                image_writer.set_sample(index, shape, list(data))
        image_writer.finish_sampling()

S
superjom 已提交
37 38 39 40 41 42 43 44 45 46 47 48

if __name__ == '__main__':
    add_scalar("train", "layer/scalar0/min", 1000, 1)
    add_scalar("test", "layer/scalar0/min", 1000, 10)
    add_scalar("valid", "layer/scalar0/min", 1000, 10)

    add_scalar("train", "layer/scalar0/max", 1000, 1)
    add_scalar("test", "layer/scalar0/max", 1000, 10)
    add_scalar("valid", "layer/scalar0/max", 1000, 10)

    add_image("train", "layer/image0", 7, 10, 1)
    add_image("test", "layer/image0", 7, 10, 3)