<jupyter_start><jupyter_text>------------------------------------------------------------------<jupyter_code>import tensorflow as tf
x = np.linspace(-3.0, 3.0, 100)
print (x)
print (x.shape)
print (x.dtype)
x = tf.linspace(-3.0, 3.0, 100)
print (x)
g = tf.get_default_graph()
[op.name for op in g.get_operations()]
g.get_tensor_by_name('LinSpace'+':0')
sess = tf.Session()
computed_x = sess.run(x)
print (computed_x)

computed_x_eval = x.eval(session=sess)
print (computed_x_eval)

sess.close()
sess = tf.Session(graph=g)
sess.close()
g2 = tf.Graph()
sess = tf.InteractiveSession()
a = x.eval()
print (x.get_shape())

print (x.get_shape().as_list())
mean = 0.0
sigma = 1.0

z = (tf.exp(tf.negative(tf.pow(x - mean, 2.0) /
                   (2.0 * tf.pow(sigma, 2.0)))) *
     (1.0 / (sigma * tf.sqrt(2.0 * 3.1415))))
res = z.eval()
plt.plot(res)
ksize = z.get_shape().as_list()[0]

z_2d = tf.matmul(tf.reshape(z,[ksize, 1]), tf.transpose(tf.reshape(z,[ksize, 1])))

plt.imshow(z_2d.eval())
img = plt.imread("<NAME>.jpg")
from scipy.misc import imresize
img = imresize(img, [300,400], interp='bilinear')
plt.imshow(img)
print (img.shape)
def rgb2gray(rgb):
    return np.dot(rgb[...,:3], [0.299, 0.587, 0.114])
img_gray = rgb2gray(img)
img_4d = img_gray.astype(np.float32).reshape([1, img_gray.shape[0], img_gray.shape[1], 1])
print (img_4d.shape)
img_4d.dtype
img_4d_tensor = tf.reshape(img_gray.astype(np.float32), [1, img_gray.shape[0], img_gray.shape[1], 1])
print (img_4d_tensor.get_shape().as_list())
img_4d_tensor
z_4d = tf.reshape(z_2d, [ksize, ksize, 1, 1])
print (z_4d.get_shape().as_list())
convolved = tf.nn.conv2d(img_4d_tensor, z_4d, strides=[1,1,1,1], padding='SAME')
res = convolved.eval()
print (res.shape)
plt.imshow(res[0,:,:,0], cmap='gray')
xs = tf.linspace(-3.0, 3.0, ksize)
ys = tf.sin(xs)
plt.figure()
plt.plot(ys.eval())
ys = tf.reshape(ys, [ksize, 1])
ones = tf.ones((1, ksize))
wave = tf.matmul(ys, ones)
plt.imshow(wave.eval(), cmap='gray')
gabor = tf.multiply(wave, z_2d)
plt.imshow(gabor.eval(), cmap='gray')
wave, z_2d
a = 100
blur_filter = np.array([[0.0625, 0.125, 0.0625],
                        [0.1250, 0.250, 0.1250],
                        [0.0625, 0.125, 0.0625]])
print (blur_filter.shape)
blur_filter = np.stack((blur_filter, blur_filter, blur_filter), axis=2)
print (blur_filter.shape)

blur_filter = tf.reshape(a * blur_filter.astype(np.float32), [3,3,3,1])

img = tf.placeholder(tf.float32, shape=[None, None], name='img')
img_3d = tf.expand_dims(img, 2)
print (img_3d.get_shape().as_list())

img_4d = tf.expand_dims(img_3d, 0)
print(img_4d.get_shape().as_list())

mean = tf.placeholder(tf.float32, name='mean')
sigma = tf.placeholder(tf.float32, name='sigma')
ksize = tf.placeholder(tf.int32, name='ksize')

x = tf.linspace(-3.0, 3.0, ksize)
z = (tf.exp(tf.negative(tf.pow(x - mean, 2.0) /
                   (2.0 * tf.pow(sigma, 2.0)))) *
      (1.0 / (sigma * tf.sqrt(2.0 * 3.1415))))
z_2d = tf.matmul(
  tf.reshape(z, tf.stack([ksize, 1])),
  tf.reshape(z, tf.stack([1, ksize])))
ys = tf.sin(x)
ys = tf.reshape(ys, tf.stack([ksize, 1]))
ones = tf.ones(tf.stack([1, ksize]))
wave = tf.matmul(ys, ones)
gabor = tf.multiply(wave, z_2d)
gabor_4d = tf.reshape(gabor, tf.stack([ksize, ksize, 1, 1]))

convolved = tf.nn.conv2d(img_4d, gabor_4d, strides=[1, 1, 1, 1], padding='SAME', name='convolved')
convolved_img = convolved[0, :, :, 0]
resimage = convolved_img.eval(feed_dict={
    img: rgb2gray(plt.imread('img_align_celeba/000029.jpg')),
    mean: 0.0,
    sigma: 0.5,
    ksize: 5})
plt.figure()
plt.imshow(rgb2gray(plt.imread('img_align_celeba/000029.jpg')), cmap='gray')
plt.title('Original')

plt.figure()
plt.imshow(resimage, cmap='gray')
plt.title('Convolved')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2219551282051282, 'fraction_numerical': 0.05982905982905983, 'mean_word_length': 4.095238095238095, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '638700', 'license': 'Apache-2.0', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1646, 'n_words': 285, 'path': 'cadl-tutorial/Session_1/session_1.ipynb', 'repo_name': 'GChaudhary/Completed-ML-DL-Online-Tutorials', 'size': '3751'}