Skip to content

Commit

Permalink
Update Cellular_Automata_Kernel.py
Browse files Browse the repository at this point in the history
  • Loading branch information
RubensZimbres authored Feb 21, 2021
1 parent 4d20752 commit 6c49e80
Showing 1 changed file with 4 additions and 33 deletions.
37 changes: 4 additions & 33 deletions Neural_Cellular_Automata_Google/Cellular_Automata_Kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,19 @@
[770.]] ]]

####################################################################

import numpy as np
import tensorflow as tf

# sets, rows, columns
## 2D CNN expects a 4D (batch, height, width, channels)

inp=np.repeat(np.zeros(7),21).reshape(1,7,7,3).astype(np.float32)

inp[0][3][3]=1
inp[0][3][4]=1
inp[0][3][2]=1
inp[0][4][3]=1
inp[0][4][4]=1
inp[0][4][2]=1
inp[0][2][3]=1
inp[0][2][4]=1
inp[0][2][2]=1

inp=inp.reshape(1,7,7,3).astype(np.float32)
inp=np.random.randint(0,2,7*7*3).reshape(1,7,7,3).astype(np.float32)

[0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0.],
[0., 0., 1., 1., 1., 0., 0.],
[0., 0., 1., 1., 1., 0., 0.],
[0., 0., 1., 1., 1., 0., 0.],
[0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0.]

kernel = np.array([[ [1,1,1],[1,2,1],[1,1,1] ]]).astype(np.float32).reshape(1,3,3,1)
kernel = np.array([[1,1,1],[1,2,1],[1,1,1]]).astype(np.float32).reshape(1,3,3,1)

print('input shape ->',inp.shape)
print('kernel shape ->',kernel.shape)

result = tf.nn.conv2d(inp, kernel, strides=(1,1), padding='SAME')

result = tf.nn.conv2d(inp, kernel, strides=(1,1,1,1), padding='SAME')
result.shape
tf.reshape(result,[7,7])

[ 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0.],
[ 0., 3., 7., 10., 7., 3., 0.],
[ 0., 3., 7., 10., 7., 3., 0.],
[ 0., 3., 7., 10., 7., 3., 0.],
[ 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0.]

0 comments on commit 6c49e80

Please sign in to comment.