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.

attach.py 1.1 kB

3 years ago
12345678910111213141516171819202122232425262728
  1. from typing import Sequence, Callable
  2. from numbers import Number
  3. from kamal.core import exceptions
  4. import pdb
  5. class AttachTo(object):
  6. """ Attach task, metrics or visualizer to specified model outputs
  7. """
  8. def __init__(self, attach_to=None):
  9. if attach_to is not None and not isinstance(attach_to, (Sequence, Number, str, Callable) ):
  10. raise exceptions.InvalidMapping
  11. self._attach_to = attach_to
  12. def __call__(self, *tensors):
  13. if self._attach_to is not None:
  14. if isinstance(self._attach_to, Callable):
  15. return self._attach_to( *tensors )
  16. if isinstance(self._attach_to, Sequence):
  17. _attach_to = self._attach_to
  18. else:
  19. _attach_to = [ self._attach_to for _ in range(len(tensors)) ]
  20. _attach_to = _attach_to[:len(tensors)]
  21. tensors = [ tensor[index] for (tensor, index) in zip( tensors, _attach_to ) ]
  22. if len(tensors)==1:
  23. tensors = tensors[0]
  24. return tensors
  25. def __repr__(self):
  26. rep = "AttachTo: %s"%(self._attach_to)

模型炼知是由浙江大学VIPA团队于2019-2020年期间提出,其目的是建立轻量化的知识融合算法和解决深度模型迁移性度量问题。 本仓库包含TTL、THL、TFL三个模型炼知示例算法,用于计算机视觉领域,通过将多个同构或异构教师重组,实现知识融合,获得定制化的、全能型的学生模型,解决所有教师任务,学生模型性能相比于传统训练结果显著提高。因此,模型炼知具有深入研究和实际应用价值。

Contributors (1)