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.

preprocess.py 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. """unet 310 infer preprocess dataset"""
  16. import argparse
  17. from src.data_loader import create_dataset
  18. from src.config import cfg_unet
  19. def preprocess_dataset(data_dir, result_path, cross_valid_ind=1, cfg=None):
  20. _, valid_dataset = create_dataset(data_dir, 1, 1, False, cross_valid_ind, False)
  21. for i, data in enumerate(valid_dataset):
  22. file_name = "ISBI_test_bs_1_" + str(i) + ".bin"
  23. file_path = result_path + file_name
  24. data[0].asnumpy().tofile(file_path)
  25. def get_args():
  26. parser = argparse.ArgumentParser(description='Preprocess the UNet dataset ',
  27. formatter_class=argparse.ArgumentDefaultsHelpFormatter)
  28. parser.add_argument('-d', '--data_url', dest='data_url', type=str, default='data/',
  29. help='data directory')
  30. parser.add_argument('-p', '--result_path', dest='result_path', type=str, default='./preprocess_Result/',
  31. help='result path')
  32. return parser.parse_args()
  33. if __name__ == '__main__':
  34. args = get_args()
  35. preprocess_dataset(data_dir=args.data_url, cross_valid_ind=cfg_unet['cross_valid_ind'], cfg=cfg_unet, result_path=
  36. args.result_path)