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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. original_buckets = [Bucket(bucket.left, bucket.width, bucket.count) for bucket in histogram_message.buckets]
  26. # Ensure buckets are sorted from min to max.
  27. original_buckets.sort(key=lambda bucket: bucket.left)
  28. self._count = sum(bucket.count for bucket in original_buckets)
  29. self._max = mask_invalid_number(histogram_message.max)
  30. self._min = mask_invalid_number(histogram_message.min)
  31. self._histogram = Histogram(tuple(original_buckets), self._max, self._min, self._count)
  32. @property
  33. def max(self):
  34. """Gets max value of the tensor."""
  35. return self._max
  36. @property
  37. def min(self):
  38. """Gets min value of the tensor."""
  39. return self._min
  40. @property
  41. def count(self):
  42. """Gets valid number count of the tensor."""
  43. return self._count
  44. @property
  45. def histogram(self):
  46. """Gets histogram data"""
  47. return self._histogram
  48. def buckets(self):
  49. """Gets histogram buckets"""
  50. return self._histogram.buckets()