4d3ea76dcab0d44a9a58a2482cada4b7d5386726,neuron/layers.py,MeanStream,call,#MeanStream#Any#,512

Before Change


    
        // compute this batch stats
        this_sum = tf.reduce_sum(x, 0)
        this_bs = tf.cast(K.shape(x)[0], "float32")  // this batch size
        
        // increase count and compute weights
        new_count = self.count + this_bs
        alpha = this_bs/K.minimum(new_count, self.cap)
        
        // compute new mean. Note that once we reach self.cap (e.g. 1000), the "previous mean" matters less
        new_mean = pre_mean * (1-alpha) + (this_sum/this_bs) * alpha
        

After Change


        self.add_update(updates, x)

        // prep for broadcasting :(
        p = tf.concat((K.reshape(this_bs_int, (1,)), K.shape(self.mean)), 0)
        z = K.ones(p)
        
        // the first few 1000 should not matter that much towards this cost
        return K.minimum(1., new_count/self.cap) * (z * K.expand_dims(new_mean, 0))
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 4

Instances


Project Name: adalca/neuron
Commit Name: 4d3ea76dcab0d44a9a58a2482cada4b7d5386726
Time: 2019-03-07
Author: adalca@mit.edu
File Name: neuron/layers.py
Class Name: MeanStream
Method Name: call


Project Name: tensorflow/models
Commit Name: 2f8481da9bacb3f93d19a9806e83daf886c2d4e2
Time: 2018-12-20
Author: shiningsun@google.com
File Name: official/resnet/keras/keras_imagenet_main.py
Class Name:
Method Name: parse_record_keras


Project Name: dmlc/gluon-nlp
Commit Name: ab9e353c928218d12a977112d241c152ebcf06a9
Time: 2020-01-27
Author: lausen@amazon.com
File Name: src/gluonnlp/model/bert.py
Class Name: BERTEncoder
Method Name: hybrid_forward