def _gradients(self, v): v_mean, h_mean, h_mean0 = self._gibbs(v) # SIDE EFFECT: save means for future use (in _batch_err and # sparsity regularization) self.v_mean = v_mean self.h_mean = h_mean dW = np.zeros(self.W.shape) for k in xrange(self.n_hiddens): # print('_gradient: ' + str(v.shape)) dW[k] = conv2(v, self._ff(h_mean[k]), 'valid') - \ conv2(v_mean, self._ff(h_mean[k]), 'valid') db = (v - v_mean).sum() dc = (h_mean0 - h_mean).sum(axis=2).sum(axis=1) # TODO: check it! return dW, db, dc
def _mean_hiddens(self, v): h = np.zeros((self.n_hiddens,) + self.h_shape) for k in xrange(self.n_hiddens): # print('_mean_hiddens (loop): %s' % (v.shape,)) h[k] = np.exp(conv2(v, self._ff(self.W[k]), mode='valid') + self.c[k]) h_mean = h / (1 + self.pool(h)) return h_mean
com2 = np.multiply(lap2[i],(1.0-gau1[i])) term2.append(com2) blend.append(term1[k]+term2[k]) k += 1 #collapsing the blended pyramids to obtain the blended image res = [] res.append(blend[0]) gkern2d = get_gauss_kernel(5,2) for i in range(0,len(blend)-1): tmp1 = image_upsamp(res[i],0) tmp1= conv2(tmp1, gkern2d) tmp2 = blend[i+1] total = np.add(tmp1 , tmp2) res.append(total) output = total #linearly spreading the intensity values to get the final image res_img = spread_linear(output,255) #diaplaying the final blended image cv2.imshow("blended image",res_img) cv2.waitKey(0)
def transform(self, v): I = np.zeros(self.h_mean.shape) for k in xrange(self.n_hiddens): I[k] = np.exp(conv2(v, self._ff(self.W[k]), 'valid') + self.c[k]) pool_mean = 1 - (1. / (1 + self.pool(np.exp(I)))) return pool_mean
def _mean_visible(self, h): v = np.zeros(self.v_shape) for k in xrange(self.n_hiddens): v += conv2(h[k], self.W[k], 'full') return logistic_sigmoid(v + self.b)
def __init__(self, inp, dropout=False, drop_prob=0.25, histogram=True, num_class=11, verb=True, def_cp_name='mnist_seg', def_cp_path='checkpoints/mnist_seg_st', def_log_name='mnist_seg_st', def_log_path='./log/', version=1): """ inp: Input placeholder. shape: Tensorflow tensor shape used in the input placeholder. It must be a list object. dropout: Flag used to indicate if dropout will be used drop_prob: Percentage of neurons to be turned off histogram: Indicates if information for tensorboard should be annexed. """ self.def_cp_name = def_cp_name self.def_cp_path = def_cp_path + 'v' + str(version) if self.def_cp_path[-1] != '/': self.def_cp_path += '/' self.def_log_name = def_log_name + 'v' + str(version) self.def_log_path = def_log_path if self.def_log_path[-1] != '/': self.def_log_path += '/' self.reg = [] # Contains l2 regularizaton for weights self.dropout = dropout self.drop_prob = drop_prob self.x = inp # shape vs get_shape https://stackoverflow.com/a/43290897/5969548 self.im_h = int(self.x.get_shape()[1]) self.im_w = int(self.x.get_shape()[2]) self.im_c = int(self.x.get_shape()[3]) self.num_class = num_class ##### Network Specs ks1 = 3 num_k1 = 8 ks2 = 3 num_k2 = 8 ks3 = 3 num_k3 = 16 ks4 = 3 num_k4 = 16 ks5 = 3 num_k5 = 32 ks6 = 3 num_k6 = 32 #### Core Model c1_shape = [ks1, ks1, self.im_c, num_k1] self.conv1, reg = ut.conv2(inp=self.x, shape=c1_shape, name='conv1', dropout=self.dropout, drop_prob=self.drop_prob, histogram=histogram, l2=True) self.reg.append(reg) c2_shape = [ks2, ks2, num_k1, num_k2] self.conv2, reg = ut.conv2(inp=self.conv1, shape=c2_shape, name='conv2', dropout=self.dropout, drop_prob=self.drop_prob, histogram=histogram, l2=True) self.reg.append(reg) c3_shape = [ks3, ks3, num_k2, num_k3] self.conv3, reg = ut.conv2(inp=self.conv2, shape=c3_shape, name='conv3', strides=[1, 2, 2, 1], dropout=self.dropout, drop_prob=self.drop_prob, histogram=histogram, l2=True) self.reg.append(reg) c4_shape = [ks4, ks4, num_k3, num_k4] self.conv4, reg = ut.conv2(inp=self.conv3, shape=c4_shape, name='conv4', dropout=self.dropout, drop_prob=self.drop_prob, histogram=histogram, l2=True) self.reg.append(reg) c5_shape = [ks5, ks5, num_k4, num_k5] self.conv5, reg = ut.conv2(inp=self.conv4, shape=c5_shape, name='conv5', strides=[1, 2, 2, 1], dropout=self.dropout, drop_prob=self.drop_prob, histogram=histogram, l2=True) self.reg.append(reg) c6_shape = [ks6, ks6, num_k5, num_k6] self.conv6, reg = ut.conv2(inp=self.conv5, shape=c6_shape, name='conv6', dropout=self.dropout, drop_prob=self.drop_prob, histogram=histogram, l2=True) self.reg.append(reg) d1_shape = [ks6, ks6, num_k6, num_k6] self.deconv1, reg = ut.deconv2(inp=self.conv6, shape=d1_shape, relu=True, dropout=self.dropout, drop_prob=self.drop_prob, histogram=histogram, name='deconv1', l2=True) self.reg.append(reg) #d2_shape = [ks5,ks5,num_k4,num_k5] d2_shape = [ks5, ks5, num_k5, num_k6] self.deconv2, reg = ut.deconv2(inp=self.deconv1, shape=d2_shape, relu=True, name='deconv2', dropout=self.dropout, drop_prob=self.drop_prob, histogram=histogram, l2=True) self.reg.append(reg) #self.sum1 = self.deconv2 + self.conv4 #d3_shape = [ks4,ks4,num_k3,num_k4] d3_shape = [ks4, ks4, num_k4, num_k5] self.deconv3, reg = ut.deconv2(inp=self.deconv2, shape=d3_shape, relu=True, strides=[1, 2, 2, 1], name='deconv3', dropout=self.dropout, drop_prob=self.drop_prob, histogram=histogram, l2=True) self.reg.append(reg) self.sum1 = self.deconv3 + self.conv4 #d4_shape = [ks3,ks3,num_k2,num_k3] d4_shape = [ks3, ks3, num_k3, num_k4] self.deconv4, reg = ut.deconv2(inp=self.sum1, shape=d4_shape, relu=True, name='deconv4', dropout=self.dropout, drop_prob=self.drop_prob, histogram=histogram, l2=True) self.reg.append(reg) #self.sum2 = self.deconv4 + self.conv3 #d5_shape = [ks2,ks2,num_k2,num_k2] d5_shape = [ks2, ks2, num_k1, num_k3] self.deconv5, reg = ut.deconv2(inp=self.deconv4, shape=d5_shape, strides=[1, 2, 2, 1], relu=True, name='deconv5', dropout=self.dropout, drop_prob=self.drop_prob, histogram=histogram, l2=True) self.reg.append(reg) self.sum2 = self.deconv5 + self.conv2 #d6_shape = [ks1,ks1,self.num_class,num_k2] d6_shape = [ks1, ks1, self.num_class, num_k1] self.deconv6, reg = ut.deconv2(inp=self.sum2, shape=d6_shape, relu=False, name='deconv6', histogram=histogram, l2=True) self.reg.append(reg) self.pre_logits = self.deconv6 if verb: msg = '\n\t{0} \n\t{1} \n\t{2} \n\t{3} \n\t{4} \n\t{5}' msg = msg.format(self.conv1, self.conv2, self.conv3, self.conv4, self.conv5, self.conv6) msg += '\n\t{0} \n\t{1} \n\t{2} \n\t{3} \n\t{4} \n\t{5}' msg = msg.format(self.deconv1, self.deconv2, self.deconv3, self.deconv4, self.deconv5, self.deconv6) print(msg)