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 2.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. """
  16. ##############preprocess#################
  17. """
  18. import argparse
  19. import os
  20. import numpy as np
  21. from src.config import lstm_cfg, lstm_cfg_ascend
  22. from src.dataset import lstm_create_dataset
  23. parser = argparse.ArgumentParser(description='preprocess')
  24. parser.add_argument('--preprocess_path', type=str, default="./preprocess",
  25. help='path where the pre-process data is stored.')
  26. parser.add_argument('--result_path', type=str, default='./preprocess_Result/', help='result path')
  27. parser.add_argument('--device_target', type=str, default="Ascend", choices=['GPU', 'CPU', 'Ascend'],
  28. help='the target device to run, support "GPU", "CPU". Default: "Ascend".')
  29. args = parser.parse_args()
  30. if __name__ == '__main__':
  31. if args.device_target == 'Ascend':
  32. cfg = lstm_cfg_ascend
  33. else:
  34. cfg = lstm_cfg
  35. dataset = lstm_create_dataset(args.preprocess_path, cfg.batch_size, training=False)
  36. img_path = os.path.join(args.result_path, "00_data")
  37. os.makedirs(img_path)
  38. label_list = []
  39. for i, data in enumerate(dataset.create_dict_iterator(output_numpy=True)):
  40. file_name = "LSTM_data_bs" + str(cfg.batch_size) + "_" + str(i) + ".bin"
  41. file_path = img_path + "/" + file_name
  42. data['feature'].tofile(file_path)
  43. label_list.append(data['label'])
  44. np.save(args.result_path + "label_ids.npy", label_list)
  45. print("="*20, "export bin files finished", "="*20)