“0bb9c80ef960d777c5937f8fed8ddf75f2ac6a18”上不存在“paddle/phi/kernels/cpu/adadelta_kernel.cc”
未验证 提交 c678924e 编写于 作者: Y Yan Chunwei 提交者: GitHub

Feature/add scratch demo (#150)

上级 ec572c0d
import mxnet as mx import logging
import mxnet as mx
# Here we import LogWriter so that we can write log data while MXNet is training # Here we import LogWriter so that we can write log data while MXNet is training
from visualdl import LogWriter from visualdl import LogWriter
...@@ -45,7 +46,6 @@ def add_scalar(): ...@@ -45,7 +46,6 @@ def add_scalar():
# Start to build CNN in MXNet, train MNIST dataset. For more info, check MXNet's official website: # Start to build CNN in MXNet, train MNIST dataset. For more info, check MXNet's official website:
# https://mxnet.incubator.apache.org/tutorials/python/mnist.html # https://mxnet.incubator.apache.org/tutorials/python/mnist.html
import logging
logging.getLogger().setLevel(logging.DEBUG) # logging to stdout logging.getLogger().setLevel(logging.DEBUG) # logging to stdout
train_iter = mx.io.NDArrayIter(mnist['train_data'], mnist['train_label'], batch_size, shuffle=True) train_iter = mx.io.NDArrayIter(mnist['train_data'], mnist['train_label'], batch_size, shuffle=True)
......
...@@ -2,13 +2,14 @@ from __future__ import print_function ...@@ -2,13 +2,14 @@ from __future__ import print_function
import sys import sys
import numpy as np
from visualdl import LogWriter
import paddle.v2 as paddle import paddle.v2 as paddle
import paddle.v2.fluid as fluid import paddle.v2.fluid as fluid
import paddle.v2.fluid.framework as framework import paddle.v2.fluid.framework as framework
from paddle.v2.fluid.param_attr import ParamAttr
from paddle.v2.fluid.initializer import NormalInitializer from paddle.v2.fluid.initializer import NormalInitializer
from visualdl import LogWriter from paddle.v2.fluid.param_attr import ParamAttr
import numpy as np
logdir = "./tmp" logdir = "./tmp"
logwriter = LogWriter(logdir, sync_cycle=10) logwriter = LogWriter(logdir, sync_cycle=10)
......
#!/user/bin/env python #!/user/bin/env python
import math
import os import os
from visualdl import LogWriter, ROOT import random
import subprocess import subprocess
from scipy.stats import norm
import numpy as np import numpy as np
import random
from PIL import Image from PIL import Image
from scipy.stats import norm
from visualdl import ROOT, LogWriter
logdir = './scratch_log' logdir = './scratch_log'
...@@ -19,22 +21,29 @@ with logw.mode('test') as logger: ...@@ -19,22 +21,29 @@ with logw.mode('test') as logger:
scalar1 = logger.scalar("scratch/scalar") scalar1 = logger.scalar("scratch/scalar")
# add scalar records. # add scalar records.
for step in range(200): last_record0 = 0.
scalar0.add_record(step, step * 1. / 200) last_record1 = 0.
scalar1.add_record(step, 1. - step * 1. / 200) for step in range(1, 100):
last_record0 += 0.1 * (random.random() - 0.3)
last_record1 += 0.1 * (random.random() - 0.7)
scalar0.add_record(step, last_record0)
scalar1.add_record(step, last_record1)
# create histogram # create histogram
with logw.mode('train') as logger: with logw.mode('train') as logger:
histogram = logger.histogram("scratch/histogram", num_buckets=100) histogram = logger.histogram("scratch/histogram", num_buckets=200)
for step in range(100): for step in range(1, 100):
histogram.add_record(step, histogram.add_record(step,
np.random.normal(0.1 + step * 0.01, size=1000)) np.random.normal(
0.1 + step * 0.001,
200. / (100 + step),
size=1000))
# create image # create image
with logw.mode("train") as logger: with logw.mode("train") as logger:
image = logger.image("scratch/dog", 4, image = logger.image("scratch/dog", 4,
1) # randomly sample 4 images one pass 1) # randomly sample 4 images one pass
dog_jpg = Image.open(os.path.join(ROOT, 'python/dog.jpg')) dog_jpg = Image.open(os.path.join(ROOT, 'python/dog.jpg'))
dog_jpg = dog_jpg.resize(np.array(dog_jpg.size) / 2)
shape = [dog_jpg.size[1], dog_jpg.size[0], 3] shape = [dog_jpg.size[1], dog_jpg.size[0], 3]
for pass_ in xrange(4): for pass_ in xrange(4):
...@@ -47,12 +56,13 @@ with logw.mode("train") as logger: ...@@ -47,12 +56,13 @@ with logw.mode("train") as logger:
right_x = left_x + target_shape[1] right_x = left_x + target_shape[1]
right_y = left_y + target_shape[0] right_y = left_y + target_shape[0]
idx = image.is_sample_taken() # a more efficient way to sample images
# a more efficient way to sample images is idx = image.is_sample_taken() # check whether this image will be taken by reservoir sampling
if idx >= 0: if idx >= 0:
data = np.array( data = np.array(
dog_jpg.crop((left_x, left_y, right_x, dog_jpg.crop((left_x, left_y, right_x,
right_y))).flatten() right_y))).flatten()
# add this image to log
image.set_sample(idx, target_shape, data) image.set_sample(idx, target_shape, data)
# you can also just write followig codes, it is more clear, but need to # you can also just write followig codes, it is more clear, but need to
# process image even if it will not be sampled. # process image even if it will not be sampled.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册