diff --git a/server/visualdl/lib.py b/server/visualdl/lib.py index c86fe14643eb8804af102004eb6528a7f87fa80c..e22cd07a7e7f7066f3a43bd65109170bec96a878 100644 --- a/server/visualdl/lib.py +++ b/server/visualdl/lib.py @@ -21,6 +21,18 @@ def get_scalar_tags(storage, mode): return result +def get_scalar(storage, mode, tag): + reader = storage.as_mode(mode) + scalar = reader.scalar(tag) + + records = scalar.records() + ids = scalar.ids() + timestamps = scalar.timestamps() + + result = zip(timestamps, ids, records) + return result + + def get_image_tags(storage, mode): result = {} @@ -31,16 +43,17 @@ def get_image_tags(storage, mode): result[mode] = {} for tag in reader.tags('image'): image = reader.image(tag) - if image.num_samples() == 1: + if image.num_samples() <= 1: result[mode][tag] = { - 'displayName': mage.caption(), + 'displayName': image.caption(), 'description': "", 'samples': 1, } else: for i in xrange(image.num_samples()): - result[mode][tag + '/%d' % i] = { - 'displayName': image.caption(), + caption = tag + '/%d' % i + result[mode][caption] = { + 'displayName': caption, 'description': "", 'samples': 1, } @@ -51,6 +64,7 @@ def get_image_tag_steps(storage, mode, tag): # remove suffix '/x' res = re.search(r".*/([0-9]+$)", tag) step_index = 0 + origin_tag = tag if res: tag = tag[:tag.rfind('/')] step_index = int(res.groups()[0]) @@ -65,7 +79,7 @@ def get_image_tag_steps(storage, mode, tag): query = urllib.urlencode({ 'sample': 0, 'index': i, - 'tag': tag, + 'tag': origin_tag, 'run': mode, }) res.append({ diff --git a/server/visualdl/run.sh b/server/visualdl/run.sh index 227f596c4bb273387203d5f333efc3c2da022271..b67a4d339e74d206b0ed3f2d3d123da44a128b3c 100644 --- a/server/visualdl/run.sh +++ b/server/visualdl/run.sh @@ -2,5 +2,7 @@ set -ex export PYTHONPATH="$(pwd)/..:/home/superjom/project/VisualDL/build/visualdl/logic:/home/superjom/project/VisualDL/visualdl/python" +export FLASK_APP=visual_dl.py +export FLASK_DEBUG=1 -python visual_dl.py --logdir ./tmp/mock --host 172.23.233.68 +python visual_dl.py --logdir ./tmp/mock --host 172.23.233.68 --port 8041 diff --git a/server/visualdl/visual_dl.py b/server/visualdl/visual_dl.py index 98b1d87da7715fdf7403e3007b75dbb0d4967cf8..953b0203553c6a4c48d654a14e929d537fa73bcd 100644 --- a/server/visualdl/visual_dl.py +++ b/server/visualdl/visual_dl.py @@ -95,7 +95,8 @@ def runs(): @app.route("/data/plugin/scalars/tags") -def tags(): +def scalar_tags(): + mode = request.args.get('mode') is_debug = bool(request.args.get('debug')) if is_debug: result = mock_tags.data() @@ -107,7 +108,8 @@ def tags(): @app.route("/data/plugin/images/tags") -def tags(): +def image_tags(): + mode = request.args.get('mode') result = lib.get_image_tags(storage, mode) print 'tags', result result = gen_result(0, "", result) @@ -120,39 +122,33 @@ def scalars(): tag = request.args.get('tag') is_debug = bool(request.args.get('debug')) if is_debug: - result = gen_result(0, "", mock_data.sequence_data()) + result = mock_data.sequence_data() else: - reader = storage.as_mode(run) - scalar = reader.scalar(tag) - - records = scalar.records() - ids = scalar.ids() - timestamps = scalar.timestamps() - - result = zip(timestamps, ids, records) - result = gen_result(0, "", result) + result = lib.get_scalar(storage, run, tag) + result = gen_result(0, "", result) return Response(json.dumps(result), mimetype='application/json') @app.route('/data/plugin/images/images') def images(): - run = request.args.get('run') - tag = request.args.get('tag') + mode = request.args.get('run') + #tag = request.args.get('tag') + tag = request.args.get('displayName') - res = lib.gen_image_tag_steps(storage, mode, tag) + result = lib.get_image_tag_steps(storage, mode, tag) return Response(json.dumps(result), mimetype='application/json') @app.route('/data/plugin/images/individualImage') def individual_image(): - run = request.args.get('run') + mode = request.args.get('run') tag = request.args.get('tag') # include a index - index = request.args.get('index') # index of step + step_index = request.args.get('index') # index of step offset = 0 - imagefile = lib.get_invididual_image(storage, mode, tag) + imagefile = lib.get_invididual_image(storage, mode, tag, step_) response = send_file( imagefile, as_attachment=True, attachment_filename='img.png') return response @@ -160,4 +156,4 @@ def individual_image(): if __name__ == '__main__': logger.info(" port=" + str(options.port)) - app.run(debug=False, host=options.host, port=options.port) + app.run(debug=True, host=options.host, port=options.port)