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.

histogram_container.py 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """Histogram data container."""
  16. from mindinsight.datavisual.data_transform.histogram import Histogram, Bucket, mask_invalid_number
  17. from mindinsight.datavisual.proto_files.mindinsight_summary_pb2 import Summary
  18. class HistogramContainer:
  19. """
  20. Histogram data container.
  21. Args:
  22. histogram_message (Summary.Histogram): Histogram message in summary file.
  23. """
  24. def __init__(self, histogram_message: Summary.Histogram):
  25. self._msg = histogram_message
  26. original_buckets = [Bucket(bucket.left, bucket.width, bucket.count) for bucket in self._msg.buckets]
  27. # Ensure buckets are sorted from min to max.
  28. original_buckets.sort(key=lambda bucket: bucket.left)
  29. self._count = sum(bucket.count for bucket in original_buckets)
  30. self._max = mask_invalid_number(histogram_message.max)
  31. self._min = mask_invalid_number(histogram_message.min)
  32. self._histogram = Histogram(tuple(original_buckets), self._max, self._min, self._count)
  33. @property
  34. def max(self):
  35. """Gets max value of the tensor."""
  36. return self._max
  37. @property
  38. def min(self):
  39. """Gets min value of the tensor."""
  40. return self._min
  41. @property
  42. def count(self):
  43. """Gets valid number count of the tensor."""
  44. return self._count
  45. @property
  46. def histogram(self):
  47. """Gets histogram data"""
  48. return self._histogram
  49. def buckets(self):
  50. """Gets histogram buckets"""
  51. return self._histogram.buckets()