Both, this notebook and this wikipedia page might help you understand what is a convolution.
no, if we consider two functions $f$ and $g$ taking values from $\mathbb{Z} \to \mathbb{R}$ then:
$ (f * g)[n] = \sum_{m = -\infty}^{+\infty} f[m] \cdot g[n - m] $
In our case, we consider the two vectors $x$ and $w$ :
$ x = (x_1, x_2, ..., x_{n-1}, x_n) $
$ w = (w_1, w_2) $
And get :
$ x * w = (w_1 x_1 + w_2 x_2, w_1 x_2 + w_2 x_3, ..., w_1 x_{n-1} + w_2 x_n)$
In most of deep learning framewoks, you'll get to chose in between three paddings:
"TensorFlow is an open-source software library for dataflow programming across a range of tasks. It is a symbolic math library, and also used for machine learning applications such as neural networks.[3] It is used for both research and production at Google often replacing its closed-source predecessor, DistBelief." - Wikipedia
We'll be using tensorflow to build the models we want to use.
Here below, we build a AND gate with a very simple neural network :
In [1]:
import tensorflow as tf
import numpy as np
tf.reset_default_graph()
# Define our Dataset
X = np.array([[0,0],[0,1],[1,0],[1,1]])
Y = np.array([0,0,0,1]).reshape(-1,1)
# Define the tensorflow tensors
x = tf.placeholder(tf.float32, [None, 2], name='X') # inputs
y = tf.placeholder(tf.float32, [None, 1], name='Y') # outputs
W = tf.Variable(tf.zeros([2, 1]), name='W')
b = tf.Variable(tf.zeros([1,]), name='b')
# Define the model
pred = tf.nn.sigmoid(tf.matmul(x, W) + b) # Model
# Define the loss
with tf.name_scope("loss"):
loss = tf.reduce_mean(-tf.reduce_sum(y * tf.log(pred) + (1-y) * tf.log(1-pred), reduction_indices=1))
# Define the optimizer method you want to use
with tf.name_scope("optimizer"):
optimizer = tf.train.GradientDescentOptimizer(0.1).minimize(loss)
# Include some Tensorboard visualization
writer_train = tf.summary.FileWriter("./my_model/")
# Start training session
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
writer_train.add_graph(sess.graph)
for epoch in range(1000):
_, c, p = sess.run([optimizer, loss, pred], feed_dict={x: X,
y: Y})
print p, y
To visualize the graph you just created, launch tensorbord.
$tensorboard --logdirs=./ on linux (with corresponding logdir)
Design a neural network with 2 layers.
And train it
It's mandatory that you get a tensorboard visualization of your graph, try to make it look good, plz :)
Here below I put a graph of the model you want to have (yet your weights won't be the same)
In [ ]:
### Code here
In [ ]:
### Code here
You can now move to CNNs. You'll have to train a convolutional neural network to predict the digits from MNIST.
You might want to reuse some pieces of code from SNN
Your model should have 3 layers:
Train your model.
Explain all you do, and why, make it lovely to read, plz o:)
In [ ]:
### code here
In [ ]:
### code here
In [ ]:
### Code here