3636# We'll use our values from [-3, 3] to create a Gaussian Distribution
3737sigma = 1.0
3838mean = 0.0
39- z = (tf .exp (tf .neg (tf .pow (x - mean , 2.0 ) /
39+ z = (tf .exp (tf .negative (tf .pow (x - mean , 2.0 ) /
4040 (2.0 * tf .pow (sigma , 2.0 )))) *
4141 (1.0 / (sigma * tf .sqrt (2.0 * 3.1415 ))))
4242
6060print (tf .shape (z ).eval ())
6161
6262# %% We can combine tensors like so:
63- print (tf .pack ([tf .shape (z ), tf .shape (z ), [3 ], [4 ]]).eval ())
63+ print (tf .stack ([tf .shape (z ), tf .shape (z ), [3 ], [4 ]]).eval ())
6464
6565# %% Let's multiply the two to get a 2d gaussian
6666z_2d = tf .matmul (tf .reshape (z , [n_values , 1 ]), tf .reshape (z , [1 , n_values ]))
7171# %% For fun let's create a gabor patch:
7272x = tf .reshape (tf .sin (tf .linspace (- 3.0 , 3.0 , n_values )), [n_values , 1 ])
7373y = tf .reshape (tf .ones_like (x ), [1 , n_values ])
74- z = tf .mul (tf .matmul (x , y ), z_2d )
74+ z = tf .multiply (tf .matmul (x , y ), z_2d )
7575plt .imshow (z .eval ())
7676
7777# %% We can also list all the operations of a graph:
8181# %% Lets try creating a generic function for computing the same thing:
8282def gabor (n_values = 32 , sigma = 1.0 , mean = 0.0 ):
8383 x = tf .linspace (- 3.0 , 3.0 , n_values )
84- z = (tf .exp (tf .neg (tf .pow (x - mean , 2.0 ) /
84+ z = (tf .exp (tf .negative (tf .pow (x - mean , 2.0 ) /
8585 (2.0 * tf .pow (sigma , 2.0 )))) *
8686 (1.0 / (sigma * tf .sqrt (2.0 * 3.1415 ))))
8787 gauss_kernel = tf .matmul (
8888 tf .reshape (z , [n_values , 1 ]), tf .reshape (z , [1 , n_values ]))
8989 x = tf .reshape (tf .sin (tf .linspace (- 3.0 , 3.0 , n_values )), [n_values , 1 ])
9090 y = tf .reshape (tf .ones_like (x ), [1 , n_values ])
91- gabor_kernel = tf .mul (tf .matmul (x , y ), gauss_kernel )
91+ gabor_kernel = tf .multiply (tf .matmul (x , y ), gauss_kernel )
9292 return gabor_kernel
9393
9494# %% Confirm this does something:
@@ -112,7 +112,7 @@ def convolve(img, W):
112112 img = tf .reshape (img , dims )
113113 # if the image is 3 channels, then our convolution
114114 # kernel needs to be repeated for each input channel
115- W = tf .concat (2 , [W , W , W ])
115+ W = tf .concat (axis = 2 , values = [W , W , W ])
116116
117117 # Stride is how many values to skip for the dimensions of
118118 # num, height, width, channels
0 commit comments