-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest.py
70 lines (53 loc) · 2.46 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import numpy as np
import datasets as d
import cv2
from viz.view import reshape_to_row, reshape_to_grid
# INIT CELEBA
# celeba = d.get('celeba', [])
# batch, _ = next(celeba.train_epoch_in_batches(64))
# print(np.shape(list(batch)))
# ex_side = int(np.sqrt(len(batch[0]) / 3))
# SANITY CHECK
# print('min: {}'.format(min(batch[0])))
# print('max: {}'.format(max(batch[0])))
# print('mean: {}'.format(np.mean(np.reshape(batch, (-1,)))))
# print('std: {}'.format(np.std(np.reshape(batch, (-1,)))))
# SHOWING ALL EX IN THIS BATCH
# cv2.imshow('normal.png', reshape_to_grid(np.array(batch), side=ex_side, rgb=True))
# cv2.waitKey(0)
# SHOWING MEANS OF THOSE
# means = [np.squeeze(np.mean(batch, axis=0))]
# cv2.imshow('means.png', reshape_to_row(np.array(means), side=ex_side, rgb=True))
# cv2.waitKey(0)
# TESTING HOW TO BLUR IN TF
# import tensorflow as tf
# blur_kernel = tf.constant([
# [[[1/16, 0, 0], [0, 1/16, 0], [0, 0, 1/16]], [[1/8, 0, 0], [0, 1/8, 0], [0, 0, 1/8]], [[1/16, 0 ,0], [0, 1/16, 0], [0, 0, 1/16]]],
# [[[1/8 , 0, 0], [0, 1/8 , 0], [0, 0, 1/8 ]], [[1/4, 0, 0], [0, 1/4, 0], [0, 0, 1/4]], [[1/8 , 0 ,0], [0, 1/8 , 0], [0, 0, 1/8 ]]],
# [[[1/16, 0, 0], [0, 1/16, 0], [0, 0, 1/16]], [[1/8, 0, 0], [0, 1/8, 0], [0, 0, 1/8]], [[1/16, 0 ,0], [0, 1/16, 0], [0, 0, 1/16]]]])
# imgs = tf.constant(np.asarray(batch), dtype=tf.float32)
# sess = tf.Session()
# blurred = sess.run(tf.nn.conv2d(tf.reshape(imgs, [64, 224, 224, 3]), blur_kernel, strides=[1,1,1,1], padding='SAME'))
# cv2.imshow('normal.png', reshape_to_grid(np.array(batch), side=ex_side, rgb=True))
# cv2.waitKey(10000)
# cv2.imshow('blurred.png', reshape_to_grid(np.array(blurred), side=ex_side, rgb=True))
# cv2.waitKey(10000)
# INIT MNIST
mnist = d.get('mnist', None)
batch, _ = next(mnist.train_epoch_in_batches(64))
print(np.shape(list(batch)))
ex_side = int(np.sqrt(len(batch[0])))
print(ex_side)
# TESTING BLUR IN TF FOR MNIST
import tensorflow as tf
blur_kernel= tf.constant([
[[[1/16]], [[1/8 ]], [[1/16]]],
[[[1/8 ]], [[1/4 ]], [[1/8 ]]],
[[[1/16]], [[1/8 ]], [[1/16]]]])
imgs = tf.constant(np.asarray(batch), dtype=tf.float32)
sess = tf.Session()
blurred = sess.run(tf.nn.conv2d(tf.reshape(imgs, [64, 28, 28, 1]), blur_kernel, strides=[1,1,1,1], padding='SAME'))
cv2.imshow('normal.png', reshape_to_grid(np.array(batch), side=ex_side, rgb=False))
cv2.waitKey(10000)
cv2.imshow('blurred.png', reshape_to_grid(np.array(blurred), side=ex_side, rgb=False))
cv2.waitKey(10000)