visualize.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
  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. import os
  15. import os.path as osp
  16. from .cls_transforms import ClsTransform
  17. from .det_transforms import DetTransform
  18. from .seg_transforms import SegTransform
  19. def visualize(dataset, index=0, steps=3, save_dir='vdl_output'):
  20. transforms = dataset.transforms
  21. if not osp.isdir(save_dir):
  22. if osp.exists(save_dir):
  23. os.remove(save_dir)
  24. os.makedirs(save_dir)
  25. for i, data in enumerate(dataset.iterator()):
  26. if i == index:
  27. break
  28. from visualdl import LogWriter
  29. vdl_save_dir = osp.join(save_dir, 'image_transforms')
  30. images_writer = LogWriter(vdl_save_dir)
  31. data.append(images_writer)
  32. for s in range(steps):
  33. if s != 0:
  34. data.pop()
  35. data.append(s)
  36. transforms(*data)