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.

test_browse_dataset.py 2.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright 2021 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. import os
  16. import numpy as np
  17. import mindspore.dataset as ds
  18. from mindspore.dataset.utils.browse_dataset import imshow_det_bbox
  19. def test_browse_dataset():
  20. '''
  21. Demo code of visualization on VOC detection dataset.
  22. '''
  23. # init
  24. DATA_DIR = "../data/dataset/testVOC2012_2"
  25. dataset = ds.VOCDataset(DATA_DIR, task="Detection", usage="train", shuffle=False, decode=True, num_samples=3)
  26. dataset_iter = dataset.create_dict_iterator(output_numpy=True, num_epochs=1)
  27. # iter
  28. for index, data in enumerate(dataset_iter):
  29. image = data["image"]
  30. bbox = data["bbox"]
  31. label = data["label"]
  32. masks = np.zeros((4, image.shape[0], image.shape[1]))
  33. masks[0][0:500, 0:500] = 1
  34. masks[1][1000:1500, 1000:1500] = 2
  35. masks[2][0:500, 0:500] = 3
  36. masks[3][1000:1500, 1000:1500] = 4
  37. segm = masks
  38. imshow_det_bbox(image, bbox, label, segm,
  39. class_names=['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair',
  40. 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant',
  41. 'sheep', 'sofa', 'train', 'tvmonitor'],
  42. win_name="windows 98",
  43. wait_time=5,
  44. show=False,
  45. out_file="test_browse_dataset_{}.jpg".format(str(index)))
  46. index += 1
  47. if os.path.exists("test_browse_dataset_0.jpg"):
  48. os.remove("test_browse_dataset_0.jpg")
  49. if os.path.exists("test_browse_dataset_1.jpg"):
  50. os.remove("test_browse_dataset_1.jpg")
  51. if os.path.exists("test_browse_dataset_2.jpg"):
  52. os.remove("test_browse_dataset_2.jpg")
  53. if __name__ == "__main__":
  54. test_browse_dataset()