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

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