def g_error(pic, w1, w2, ans, N): data = np.zeros((6, 36)) a = np.zeros((6, 2)) for i in range(0, 6): if random.randint(0, 1) == 1: p = p_gn(N) p1 = tf.reshape(p.astype('float64').reshape(1, 3000) / 255, shape=[-1, 50, 60, 1]) II = conv2d(p1, w1) II = maxpool2d(II, k=5) II1 = conv2d(II, w2) II1 = maxpool2d(II1, k=5) II1 = tf.reshape(II1, [-1, 36]).eval() data[i, :] = II1 a[i, :] = [1, 0] if random.randint(0, 1) == 0: k = random.randint(0, 5) while k == ans: k = random.randint(0, 5) p = pic[:, :, k] p1 = tf.reshape(p.astype('float64').reshape(1, 3000) / 255, shape=[-1, 50, 60, 1]) II = conv2d(p1, w1) II = maxpool2d(II, k=5) II1 = conv2d(II, w2) II1 = maxpool2d(II1, k=5) II1 = tf.reshape(II1, [-1, 36]).eval() data[i, :] = II1 a[i, :] = [0, 1] return data, a
def forward(p, pic, w1, w2, w, b): with tf.Session() as sess: p1 = tf.reshape(p.astype('float64').reshape(1, 3000) / 255, shape=[-1, 50, 60, 1]) I = conv2d(p1, w1) I = maxpool2d(I, k=5) I1 = conv2d(I, w2) I1 = maxpool2d(I1, k=5) I1 = tf.reshape(I1, [-1, 36]).eval() II2 = np.zeros((6, 36)) with tf.Session() as sess: for i in range(0, 6): p1 = tf.reshape(pic[:, :, i].astype('float64').reshape(1, 3000) / 255, shape=[-1, 50, 60, 1]) II = conv2d(p1, w1) II = maxpool2d(II, k=5) II1 = conv2d(II, w2) II1 = maxpool2d(II1, k=5) II1 = tf.reshape(II1, [-1, 36]).eval() II2[i, :] = II1 II3 = np.zeros((6, 1024)) II1 = I1.dot(w) + b with tf.Session() as sess: for i in range(0, 6): II3[i, :] = II2[i, :].dot(w) + b return II1, II3
def forward(pic,w1,w2): II=np.zeros((16,6*7*7)) with tf.Session() as sess: for i in range (0,16): p1=tf.reshape(pic[:,:,i].astype('float64').reshape(1,28*28)/255 , shape=[-1, 28,28 , 1]) I=conv2d(p1, w1) I=maxpool2d(I,k=2) I1 = conv2d(I, w2) I1=maxpool2d(I1,k=2) I1=tf.reshape(I1,[-1,6*7*7]).eval() II[i,:]=I1 return II
def forward(pic, w1, w2): II = np.zeros((9, 180)) with tf.Session() as sess: for i in range(0, 9): p1 = tf.reshape( pic[:, :, i].astype('float64').reshape(1, 40 * 50) / 255, shape=[-1, 40, 50, 1]) I = conv2d(p1, w1) I = maxpool2d(I, k=3) I1 = conv2d(I, w2) I1 = maxpool2d(I1, k=3) I1 = tf.reshape(I1, [-1, 180]).eval() II[i, :] = I1 return II
def prep(pic, weight1, weight2): n = weight1.shape[4] M = np.zeros((n, pic.shape[2], 7020)) with tf.Session() as sess: p = np.zeros((pic.shape[2], 3000)) for i in range(0, pic.shape[2]): p[i, :] = pic[:, :, i].reshape(3000, ) p = tf.reshape(p, shape=[-1, 50, 60, 1]) for k in range(0, n): I = conv2d(p, weight1[:, :, :, :, k].reshape(25, 25, 1, 3)) I = maxpool2d(I, k=2) I1 = conv2d(I, weight2[:, :, :, :, k].reshape(50, 50, 3, 6)) # Max Pooling (down-sampling) I1 = maxpool2d(I1, k=2) I1 = tf.reshape(I1, [-1, 7020]).eval() M[k, :, :] = I1 return M
def prep(pic, weight1, weight2, a): n = weight1.shape[4] M = np.zeros((n, pic.shape[2], 49 * 2 * a)) with tf.Session() as sess: p = np.zeros((pic.shape[2], 784)) for i in range(0, pic.shape[2]): p[i, :] = pic[:, :, i].reshape(784, ) p = tf.reshape(p, shape=[-1, 28, 28, 1]) for k in range(0, n): I = conv2d(p, weight1[:, :, :, :, k].reshape(5, 5, 1, a)) I = maxpool2d(I, 2) I1 = conv2d(I, weight2[:, :, :, :, k].reshape(5, 5, a, 2 * a)) # Max Pooling (down-sampling) I1 = maxpool2d(I1, 2) I1 = tf.reshape(I1, [-1, 49 * 2 * a]).eval() M[k, :, :] = I1 return M
def forward(p, pic, w1, w2): with tf.Session() as sess: p1 = tf.reshape(p.astype('float64').reshape(1, 3000) / 255, shape=[-1, 50, 60, 1]) I = conv2d(p1, w1) I = maxpool2d(I, k=5) #I1 = conv2d(I, w2) #I1=maxpool2d(I1,k=5) I1 = tf.reshape(I, [-1, 360]).eval() II2 = np.zeros((6, 360)) with tf.Session() as sess: for i in range(0, 6): p1 = tf.reshape(pic[:, :, i].astype('float64').reshape(1, 3000) / 255, shape=[-1, 50, 60, 1]) II = conv2d(p1, w1) II = maxpool2d(II, k=5) #II1 = conv2d(II, w2) #II1=maxpool2d(II1,k=5) II1 = tf.reshape(II, [-1, 360]).eval() II2[i, :] = II1 return I1, II2