MCPcopy Index your code
hub / github.com/OpenGVLab/HumanBench / DataContainer

Class DataContainer

PATH/core/data/transforms/pose_transforms.py:97–166  ·  view source on GitHub ↗

A container for any type of objects. Typically tensors will be stacked in the collate function and sliced along some dimension in the scatter function. This behavior has some limitations. 1. All tensors have to be the same size. 2. Types are limited (numpy array or Tensor). We

Source from the content-addressed store, hash-verified

95
96
97class DataContainer:
98 """A container for any type of objects.
99
100 Typically tensors will be stacked in the collate function and sliced along
101 some dimension in the scatter function. This behavior has some limitations.
102 1. All tensors have to be the same size.
103 2. Types are limited (numpy array or Tensor).
104
105 We design `DataContainer` and `MMDataParallel` to overcome these
106 limitations. The behavior can be either of the following.
107
108 - copy to GPU, pad all tensors to the same size and stack them
109 - copy to GPU without stacking
110 - leave the objects as is and pass it to the model
111 - pad_dims specifies the number of last few dimensions to do padding
112 """
113
114 def __init__(self,
115 data,
116 stack=False,
117 padding_value=0,
118 cpu_only=False,
119 pad_dims=2):
120 self._data = data
121 self._cpu_only = cpu_only
122 self._stack = stack
123 self._padding_value = padding_value
124 assert pad_dims in [None, 1, 2, 3]
125 self._pad_dims = pad_dims
126
127 def __repr__(self):
128 return f'{self.__class__.__name__}({repr(self.data)})'
129
130 def __len__(self):
131 return len(self._data)
132
133 @property
134 def data(self):
135 return self._data
136
137 @property
138 def datatype(self):
139 if isinstance(self.data, torch.Tensor):
140 return self.data.type()
141 else:
142 return type(self.data)
143
144 @property
145 def cpu_only(self):
146 return self._cpu_only
147
148 @property
149 def stack(self):
150 return self._stack
151
152 @property
153 def padding_value(self):
154 return self._padding_value

Callers 4

__getitem__Method · 0.90
__call__Method · 0.85
stackFunction · 0.85
collateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected