Advertisement
Guest User

Untitled

a guest
May 21st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3.  
  4. class LeakyRelu(cv2.dnn_Layer):
  5. def __init__(self, params, blobs):
  6. self._alpha = np.float32(params['alpha'])
  7. self._one = np.float32(1)
  8.  
  9. def getMemoryShapes(self, inputs):
  10. return inputs
  11.  
  12. def _forward_elem(self, x):
  13. m = (x < 0) * self._alpha + (x >= 0) * self._one
  14. return np.multiply(x, m)
  15.  
  16. def forward(self, inputs):
  17. return [self._forward_elem(x) for x in inputs]
  18.  
  19. cv2.dnn_registerLayer('LeakyRelu', LeakyRelu)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement