Exemplo n.º 1
0
 def call(self, inputs):
   x1 = inputs[0]
   x2 = inputs[1]
   if isinstance(self.axes, int):
     if self.axes < 0:
       axes = [self.axes % K.ndim(x1), self.axes % K.ndim(x2)]
     else:
       axes = [self.axes] * 2
   else:
     axes = []
     for i in range(len(self.axes)):
       if self.axes[i] < 0:
         axes.append(self.axes[i] % K.ndim(inputs[i]))
       else:
         axes.append(self.axes[i])
   if self.normalize:
     x1 = K.l2_normalize(x1, axis=axes[0])
     x2 = K.l2_normalize(x2, axis=axes[1])
   output = K.batch_dot(x1, x2, axes)
   return output
Exemplo n.º 2
0
 def call(self, inputs):
     x1 = inputs[0]
     x2 = inputs[1]
     if isinstance(self.axes, int):
         if self.axes < 0:
             axes = [self.axes % K.ndim(x1), self.axes % K.ndim(x2)]
         else:
             axes = [self.axes] * 2
     else:
         axes = []
         for i in range(len(self.axes)):
             if self.axes[i] < 0:
                 axes.append(self.axes[i] % K.ndim(inputs[i]))
             else:
                 axes.append(self.axes[i])
     if self.normalize:
         x1 = K.l2_normalize(x1, axis=axes[0])
         x2 = K.l2_normalize(x2, axis=axes[1])
     output = K.batch_dot(x1, x2, axes)
     return output
Exemplo n.º 3
0
 def _merge_function(self, inputs):
   if len(inputs) != 2:
     raise ValueError('A `Dot` layer should be called ' 'on exactly 2 inputs')
   x1 = inputs[0]
   x2 = inputs[1]
   if isinstance(self.axes, int):
     if self.axes < 0:
       axes = [self.axes % K.ndim(x1), self.axes % K.ndim(x2)]
     else:
       axes = [self.axes] * 2
   else:
     axes = []
     for i in range(len(self.axes)):
       if self.axes[i] < 0:
         axes.append(self.axes[i] % K.ndim(inputs[i]))
       else:
         axes.append(self.axes[i])
   if self.normalize:
     x1 = K.l2_normalize(x1, axis=axes[0])
     x2 = K.l2_normalize(x2, axis=axes[1])
   output = K.batch_dot(x1, x2, axes)
   return output
Exemplo n.º 4
0
 def _merge_function(self, inputs):
     if len(inputs) != 2:
         raise ValueError('A `Dot` layer should be called '
                          'on exactly 2 inputs')
     x1 = inputs[0]
     x2 = inputs[1]
     if isinstance(self.axes, int):
         if self.axes < 0:
             axes = [self.axes % K.ndim(x1), self.axes % K.ndim(x2)]
         else:
             axes = [self.axes] * 2
     else:
         axes = []
         for i in range(len(self.axes)):
             if self.axes[i] < 0:
                 axes.append(self.axes[i] % K.ndim(inputs[i]))
             else:
                 axes.append(self.axes[i])
     if self.normalize:
         x1 = K.l2_normalize(x1, axis=axes[0])
         x2 = K.l2_normalize(x2, axis=axes[1])
     output = K.batch_dot(x1, x2, axes)
     return output