• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python tensorflow.reduce_max函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tensorflow.reduce_max函数的典型用法代码示例。如果您正苦于以下问题:Python reduce_max函数的具体用法?Python reduce_max怎么用?Python reduce_max使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了reduce_max函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: convolution

 def convolution(self, inputs, num_units):
     x = tf.expand_dims(inputs, 3)
     chan_in = 1
     
     #Bigram
     w_bigram = tf.get_variable("w_bigram", shape= [2,50,chan_in,num_units],
                              initializer= tf.contrib.layers.xavier_initializer_conv2d())
     b_bigram = tf.get_variable("b_bigram", shape= [num_units])
     y_bigram = self.nonlin(tf.nn.conv2d(x, w_bigram, strides= [1,1,1,1], padding='VALID') + b_bigram)
     h_bigram = tf.reduce_max(tf.squeeze(y_bigram) , 1)
     
     #Trigram
     w_trigram = tf.get_variable("w_trigram", shape= [3,50,chan_in,num_units],
                              initializer= tf.contrib.layers.xavier_initializer_conv2d())
     b_trigram = tf.get_variable("b_trigram", shape= [num_units])
     y_trigram = self.nonlin(tf.nn.conv2d(x, w_trigram, strides= [1,1,1,1], padding='VALID') + b_trigram)
     h_trigram = tf.reduce_max(tf.squeeze(y_trigram) , 1)
     
     #Quin-gram
     w_quingram = tf.get_variable("w_quingram", shape= [3,50,chan_in,num_units],
                              initializer= tf.contrib.layers.xavier_initializer_conv2d())
     b_quingram = tf.get_variable("b_quingram", shape= [num_units])
     y_quingram = self.nonlin(tf.nn.conv2d(x, w_trigram, strides= [1,1,1,1], padding='VALID') + b_trigram)
     h_quingram = tf.reduce_max(tf.squeeze(y_quingram) , 1)
     
     if self.hyperparams['conv_type'] == 'bigram':
         h = h_bigram
     elif self.hyperparams['conv_type'] == 'trigram':
         h = h_trigram
     elif self.hyperparams['conv_type'] == 'quingram':
         h = h_quingram            
     elif self.hyperparams['conv_type'] == 'inception':
         h = tf.concat(1, [h_bigram, h_trigram, h_quingram])
         
     return h
开发者ID:akuefler,项目名称:GenerativeModels,代码行数:35,代码来源:networks.py


示例2: _tf_loss

    def _tf_loss(self, sim, sim_emb):
        """Define loss"""

        if self.use_max_sim_neg:
            max_sim_neg = tf.reduce_max(sim[:, 1:], -1)
            loss = tf.reduce_mean(tf.maximum(0., self.mu_pos - sim[:, 0]) +
                                  tf.maximum(0., self.mu_neg + max_sim_neg))
        else:
            # create an array for mu
            mu = self.mu_neg * np.ones(self.num_neg + 1)
            mu[0] = self.mu_pos

            factors = tf.concat([-1 * tf.ones([1, 1]),
                                 tf.ones([1, tf.shape(sim)[1] - 1])], 1)
            max_margin = tf.maximum(0., mu + factors * sim)
            loss = tf.reduce_mean(tf.reduce_sum(max_margin, -1))

        max_sim_emb = tf.maximum(0., tf.reduce_max(sim_emb, -1))

        loss = (loss +
                # penalize max similarity between intent embeddings
                tf.reduce_mean(max_sim_emb) * self.C_emb +
                # add regularization losses
                tf.losses.get_regularization_loss())
        return loss
开发者ID:wuxingdexian,项目名称:rasa_nlu,代码行数:25,代码来源:embedding_intent_classifier.py


示例3: gen_debug_td_error_summaries

def gen_debug_td_error_summaries(
    target_q_values, q_values, td_targets, td_errors):
  """Generates debug summaries for critic given a set of batch samples.

  Args:
    target_q_values: set of predicted next stage values.
    q_values: current predicted value for the critic network.
    td_targets: discounted target_q_values with added next stage reward.
    td_errors: the different between td_targets and q_values.
  """
  with tf.name_scope('td_errors'):
    tf.summary.histogram('td_targets', td_targets)
    tf.summary.histogram('q_values', q_values)
    tf.summary.histogram('target_q_values', target_q_values)
    tf.summary.histogram('td_errors', td_errors)
    with tf.name_scope('td_targets'):
      tf.summary.scalar('mean', tf.reduce_mean(td_targets))
      tf.summary.scalar('max', tf.reduce_max(td_targets))
      tf.summary.scalar('min', tf.reduce_min(td_targets))
    with tf.name_scope('q_values'):
      tf.summary.scalar('mean', tf.reduce_mean(q_values))
      tf.summary.scalar('max', tf.reduce_max(q_values))
      tf.summary.scalar('min', tf.reduce_min(q_values))
    with tf.name_scope('target_q_values'):
      tf.summary.scalar('mean', tf.reduce_mean(target_q_values))
      tf.summary.scalar('max', tf.reduce_max(target_q_values))
      tf.summary.scalar('min', tf.reduce_min(target_q_values))
    with tf.name_scope('td_errors'):
      tf.summary.scalar('mean', tf.reduce_mean(td_errors))
      tf.summary.scalar('max', tf.reduce_max(td_errors))
      tf.summary.scalar('min', tf.reduce_min(td_errors))
      tf.summary.scalar('mean_abs', tf.reduce_mean(tf.abs(td_errors)))
开发者ID:Exscotticus,项目名称:models,代码行数:32,代码来源:ddpg_agent.py


示例4: _update_lipschitz

  def _update_lipschitz(self,v,i):
    config = self.config
    if len(v.shape) > 1:
      k = self.config.weight_constraint_k or 100.0000
      wi_hat = v
      if len(v.shape) == 4:
        #fij = tf.reduce_sum(tf.abs(wi_hat),  axis=[0,1])
        fij = wi_hat
        fij = tf.reduce_sum(tf.abs(fij),  axis=[1])
        fij = tf.reduce_max(fij,  axis=[0])
      else:
        fij = wi_hat

      if self.config.ortho_pnorm == "inf":
        wp = tf.reduce_max(tf.reduce_sum(tf.abs(fij), axis=0), axis=0)
      else:
        # conv
        wp = tf.reduce_max(tf.reduce_sum(tf.abs(fij), axis=1), axis=0)
      ratio = (1.0/tf.maximum(1.0, wp/k))
      
      if self.config.weight_bounce:
        bounce = tf.minimum(1.0, tf.ceil(wp/k-0.999))
        ratio -= tf.maximum(0.0, bounce) * 0.2

      if self.config.weight_scaleup:
        up = tf.minimum(1.0, tf.ceil(0.02-wp/k))
        ratio += tf.maximum(0.0, up) * k/wp * 0.2

      wi = ratio*(wi_hat)
      #self.gan.metrics['wi'+str(i)]=wp
      #self.gan.metrics['wk'+str(i)]=ratio
      #self.gan.metrics['bouce'+str(i)]=bounce
      return tf.assign(v, wi)
    return None
开发者ID:255BITS,项目名称:hyperchamber-gan,代码行数:34,代码来源:weight_constraint_train_hook.py


示例5: interface

 def interface(self):
     self.W, self.b, self.logits = [], [], [self.x]
     with tf.name_scope('main_layer') as scope:
         if self.activate == 'Maxout':
             w_shape = [self.filter[0], self.filter[1], self.filter[2], self.filter[3] * self.n]
             b_shape = [self.hidden_nodes * self.n]
             self.W.append(weight_variable(w_shape))
             self.b.append(bias_variable(b_shape))
             t0 = tf.nn.conv2d(self.logits[0], self.W[0], strides = self.strides, padding = self.padding) + self.b[0]
             s = t0.get_shape()
             t1 = tf.reshape(t0, [-1, int(s.dims[1]), int(s.dims[2]), self.hidden_nodes, self.n])
             t2 = tf.reduce_max(t1, 4)
             self.logits.append(t2)
             w_shape = [self.filter[0], self.filter[1], self.hidden_nodes, self.filter[2] * self.n]
             b_shape = [self.filter[2] * self.n]
             self.W.append(weight_variable(w_shape))
             self.b.append(bias_variable(b_shape))
             t0 = tf.nn.conv2d(self.logits[1], self.W[1], strides = self.strides, padding = self.padding) + self.b[1]
             s = t0.get_shape()
             t1 = tf.reshape(t0, [-1, int(s.dims[1]), int(s.dims[2]), self.filter[2], self.n])
             t2 = tf.reduce_max(t1, 4)
             self.logits.append(t2)
             self.y = self.logits[len(self.logits) - 1]
         else:
             w_shape = self.filter
             b_shape = [self.hidden_nodes]
             self.W.append(weight_variable(w_shape))
             self.b.append(bias_variable(b_shape))
             self.logits.append(tf.nn.relu(tf.nn.conv2d(self.logits[0], self.W[0], strides = self.strides, padding = self.padding) + self.b[0]))
             w_shape = [self.filter[0], self.filter[1], self.hidden_nodes, self.filter[2]]
             b_shape = [self.filter[2]]
             self.W.append(weight_variable(w_shape))
             self.b.append(bias_variable(b_shape))
             self.logits.append(tf.nn.relu(tf.nn.conv2d(self.logits[1], self.W[1], strides = self.strides, padding = self.padding) + self.b[1]))
             self.y = self.logits[len(self.logits) - 1]
开发者ID:ustbliubo2014,项目名称:Tensorflow_USTB,代码行数:35,代码来源:cae.py


示例6: _create_aggregate_input

    def _create_aggregate_input(self, v1, v2):
        """Create and return the input to the aggregate step.

        Parameters
        ----------
        v1: tf.Tensor
           Tensor with shape (batch, time_steps, num_units).

        v2: tf.Tensor
            Tensor with shape (batch, time_steps, num_units)

        Returns
        -------
        input_tensor: tf.Tensor
            A tensor with shape (batch, num_aggregate_inputs)

        """
        # sum over time steps; resulting shape is (batch, num_units)
        v1 = utils.text.mask3d(v1, self._m_sentence1_size, 0, 1)
        v2 = utils.text.mask3d(v2, self._m_sentence2_size, 0, 1)
        v1_sum = tf.reduce_sum(v1, 1)
        v2_sum = tf.reduce_sum(v2, 1)
        v1_max = tf.reduce_max(v1, 1)
        v2_max = tf.reduce_max(v2, 1)
        return tf.concat(axis=1, values=[v1_sum, v2_sum, v1_max, v2_max])
开发者ID:zero91,项目名称:jpyutils,代码行数:25,代码来源:decomposable.py


示例7: attentive_pooling_weights

def attentive_pooling_weights(U_AP, raw_question_rep, raw_answer_rep, tokens_question, tokens_answer,
                              apply_softmax=True):
    """Calculates the attentive pooling weights for question and answer

    :param U_AP: the soft-attention similarity matrix (to learn)
    :param raw_question_rep:
    :param raw_answer_rep:
    :param tokens_question: The raw token indices of the question. Used to detection not-set tokens
    :param tokens_answer: The raw token indices of the answer. Used to detection not-set tokens
    :param Q_PW: Positional weighting matrix for the question
    :param A_PW: Positional weighting matrix for the answer
    :param apply_softmax:
    :return: question weights, answer weights
    """
    tokens_question_float = tf.to_float(tokens_question)
    tokens_answer_float = tf.to_float(tokens_answer)
    tokens_question_non_zero = non_zero_tokens(tokens_question_float)
    tokens_answer_non_zero = non_zero_tokens(tokens_answer_float)

    G = soft_alignment(U_AP, raw_question_rep, raw_answer_rep, tokens_question_non_zero, tokens_answer_non_zero)

    maxpool_GQ = tf.reduce_max(G, [2], keep_dims=False)
    maxpool_GA = tf.reduce_max(G, [1], keep_dims=False)

    if apply_softmax:
        attention_Q = attention_softmax(maxpool_GQ, tokens_question_non_zero)
        attention_A = attention_softmax(maxpool_GA, tokens_answer_non_zero)
    else:
        attention_Q = maxpool_GQ
        attention_A = maxpool_GA

    return attention_Q, attention_A
开发者ID:zhongyunuestc,项目名称:iwcs2017-answer-selection,代码行数:32,代码来源:pooling_helper.py


示例8: to_binary_tf

def to_binary_tf(bar_or_track_bar, threshold=0.0, track_mode=False, melody=False):
    """Return the binarize tensor of the input tensor (be careful of the channel order!)"""
    if track_mode:
        # melody track
        if melody:
            melody_is_max = tf.equal(bar_or_track_bar, tf.reduce_max(bar_or_track_bar, axis=2, keep_dims=True))
            melody_pass_threshold = (bar_or_track_bar > threshold)
            out_tensor = tf.logical_and(melody_is_max, melody_pass_threshold)
        # non-melody track
        else:
            out_tensor = (bar_or_track_bar > threshold)
        return out_tensor
    else:
        if len(bar_or_track_bar.get_shape()) == 4:
            melody_track = tf.slice(bar_or_track_bar, [0, 0, 0, 0], [-1, -1, -1, 1])
            other_tracks = tf.slice(bar_or_track_bar, [0, 0, 0, 1], [-1, -1, -1, -1])
        elif len(bar_or_track_bar.get_shape()) == 5:
            melody_track = tf.slice(bar_or_track_bar, [0, 0, 0, 0, 0], [-1, -1, -1, -1, 1])
            other_tracks = tf.slice(bar_or_track_bar, [0, 0, 0, 0, 1], [-1, -1, -1, -1, -1])
        # melody track
        melody_is_max = tf.equal(melody_track, tf.reduce_max(melody_track, axis=2, keep_dims=True))
        melody_pass_threshold = (melody_track > threshold)
        out_tensor_melody = tf.logical_and(melody_is_max, melody_pass_threshold)
        # other tracks
        out_tensor_others = (other_tracks > threshold)
        if len(bar_or_track_bar.get_shape()) == 4:
            return tf.concat([out_tensor_melody, out_tensor_others], 3)
        elif len(bar_or_track_bar.get_shape()) == 5:
            return tf.concat([out_tensor_melody, out_tensor_others], 4)
开发者ID:Hotim,项目名称:AI_For_Music_Composition,代码行数:29,代码来源:ops.py


示例9: dot_product_attention

  def dot_product_attention(self,x_sen,y_sen,x_len,y_len):
    '''
    function: use the dot-production of left_sen and right_sen to compute the attention weight matrix
    :param left_sen: a list of 2D tensor (x_len,hidden_units)
    :param right_sen: a list of 2D tensor (y_len,hidden_units)
    :return: (1) weighted_y: the weightd sum of y_sen, a 3D tensor with shape (b,x_len,2*h)
             (2)weghted_x:  the weighted sum of x_sen, a 3D tensor with shape (b,y_len,2*h)
    '''
    
    weight_matrix =tf.matmul(x_sen, tf.transpose(y_sen,perm=[0,2,1])) #(b,x_len,h) x (b,h,y_len)->(b,x_len,y_len)

    weight_matrix_y =tf.exp(weight_matrix - tf.reduce_max(weight_matrix,axis=2,keep_dims=True))  #(b,x_len,y_len)
    weight_matrix_x =tf.exp(tf.transpose((weight_matrix - tf.reduce_max(weight_matrix,axis=1,keep_dims=True)),perm=[0,2,1]))  #(b,y_len,x_len)

    weight_matrix_y=weight_matrix_y*self.y_mask[:,None,:]#(b,x_len,y_len)*(b,1,y_len)
    weight_matrix_x=weight_matrix_x*self.x_mask[:,None,:]#(b,y_len,x_len)*(b,1,x_len)
    
    alpha=weight_matrix_y/(tf.reduce_sum(weight_matrix_y,2,keep_dims=True)+1e-8)#(b,x_len,y_len)
    beta=weight_matrix_x/(tf.reduce_sum(weight_matrix_x,2,keep_dims=True)+1e-8)#(b,y_len,x_len)

    #(b,1,y_len,2*h)*(b,x_len,y_len,1)*=>(b,x_len,y_len,2*h) =>(b,x_len,2*h)
    weighted_y =tf.reduce_sum(tf.expand_dims(y_sen,1) *tf.expand_dims(alpha,-1),2)

    #(b,1,x_len,2*h)*(b,y_len,x_len,1) =>(b,y_len,x_len,2*h) =>(b,y_len,2*h)
    weighted_x =tf.reduce_sum(tf.expand_dims(x_sen,1) * tf.expand_dims(beta,-1),2)

    return weighted_y,weighted_x
开发者ID:JShanPP,项目名称:HelloWorld,代码行数:27,代码来源:snli_model_mask.py


示例10: check_convergence

    def check_convergence(self, new_T0, new_transition, new_emission):
        
        delta_T0 = tf.reduce_max(tf.abs(self.T0 - new_T0)) < self.epsilon
        delta_T = tf.reduce_max(tf.abs(self.T - new_transition)) < self.epsilon
        delta_E = tf.reduce_max(tf.abs(self.E - new_emission)) < self.epsilon

        return tf.logical_and(tf.logical_and(delta_T0, delta_T), delta_E)
开发者ID:aliziaei,项目名称:HiddenMarkovModel_TensorFlow,代码行数:7,代码来源:HiddenMarkovModel.py


示例11: call

    def call(self, x, mask=None):
        x1 ,x2 = x
        outer = tf.matmul(tf.expand_dims(x1, axis=2), tf.expand_dims(x2, axis=1))
        outer = tf.matrix_band_part(outer, 0, self.ans_limit)
        output1 = tf.reshape(tf.cast(tf.argmax(tf.reduce_max(outer, axis=2), axis=1), tf.float32),(-1,1))
        output2 = tf.reshape(tf.cast(tf.argmax(tf.reduce_max(outer, axis=1), axis=1), tf.float32),(-1,1))

        return [output1, output2]
开发者ID:sunlinyu1993,项目名称:Machine-Learning-Toolbox,代码行数:8,代码来源:QAoutputBlock.py


示例12: prepare_decoder_components

 def prepare_decoder_components(self):
     self.decoder_cell = tf.nn.rnn_cell.MultiRNNCell([self.lstm_cell() for _ in range(self.n_layers)])
     Y_vocab_size = len(self.Y_word2idx)
     self.decoder_embedding = tf.get_variable('decoder_embedding', [Y_vocab_size, self.decoder_embedding_dim],
                                              tf.float32, tf.random_uniform_initializer(-1.0, 1.0))
     self.projection_layer = Dense(Y_vocab_size)
     self.X_seq_max_len = tf.reduce_max(self.X_seq_len)
     self.Y_seq_max_len = tf.reduce_max(self.Y_seq_len)
开发者ID:huihui7987,项目名称:finch,代码行数:8,代码来源:seq2seq.py


示例13: kl

 def kl(self, other):
     a0 = self.logits - tf.reduce_max(self.logits, axis=-1, keep_dims=True)
     a1 = other.logits - tf.reduce_max(other.logits, axis=-1, keep_dims=True)
     ea0 = tf.exp(a0)
     ea1 = tf.exp(a1)
     z0 = tf.reduce_sum(ea0, axis=-1, keep_dims=True)
     z1 = tf.reduce_sum(ea1, axis=-1, keep_dims=True)
     p0 = ea0 / z0
     return tf.reduce_sum(p0 * (a0 - tf.log(z0) - a1 + tf.log(z1)), axis=-1)
开发者ID:Divyankpandey,项目名称:baselines,代码行数:9,代码来源:distributions.py


示例14: forward

 def forward(self, inputs):
     if self.data_format == 'channels_last':
         outputs = tf.reduce_max(input_tensor=inputs, axis=[1, 2, 3], name=self.name)
     elif self.data_format == 'channels_first':
         outputs = tf.reduce_max(input_tensor=inputs, axis=[2, 3, 4], name=self.name)
     else:
         raise ValueError(
             "`data_format` should have one of the following values: [`channels_last`, `channels_first`]"
         )
     return outputs
开发者ID:zsdonghao,项目名称:tensorlayer,代码行数:10,代码来源:pooling.py


示例15: coverage_box

 def coverage_box(bboxes):
   y_min, x_min, y_max, x_max = tf.split(
       value=bboxes, num_or_size_splits=4, axis=1)
   y_min_coverage = tf.reduce_min(y_min, axis=0)
   x_min_coverage = tf.reduce_min(x_min, axis=0)
   y_max_coverage = tf.reduce_max(y_max, axis=0)
   x_max_coverage = tf.reduce_max(x_max, axis=0)
   return tf.stack(
       [y_min_coverage, x_min_coverage, y_max_coverage, x_max_coverage],
       axis=1)
开发者ID:NoPointExc,项目名称:models,代码行数:10,代码来源:box_list_ops.py


示例16: VI_Block

def VI_Block(X, S1, S2, config):
    k    = config.k    # Number of value iterations performed
    ch_i = config.ch_i # Channels in input layer
    ch_h = config.ch_h # Channels in initial hidden layer
    ch_q = config.ch_q # Channels in q layer (~actions)
    state_batch_size = config.statebatchsize # k+1 state inputs for each channel

    bias  = tf.Variable(np.random.randn(1, 1, 1, ch_h)    * 0.01, dtype=tf.float32)
    # weights from inputs to q layer (~reward in Bellman equation)
    w0    = tf.Variable(np.random.randn(3, 3, ch_i, ch_h) * 0.01, dtype=tf.float32)
    w1    = tf.Variable(np.random.randn(1, 1, ch_h, 1)    * 0.01, dtype=tf.float32)
    w     = tf.Variable(np.random.randn(3, 3, 1, ch_q)    * 0.01, dtype=tf.float32)
    # feedback weights from v layer into q layer (~transition probabilities in Bellman equation)
    w_fb  = tf.Variable(np.random.randn(3, 3, 1, ch_q)    * 0.01, dtype=tf.float32)
    w_o   = tf.Variable(np.random.randn(ch_q, 8)          * 0.01, dtype=tf.float32)

    # initial conv layer over image+reward prior
    h = conv2d_flipkernel(X, w0, name="h0") + bias

    r = conv2d_flipkernel(h, w1, name="r")
    q = conv2d_flipkernel(r, w, name="q")
    v = tf.reduce_max(q, axis=3, keep_dims=True, name="v")

    for i in range(0, k-1):
        rv = tf.concat([r, v], 3)
        wwfb = tf.concat([w, w_fb], 2)
        q = conv2d_flipkernel(rv, wwfb, name="q")
        v = tf.reduce_max(q, axis=3, keep_dims=True, name="v")

    # do one last convolution
    q = conv2d_flipkernel(tf.concat([r, v], 3),
                          tf.concat([w, w_fb], 2), name="q")

    # CHANGE TO THEANO ORDERING
    # Since we are selecting over channels, it becomes easier to work with
    # the tensor when it is in NCHW format vs NHWC
    q = tf.transpose(q, perm=[0, 3, 1, 2])

    # Select the conv-net channels at the state position (S1,S2).
    # This intuitively corresponds to each channel representing an action, and the convnet the Q function.
    # The tricky thing is we want to select the same (S1,S2) position *for each* channel and for each sample
    # TODO: performance can be improved here by substituting expensive
    #       transpose calls with better indexing for gather_nd
    bs = tf.shape(q)[0]
    rprn = tf.reshape(tf.tile(tf.reshape(tf.range(bs), [-1, 1]), [1, state_batch_size]), [-1])
    ins1 = tf.cast(tf.reshape(S1, [-1]), tf.int32)
    ins2 = tf.cast(tf.reshape(S2, [-1]), tf.int32)
    idx_in = tf.transpose(tf.stack([ins1, ins2, rprn]), [1, 0])
    q_out = tf.gather_nd(tf.transpose(q, [2, 3, 0, 1]), idx_in, name="q_out")

    # add logits
    logits = tf.matmul(q_out, w_o)
    # softmax output weights
    output = tf.nn.softmax(logits, name="output")
    return logits, output
开发者ID:BermineCN,项目名称:GVIN,代码行数:55,代码来源:model.py


示例17: kl

 def kl(self, other):
     a0 = self.inputs - tf.reduce_max(self.inputs, reduction_indices=[1],
                                      keep_dims=True)
     a1 = other.inputs - tf.reduce_max(other.inputs, reduction_indices=[1],
                                       keep_dims=True)
     ea0 = tf.exp(a0)
     ea1 = tf.exp(a1)
     z0 = tf.reduce_sum(ea0, reduction_indices=[1], keep_dims=True)
     z1 = tf.reduce_sum(ea1, reduction_indices=[1], keep_dims=True)
     p0 = ea0 / z0
     return tf.reduce_sum(p0 * (a0 - tf.log(z0) - a1 + tf.log(z1)),
                          reduction_indices=[1])
开发者ID:adgirish,项目名称:ray,代码行数:12,代码来源:action_dist.py


示例18: __init__

  def __init__(self, reuse=False, trainable=True):
    # Placeholders for our input
    # Our input are 4 RGB frames of shape 160, 160 each
    self.states = tf.placeholder(shape=[None, 84, 84, 4], dtype=tf.uint8, name="X")
    # The TD target value
    self.targets = tf.placeholder(shape=[None], dtype=tf.float32, name="y")

    X = tf.to_float(self.states) / 255.0
    batch_size = tf.shape(self.states)[0]

    # Graph shared with Value Net
    with tf.variable_scope("shared", reuse=reuse):
      fc1 = build_shared_network(X, add_summaries=(not reuse))

    with tf.variable_scope("value_net"):
      self.logits = tf.contrib.layers.fully_connected(
        inputs=fc1,
        num_outputs=1,
        activation_fn=None)
      self.logits = tf.squeeze(self.logits, squeeze_dims=[1], name="logits")

      self.losses = tf.squared_difference(self.logits, self.targets)
      self.loss = tf.reduce_sum(self.losses, name="loss")

      self.predictions = {
        "logits": self.logits
      }

      # Summaries
      prefix = tf.get_variable_scope().name
      tf.scalar_summary(self.loss.name, self.loss)
      tf.scalar_summary("{}/max_value".format(prefix), tf.reduce_max(self.logits))
      tf.scalar_summary("{}/min_value".format(prefix), tf.reduce_min(self.logits))
      tf.scalar_summary("{}/mean_value".format(prefix), tf.reduce_mean(self.logits))
      tf.scalar_summary("{}/reward_max".format(prefix), tf.reduce_max(self.targets))
      tf.scalar_summary("{}/reward_min".format(prefix), tf.reduce_min(self.targets))
      tf.scalar_summary("{}/reward_mean".format(prefix), tf.reduce_mean(self.targets))
      tf.histogram_summary("{}/reward_targets".format(prefix), self.targets)
      tf.histogram_summary("{}/values".format(prefix), self.logits)

      if trainable:
        # self.optimizer = tf.train.AdamOptimizer(1e-4)
        self.optimizer = tf.train.RMSPropOptimizer(0.00025, 0.99, 0.0, 1e-6)
        self.grads_and_vars = self.optimizer.compute_gradients(self.loss)
        self.grads_and_vars = [[grad, var] for grad, var in self.grads_and_vars if grad is not None]
        self.train_op = self.optimizer.apply_gradients(self.grads_and_vars,
          global_step=tf.contrib.framework.get_global_step())

    var_scope_name = tf.get_variable_scope().name
    summary_ops = tf.get_collection(tf.GraphKeys.SUMMARIES)
    sumaries = [s for s in summary_ops if "policy_net" in s.name or "shared" in s.name]
    sumaries = [s for s in summary_ops if var_scope_name in s.name]
    self.summaries = tf.merge_summary(sumaries)
开发者ID:Selimam,项目名称:reinforcement-learning,代码行数:53,代码来源:estimators.py


示例19: conv

    def conv(self, input, k_h, k_w, c_o, s_h, s_w, name, relu=True, padding=DEFAULT_PADDING, group=1, trainable=True):
        
        print name     
        if isinstance(input, tuple):
            input = input[0]   

        self.validate_padding(padding)
        c_i = input.get_shape()[-1]
        print c_i
        print input.get_shape().as_list()
        assert c_i%group==0
        assert c_o%group==0
        convolve = lambda i, k: tf.nn.conv2d(i, k, [1, s_h, s_w, 1], padding=padding)
        with tf.variable_scope(name) as scope:
            init_weights = tf.truncated_normal_initializer(0.0, stddev=0.01)
            init_biases = tf.constant_initializer(0.0)
            kernel = self.make_var('weights', [k_h, k_w, c_i/group, c_o], init_weights, trainable)
            biases = self.make_var('biases', [c_o], init_biases, trainable)

            
            with tf.name_scope('summaries'):
                with tf.name_scope('weights'):
                    mean = tf.reduce_mean(kernel)
                    tf.summary.scalar('mean', mean)
                    with tf.name_scope('stddev'):
                        stddev = tf.sqrt(tf.reduce_mean(tf.square(kernel- mean)))
                    tf.summary.scalar('stddev', stddev)
                    tf.summary.scalar('max', tf.reduce_max(kernel))
                    tf.summary.scalar('min', tf.reduce_min(kernel))
                    tf.summary.histogram('histogram', kernel)
                with tf.name_scope('biases'):
                    mean = tf.reduce_mean(biases)
                    tf.summary.scalar('mean', mean)
                    with tf.name_scope('stddev'):
                        stddev = tf.sqrt(tf.reduce_mean(tf.square(biases- mean)))
                    tf.summary.scalar('stddev', stddev)
                    tf.summary.scalar('max', tf.reduce_max(biases))
                    tf.summary.scalar('min', tf.reduce_min(biases))
                    tf.summary.histogram('histogram', biases)


            if group==1:
                conv = convolve(input, kernel)
            else:
                input_groups = tf.split(3, group, input)
                kernel_groups = tf.split(3, group, kernel)
                output_groups = [convolve(i, k) for i,k in zip(input_groups, kernel_groups)]
                conv = tf.concat(3, output_groups)
            if relu:
                bias = tf.nn.bias_add(conv, biases)
                return tf.nn.relu(bias, name=scope.name)
            return tf.nn.bias_add(conv, biases, name=scope.name)
开发者ID:chsiyuan,项目名称:542FinalProject,代码行数:52,代码来源:network.py


示例20: getTiles

def getTiles(img_arr):
  """Find and slice 64 chess tiles from image in 3D Matrix"""
  # Get our grayscale image matrix
  A = tf.Variable(img_arr)


  # X & Y gradients
  Dx = gradientx(A)
  Dy = gradienty(A)


  Dx_pos = tf.clip_by_value(Dx, 0., 255., name="dx_positive")
  Dx_neg = tf.clip_by_value(Dx, -255., 0., name='dx_negative')
  Dy_pos = tf.clip_by_value(Dy, 0., 255., name="dy_positive")
  Dy_neg = tf.clip_by_value(Dy, -255., 0., name='dy_negative')

  # 1-D ampltitude of hough transform of gradients about X & Y axes
  # Chessboard lines have strong positive and negative gradients within an axis
  hough_Dx = tf.reduce_sum(Dx_pos, 0) * tf.reduce_sum(-Dx_neg, 0) / (img_arr.shape[0]*img_arr.shape[0])
  hough_Dy = tf.reduce_sum(Dy_pos, 1) * tf.reduce_sum(-Dy_neg, 1) / (img_arr.shape[1]*img_arr.shape[1])

  # Slightly closer to 3/5 threshold, since they're such strong responses
  hough_Dx_thresh = tf.reduce_max(hough_Dx) * 3/5
  hough_Dy_thresh = tf.reduce_max(hough_Dy) * 3/5

  # Transition from TensorFlow to normal values (todo, do TF right) 
  
  # Initialize A with image array input
  # tf.initialize_all_variables().run() # will reset CNN weights so be selective

  # Local tf session
  sess = tf.Session()
  sess.run(tf.initialize_variables([A], name='getTiles_init'))

  # Get chess lines (try a fiew sets)
  hdx, hdy, hdx_thresh, hdy_thresh = sess.run(
    [hough_Dx, hough_Dy, hough_Dx_thresh, hough_Dy_thresh])
  lines_x, lines_y, is_match = getChessLines(hdx, hdy, hdx_thresh, hdy_thresh)
  for percentage in np.array([0.9, 0.8, 0.7, 0.6]):
    if is_match:
      break
    else:
      print("Trying %d%% of threshold" % (100*percentage))
      lines_x, lines_y, is_match = getChessLines(hdx, hdy, 
        hdx_thresh * percentage, hdy_thresh * percentage)

  # Get the tileset
  if is_match:
    return getChessTiles(img_arr, lines_x, lines_y)
  else:
    print("\tNo Match, lines found (dx/dy):", lines_x, lines_y)
    return [] # No match, no tiles
开发者ID:Elucidation,项目名称:tensorflow_chessbot,代码行数:52,代码来源:tensorflow_chessbot.py



注:本文中的tensorflow.reduce_max函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tensorflow.reduce_mean函数代码示例发布时间:2022-05-27
下一篇:
Python tensorflow.reduce_logsumexp函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap