提交 dd02ed4a 编写于 作者: S superjom

Merge branch 'feature/add_image_component-debug_image' into feature/add_image_component

...@@ -51,9 +51,9 @@ def get_image_tags(storage): ...@@ -51,9 +51,9 @@ def get_image_tags(storage):
for tag in tags: for tag in tags:
image = reader.image(tag) image = reader.image(tag)
for i in xrange(max(1, image.num_samples())): for i in xrange(max(1, image.num_samples())):
tag = image.caption() if image.num_samples() <= 1 else '%s/%d'%(tag, i) caption = tag if image.num_samples() <= 1 else '%s/%d'%(tag, i)
result[mode][tag] = { result[mode][caption] = {
'displayName': tag, 'displayName': caption,
'description': "", 'description': "",
'samples': 1, 'samples': 1,
} }
...@@ -61,6 +61,7 @@ def get_image_tags(storage): ...@@ -61,6 +61,7 @@ def get_image_tags(storage):
def get_image_tag_steps(storage, mode, tag): def get_image_tag_steps(storage, mode, tag):
print 'image_tag_steps,mode,tag:', mode, tag
# remove suffix '/x' # remove suffix '/x'
res = re.search(r".*/([0-9]+$)", tag) res = re.search(r".*/([0-9]+$)", tag)
sample_index = 0 sample_index = 0
...@@ -76,6 +77,7 @@ def get_image_tag_steps(storage, mode, tag): ...@@ -76,6 +77,7 @@ def get_image_tag_steps(storage, mode, tag):
for step_index in range(image.num_records()): for step_index in range(image.num_records()):
record = image.record(step_index, sample_index) record = image.record(step_index, sample_index)
shape = record.shape() shape = record.shape()
assert shape, "%s,%s" % (mode, tag)
query = urllib.urlencode({ query = urllib.urlencode({
'sample': 0, 'sample': 0,
'index': step_index, 'index': step_index,
......
import lib
import unittest
import storage
import pprint
from storage_mock import add_scalar, add_image
class LibTest(unittest.TestCase):
def setUp(self):
dir = "./tmp/mock"
writer = storage.StorageWriter(dir, sync_cycle=20)
add_scalar(writer, "train", "layer/scalar0/min", 1000, 1)
add_scalar(writer, "test", "layer/scalar0/min", 1000, 10)
add_scalar(writer, "valid", "layer/scalar0/min", 1000, 10)
add_scalar(writer, "train", "layer/scalar0/max", 1000, 1)
add_scalar(writer, "test", "layer/scalar0/max", 1000, 10)
add_scalar(writer, "valid", "layer/scalar0/max", 1000, 10)
add_image(writer, "train", "layer/image0", 7, 10, 1)
add_image(writer, "test", "layer/image0", 7, 10, 3)
self.reader = storage.StorageReader(dir)
def test_modes(self):
modes = lib.get_modes(self.reader)
self.assertEqual(sorted(modes), sorted(["train", "test", "valid"]))
def test_scalar(self):
for mode in "train test valid".split():
tags = lib.get_scalar_tags(self.reader, mode)
print 'scalar tags:'
pprint.pprint(tags)
self.assertEqual(len(tags), 3)
self.assertEqual(sorted(tags.keys()), sorted("train test valid".split()))
def test_image(self):
tags = lib.get_image_tags(self.reader)
self.assertEqual(len(tags), 2)
tags = lib.get_image_tag_steps(self.reader, 'train', 'layer/image0/0')
pprint.pprint(tags)
image = lib.get_invididual_image(self.reader, "train", 'layer/image0/0', 2)
print image
if __name__ == '__main__':
unittest.main()
...@@ -3,4 +3,4 @@ set -ex ...@@ -3,4 +3,4 @@ set -ex
export PYTHONPATH="/home/superjom/project/VisualDL/build/visualdl/logic:/home/superjom/project/VisualDL/visualdl/python" export PYTHONPATH="/home/superjom/project/VisualDL/build/visualdl/logic:/home/superjom/project/VisualDL/visualdl/python"
python storage_mock.py python lib_test.py
...@@ -26,11 +26,12 @@ def add_image(writer, ...@@ -26,11 +26,12 @@ def add_image(writer,
for pass_ in xrange(num_passes): for pass_ in xrange(num_passes):
image_writer.start_sampling() image_writer.start_sampling()
for ins in xrange(2 * num_samples): for ins in xrange(2 * num_samples):
print '.',
index = image_writer.is_sample_taken() index = image_writer.is_sample_taken()
if index != -1: if index != -1:
data = np.random.random(shape) * 256 data = np.random.random(shape) * 256
data = np.ndarray.flatten(data) data = np.ndarray.flatten(data)
assert shape
assert len(data) > 0
image_writer.set_sample(index, shape, list(data)) image_writer.set_sample(index, shape, list(data))
image_writer.finish_sampling() image_writer.finish_sampling()
......
...@@ -89,7 +89,7 @@ def logdir(): ...@@ -89,7 +89,7 @@ def logdir():
@app.route('/data/runs') @app.route('/data/runs')
def runs(): def runs():
modes = storage.modes() modes = storage.modes()
result = gen_result(0, "", lib.modes()) result = gen_result(0, "", lib.get_modes())
return Response(json.dumps(result), mimetype='application/json') return Response(json.dumps(result), mimetype='application/json')
......
...@@ -26,6 +26,8 @@ frontend_test() { ...@@ -26,6 +26,8 @@ frontend_test() {
} }
server_test() { server_test() {
cd $cur/server
bash build.sh
cd $cur/server/visualdl cd $cur/server/visualdl
python lib_test.py python lib_test.py
} }
......
...@@ -48,9 +48,8 @@ template class ScalarReader<float>; ...@@ -48,9 +48,8 @@ template class ScalarReader<float>;
template class ScalarReader<double>; template class ScalarReader<double>;
void Image::StartSampling() { void Image::StartSampling() {
// TODO(ChunweiYan) big bug here, every step will be stored in protobuf if (!ToSampleThisStep()) return;
// and that might result in explosion in some scenerios, Just sampling
// some steps should be better.
step_ = writer_.AddRecord(); step_ = writer_.AddRecord();
step_.SetId(step_id_); step_.SetId(step_id_);
...@@ -103,6 +102,7 @@ void Image::SetSample(int index, ...@@ -103,6 +102,7 @@ void Image::SetSample(int index,
// production // production
int size = std::accumulate( int size = std::accumulate(
shape.begin(), shape.end(), 1., [](float a, float b) { return a * b; }); shape.begin(), shape.end(), 1., [](float a, float b) { return a * b; });
CHECK_GT(size, 0);
CHECK_EQ(size, data.size()) << "image's shape not match data"; CHECK_EQ(size, data.size()) << "image's shape not match data";
CHECK_LT(index, num_samples_); CHECK_LT(index, num_samples_);
CHECK_LE(index, num_records_); CHECK_LE(index, num_records_);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册