input_helper.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
  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. def multiscale_def(image_shape, num_scale, use_flip=True):
  15. base_name_list = ['image']
  16. multiscale_def = {}
  17. ms_def_names = []
  18. if use_flip:
  19. num_scale //= 2
  20. base_name_list.append('image_flip')
  21. multiscale_def['image_flip'] = {
  22. 'shape': [None] + image_shape,
  23. 'dtype': 'float32',
  24. 'lod_level': 0
  25. }
  26. multiscale_def['im_info_image_flip'] = {
  27. 'shape': [None, 3],
  28. 'dtype': 'float32',
  29. 'lod_level': 0
  30. }
  31. ms_def_names.append('image_flip')
  32. ms_def_names.append('im_info_image_flip')
  33. for base_name in base_name_list:
  34. for i in range(0, num_scale - 1):
  35. name = base_name + '_scale_' + str(i)
  36. multiscale_def[name] = {
  37. 'shape': [None] + image_shape,
  38. 'dtype': 'float32',
  39. 'lod_level': 0
  40. }
  41. im_info_name = 'im_info_' + name
  42. multiscale_def[im_info_name] = {
  43. 'shape': [None, 3],
  44. 'dtype': 'float32',
  45. 'lod_level': 0
  46. }
  47. ms_def_names.append(name)
  48. ms_def_names.append(im_info_name)
  49. return multiscale_def, ms_def_names