5e35bf984690a196063e3eb3fe5807b1475e7d0e,capsulelayers.py,CapsuleLayer,call,#CapsuleLayer#,94

Before Change


        for _ in range(self.num_routing):
            c = K.softmax(self.bias)
            c_expand = K.expand_dims(K.expand_dims(K.expand_dims(c, 2), 2), 0)
            outputs = K.sum(c_expand * inputs_hat, 1, keepdims=True)
            outputs = squash(outputs)
            self.bias = K.update(self.bias, self.bias + K.sum(inputs_hat * outputs, [0, -2, -1]))

        // Handling with no routing scenario. Prior bias will always be zero.
        if self.num_routing == 0:
            c = K.softmax(self.bias)
            c_expand = K.expand_dims(K.expand_dims(K.expand_dims(c, 2), 2), 0)
            outputs = squash(K.sum(c_expand * inputs_hat, 1, keepdims=True))

        return K.reshape(outputs, [-1, self.num_capsule, self.dim_vector])

After Change


        _, self.bias, outputs = tf.while_loop(cond, body, loop_vars)

        // Routing algorithm V2. Use for iteration. V2 and V1 both work without much difference on performance
        assert self.num_routing > 0, "The num_routing should be > 0."
        for i in range(self.num_routing):
            c = tf.nn.softmax(self.bias, dim=2)  // dim=2 is the num_capsule dimension
            // outputs.shape=[None, 1, num_capsule, 1, dim_vector]
            outputs = squash(K.sum(c * inputs_hat, 1, keepdims=True))
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 5

Non-data size: 3

Instances


Project Name: XifengGuo/CapsNet-Keras
Commit Name: 5e35bf984690a196063e3eb3fe5807b1475e7d0e
Time: 2017-11-01
Author: guoxifeng1990@163.com
File Name: capsulelayers.py
Class Name: CapsuleLayer
Method Name: call


Project Name: fgnt/pb_bss
Commit Name: b6ee3d5b67fcb6903156a2b59f4a3832323adf27
Time: 2019-08-16
Author: mail@lukas-drude.de
File Name: nt/evaluation/sxr.py
Class Name:
Method Name: output_sxr


Project Name: deepinsight/insightface
Commit Name: fd10b74b45692e53047149cb4d526067845b4a7d
Time: 2020-11-06
Author: guojia@gmail.com
File Name: deploy/test.py
Class Name:
Method Name:


Project Name: google/unrestricted-adversarial-examples
Commit Name: b09bd8bb21519b0503ef59b8a801e7c1c8db4ae6
Time: 2018-09-12
Author: nottombrown@gmail.com
File Name: unrestricted-advex/unrestricted_advex/eval_kit.py
Class Name:
Method Name: evaluate_two_class_unambiguous_model


Project Name: XifengGuo/CapsNet-Keras
Commit Name: 688e64fd31e85371d51f44053bac2acde2328f1e
Time: 2017-10-30
Author: guoxifeng1990@163.com
File Name: capsulelayers.py
Class Name: Mask
Method Name: call