Skip to content

Instantly share code, notes, and snippets.

@itdxer
Created November 22, 2018 15:14
Show Gist options
  • Select an option

  • Save itdxer/8a8ebe368ac41f4edbf4393de58fd921 to your computer and use it in GitHub Desktop.

Select an option

Save itdxer/8a8ebe368ac41f4edbf4393de58fd921 to your computer and use it in GitHub Desktop.
import numpy as np
import tensorflow as tf
np.random.seed(0)
w1 = np.random.random((3, 3, 1, 100))
w2 = np.random.random((3, 3, 1, 100))
x1 = np.random.random((1, 256, 256, 1))
x2 = np.random.random((1, 256, 256, 1))
x = tf.concat([x1, x2], axis=-1)
y = tf.nn.convolution(x, tf.concat([w1, w2], axis=2), 'VALID')
y1 = tf.nn.convolution(x1, w1, 'VALID')
y2 = tf.nn.convolution(x2, w2, 'VALID')
sess = tf.Session()
r, r1, r2 = sess.run([y, y1, y2])
np.all(np.isclose(r, r1 + r2)) # True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment