custom_dataset.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright (c) 2018-present, Facebook, Inc.
  2. # All rights reserved.
  3. #
  4. # This source code is licensed under the license found in the
  5. # LICENSE file in the root directory of this source tree.
  6. #
  7. import numpy as np
  8. import copy
  9. from video_pose.common.skeleton import Skeleton
  10. from video_pose.common.mocap_dataset import MocapDataset
  11. from video_pose.common.camera import normalize_screen_coordinates, image_coordinates
  12. from video_pose.common.h36m_dataset import h36m_skeleton
  13. custom_camera_params = {
  14. 'id': None,
  15. 'res_w': None, # Pulled from metadata
  16. 'res_h': None, # Pulled from metadata
  17. # Dummy camera parameters (taken from Human3.6M), only for visualization purposes
  18. 'azimuth': 70, # Only used for visualization
  19. 'orientation': [0.1407056450843811, -0.1500701755285263, -0.755240797996521, 0.6223280429840088],
  20. 'translation': [1841.1070556640625, 4955.28466796875, 1563.4454345703125],
  21. }
  22. class CustomDataset(MocapDataset):
  23. def __init__(self, detections_path, remove_static_joints=True):
  24. super().__init__(fps=None, skeleton=h36m_skeleton)
  25. # Load serialized dataset
  26. data = np.load(detections_path, allow_pickle=True)
  27. resolutions = data['metadata'].item()['video_metadata']
  28. self._cameras = {}
  29. self._data = {}
  30. for video_name, res in resolutions.items():
  31. cam = {}
  32. cam.update(custom_camera_params)
  33. cam['orientation'] = np.array(cam['orientation'], dtype='float32')
  34. cam['translation'] = np.array(cam['translation'], dtype='float32')
  35. cam['translation'] = cam['translation']/1000 # mm to meters
  36. cam['id'] = video_name
  37. cam['res_w'] = res['w']
  38. cam['res_h'] = res['h']
  39. self._cameras[video_name] = [cam]
  40. self._data[video_name] = {
  41. 'custom': {
  42. 'cameras': cam
  43. }
  44. }
  45. if remove_static_joints:
  46. # Bring the skeleton to 17 joints instead of the original 32
  47. self.remove_joints([4, 5, 9, 10, 11, 16, 20, 21, 22, 23, 24, 28, 29, 30, 31])
  48. # Rewire shoulders to the correct parents
  49. self._skeleton._parents[11] = 8
  50. self._skeleton._parents[14] = 8
  51. def supports_semi_supervised(self):
  52. return False