|
32 | 32 | # create histogram |
33 | 33 | with logw.mode('train') as logger: |
34 | 34 | histogram = logger.histogram("scratch/histogram", num_buckets=200) |
| 35 | + histogram0 = logger.histogram("scratch/histogram0", num_buckets=200) |
35 | 36 | for step in range(1, 100): |
36 | 37 | histogram.add_record(step, |
37 | 38 | np.random.normal( |
38 | 39 | 0.1 + step * 0.001, |
39 | 40 | 200. / (100 + step), |
40 | 41 | 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)) |
41 | 49 | # create image |
42 | 50 | 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 | + |
45 | 54 | dog_jpg = Image.open(os.path.join(ROOT, 'python/dog.jpg')) |
46 | 55 | dog_jpg = dog_jpg.resize(np.array(dog_jpg.size) / 2) |
47 | 56 | shape = [dog_jpg.size[1], dog_jpg.size[0], 3] |
48 | 57 |
|
| 58 | + # add dog's image |
49 | 59 | for pass_ in xrange(4): |
50 | 60 | image.start_sampling() |
51 | 61 | for sample in xrange(10): |
52 | | - # randomly crop a demo image. |
| 62 | + # randomly crop a dog's image. |
53 | 63 | target_shape = [100, 100, 3] # width, height, channels(3 for RGB) |
54 | 64 | left_x = random.randint(0, shape[1] - target_shape[1]) |
55 | 65 | left_y = random.randint(0, shape[0] - target_shape[0]) |
56 | 66 | right_x = left_x + target_shape[1] |
57 | 67 | right_y = left_y + target_shape[0] |
58 | 68 |
|
59 | 69 | # 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() |
61 | 72 | if idx >= 0: |
62 | 73 | data = np.array( |
63 | 74 | dog_jpg.crop((left_x, left_y, right_x, |
|
72 | 83 | # image.add_sample(shape, data) |
73 | 84 |
|
74 | 85 | 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() |
0 commit comments