Skip to content

Commit

Permalink
Change how TensorBoard demo routing works, so that it will load on Te…
Browse files Browse the repository at this point in the history
…nsorFlow.org

Change: 119090272
  • Loading branch information
teamdandelion authored and tensorflower-gardener committed Apr 5, 2016
1 parent 8b3602d commit 9986acd
Show file tree
Hide file tree
Showing 38 changed files with 34 additions and 20 deletions.
20 changes: 16 additions & 4 deletions tensorflow/tensorboard/components/tf-backend/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ module TF.Backend {
}
function standardRoute(route: string): ((tag: string, run: string) => string) {
return function(tag: string, run: string): string {
return dataDir + "/" + route + clean(queryEncoder({tag: tag, run: run}));
var url = dataDir + "/" + route + clean(queryEncoder({tag: tag, run: run}));
if (demoMode) {
url += ".json";
}
return url;
};
}
function individualImageUrl(query: string) {
return dataDir + "/" + clean("individualImage?" + query);
var url = dataDir + "/" + clean("individualImage?" + query);
if (demoMode) {
url += ".png";
}
return url;
}
function graphUrl(run: string, limit_attr_size?: number,
large_attrs_key?: string) {
Expand All @@ -57,10 +65,14 @@ module TF.Backend {
let query = query_params.map(param => {
return param[0] + "=" + encodeURIComponent(param[1]);
}).join("&");
return dataDir + "/graph" + clean("?" + query);
var url = dataDir + "/graph" + clean("?" + query);
if (demoMode) {
url += ".pbtxt";
}
return url;
}
return {
runs: () => dataDir + "/runs",
runs: () => dataDir + "/runs" + (demoMode ? ".json" : ""),
individualImage: individualImageUrl,
graph: graphUrl,
scalars: standardRoute("scalars"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ module TF.Backend {
var backend: Backend;
var rm: RequestManager;
var base = "data";
var demoRouter = TF.Backend.router(base, true);
beforeEach(function() {
// Construct a demo Backend (third param is true)
var router = TF.Backend.router(base, true);
backend = new Backend(router);
backend = new Backend(demoRouter);
rm = new RequestManager();
});

it("runs are loaded properly", function(done) {
var runsResponse = backend.runs();
var actualRuns = rm.request(base + "/runs");
var actualRuns = rm.request(demoRouter.runs());
Promise.all([runsResponse, actualRuns]).then((values) => {
assert.deepEqual(values[0], values[1]);
done();
Expand Down Expand Up @@ -103,8 +103,7 @@ module TF.Backend {
assert.isNumber(image.width);
assert.isNumber(image.height);
var nonDemoQuery = "index=0&tag=im1&run=run1";
var nonDemoUrl = "individualImage?" + nonDemoQuery;
var expectedUrl = base + "/" + TF.Backend.demoify(nonDemoUrl);
var expectedUrl = demoRouter.individualImage(nonDemoQuery);
assert.equal(image.url, expectedUrl);
done();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"wall_time": 0, "step": 0, "query": "index=0&tag=im1&run=run1", "width": 1, "height": 1}]
[{"wall_time": 0, "step": 0, "query": "index=0&tag=im1&run=run1", "width": 1, "height": 1}]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"wall_time": 1459200389.088045, "width": 4, "height": 4, "step": 0, "query": "tag=im1%2Fimage%2F0&index=0&run=run1"}]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"wall_time": 1459200389.093653, "width": 4, "height": 4, "step": 0, "query": "tag=im2%2Fimage%2F0&index=0&run=run1"}]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"wall_time": 1459200389.117463, "width": 4, "height": 4, "step": 0, "query": "tag=im1%2Fimage%2F0&index=0&run=run2"}]
1 change: 0 additions & 1 deletion tensorflow/tensorboard/demo/data/runs

This file was deleted.

1 change: 1 addition & 0 deletions tensorflow/tensorboard/demo/data/runs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"run2": {"histograms": ["histo1", "histo2"], "run_metadata": [], "scalars": ["foo/cos", "bar/square", "foo/square"], "graph": true, "images": ["im1/image/0"], "compressedHistograms": ["histo1", "histo2"]}, "run1": {"histograms": ["histo1"], "run_metadata": [], "scalars": ["foo/sin", "foo/cos", "bar/square", "foo/square"], "graph": true, "images": ["im2/image/0", "im1/image/0"], "compressedHistograms": ["histo1"]}}
1 change: 0 additions & 1 deletion tensorflow/tensorboard/demo/data/scalars

This file was deleted.

1 change: 1 addition & 0 deletions tensorflow/tensorboard/demo/data/scalars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"run2": {"foo/cos": [[0.0, 0, 2.0], [10.0, 1, 1.0806045532226562], [20.0, 2, -0.832293689250946], [30.0, 3, -1.979984998703003], [40.0, 4, -1.3072872161865234]], "bar/square": [[0.0, 0, 0.0], [10.0, 1, 1.0], [20.0, 2, 4.0], [30.0, 3, 9.0], [40.0, 4, 16.0]], "foo/square": [[0.0, 0, 0.0], [10.0, 1, 2.0], [20.0, 2, 8.0], [30.0, 3, 18.0], [40.0, 4, 32.0]]}, "run1": {"foo/sin": [[0.0, 0, 0.0], [10.0, 1, 0.8414709568023682], [20.0, 2, 0.9092974066734314], [30.0, 3, 0.14112000167369843], [40.0, 4, -0.756802499294281]], "foo/cos": [[0.0, 0, 1.0], [10.0, 1, 0.5403022766113281], [20.0, 2, -0.416146844625473], [30.0, 3, -0.9899924993515015], [40.0, 4, -0.6536436080932617]], "bar/square": [[0.0, 0, 0.0], [10.0, 1, 1.0], [20.0, 2, 4.0], [30.0, 3, 9.0], [40.0, 4, 16.0]], "foo/square": [[0.0, 0, 0.0], [10.0, 1, 1.0], [20.0, 2, 4.0], [30.0, 3, 9.0], [40.0, 4, 16.0]]}}
13 changes: 8 additions & 5 deletions tensorflow/tensorboard/scripts/serialize_tensorboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
FLAGS = tf.flags.FLAGS

BAD_CHARACTERS = "#%&{}\\/<>*? $!'\":@+`|="
DEFAULT_SUFFIX = '.json'
IMAGE_SUFFIX = '.png'
GRAPH_SUFFIX = '.pbtxt'


def Url(route, params):
Expand Down Expand Up @@ -85,13 +88,13 @@ def __init__(self, connection, target_path):
EnsureDirectoryExists(os.path.join(target_path, 'data'))
self.path = target_path

def GetAndSave(self, url, unzip=False):
def GetAndSave(self, url, save_suffix, unzip=False):
"""GET the given url. Serialize the result at clean path version of url."""
self.connection.request('GET',
'/data/' + url,
headers={'content-type': 'text/plain'})
response = self.connection.getresponse()
destination = self.path + '/data/' + Clean(url)
destination = self.path + '/data/' + Clean(url) + save_suffix

if response.status != 200:
raise IOError(url)
Expand All @@ -109,7 +112,7 @@ def GetAndSave(self, url, unzip=False):
def GetRouteAndSave(self, route, params=None):
"""GET given route and params. Serialize the result. Return as JSON."""
url = Url(route, params)
return json.loads(self.GetAndSave(url))
return json.loads(self.GetAndSave(url, DEFAULT_SUFFIX))

def Run(self):
"""Serialize everything from a TensorBoard backend."""
Expand All @@ -127,14 +130,14 @@ def Run(self):
# in this case, tags is a bool which specifies if graph is present.
if tags:
url = Url('graph', {'run': run})
self.GetAndSave(url, unzip=True)
self.GetAndSave(url, GRAPH_SUFFIX, unzip=True)
elif tag_type == 'images':
for t in tags:
images = self.GetRouteAndSave('images', {'run': run, 'tag': t})
for im in images:
url = 'individualImage?' + im['query']
# pull down the images themselves.
self.GetAndSave(url)
self.GetAndSave(url, IMAGE_SUFFIX)
else:
for t in tags:
# Save this, whatever it is :)
Expand Down

0 comments on commit 9986acd

Please sign in to comment.