You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

quantize.py 1.1 kB

4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. from tensorlayer import logging
  4. from tensorlayer.layers.core import Module
  5. from tensorlayer.layers.utils import quantize
  6. __all__ = [
  7. 'Sign',
  8. ]
  9. class Sign(Module):
  10. """The :class:`SignLayer` class is for quantizing the layer outputs to -1 or 1 while inferencing.
  11. Parameters
  12. ----------
  13. name : a str
  14. A unique layer name.
  15. """
  16. # @deprecated_alias(layer='prev_layer', end_support_version=1.9) # TODO remove this line for the 1.9 release
  17. def __init__(
  18. self,
  19. name=None # 'sign',
  20. ):
  21. super().__init__(name)
  22. logging.info("Sign %s" % self.name)
  23. self.build()
  24. self._built = True
  25. def build(self, inputs_shape=None):
  26. pass
  27. def __repr__(self):
  28. s = ('{classname}(')
  29. if self.name is not None:
  30. s += ', name=\'{name}\''
  31. s += ')'
  32. return s.format(classname=self.__class__.__name__, **self.__dict__)
  33. def forward(self, inputs):
  34. outputs = quantize(inputs)
  35. return outputs

TensorLayer3.0 是一款兼容多种深度学习框架为计算后端的深度学习库。计划兼容TensorFlow, Pytorch, MindSpore, Paddle.