Skip to content

Commit a1176e5

Browse files
Superjomndaming-lu
authored andcommitted
Feature/fix online scratch (#160)
1 parent 9a5a3bc commit a1176e5

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

demo/vdl_scratch.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,43 @@
3232
# create histogram
3333
with logw.mode('train') as logger:
3434
histogram = logger.histogram("scratch/histogram", num_buckets=200)
35+
histogram0 = logger.histogram("scratch/histogram0", num_buckets=200)
3536
for step in range(1, 100):
3637
histogram.add_record(step,
3738
np.random.normal(
3839
0.1 + step * 0.001,
3940
200. / (100 + step),
4041
size=1000))
42+
43+
for step in range(1, 50):
44+
histogram0.add_record(step,
45+
np.random.normal(
46+
0.1 + step * 0.003,
47+
200. / (120 + step),
48+
size=1000))
4149
# create image
4250
with logw.mode("train") as logger:
43-
image = logger.image("scratch/dog", 4,
44-
1) # randomly sample 4 images one pass
51+
image = logger.image("scratch/dog", 4) # randomly sample 4 images one pass
52+
image0 = logger.image("scratch/random", 4)
53+
4554
dog_jpg = Image.open(os.path.join(ROOT, 'python/dog.jpg'))
4655
dog_jpg = dog_jpg.resize(np.array(dog_jpg.size) / 2)
4756
shape = [dog_jpg.size[1], dog_jpg.size[0], 3]
4857

58+
# add dog's image
4959
for pass_ in xrange(4):
5060
image.start_sampling()
5161
for sample in xrange(10):
52-
# randomly crop a demo image.
62+
# randomly crop a dog's image.
5363
target_shape = [100, 100, 3] # width, height, channels(3 for RGB)
5464
left_x = random.randint(0, shape[1] - target_shape[1])
5565
left_y = random.randint(0, shape[0] - target_shape[0])
5666
right_x = left_x + target_shape[1]
5767
right_y = left_y + target_shape[0]
5868

5969
# a more efficient way to sample images
60-
idx = image.is_sample_taken() # check whether this image will be taken by reservoir sampling
70+
# check whether this image will be taken by reservoir sampling
71+
idx = image.is_sample_taken()
6172
if idx >= 0:
6273
data = np.array(
6374
dog_jpg.crop((left_x, left_y, right_x,
@@ -72,3 +83,12 @@
7283
# image.add_sample(shape, data)
7384

7485
image.finish_sampling()
86+
87+
# add randomly generated image
88+
for pass_ in xrange(4):
89+
image0.start_sampling()
90+
for sample in xrange(10):
91+
shape = [40, 30, 3]
92+
data = np.random.random(shape).flatten()
93+
image0.add_sample(shape, list(data))
94+
image0.finish_sampling()

visualdl/server/visualDL

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,13 @@ def index():
109109

110110
@app.route('/static/<path:filename>')
111111
def serve_static(filename):
112-
print 'serve static ', filename
113112
return send_from_directory(
114113
os.path.join(server_path, static_file_path), filename)
115114

116115

117116
@app.route('/graphs/image')
118117
def serve_graph():
119-
return send_file(graph_image_path)
118+
return send_file(os.path.join(os.getcwd(), graph_image_path))
120119

121120

122121
@app.route('/data/logdir')

0 commit comments

Comments
 (0)