Download src/datasets/utils.py from L-yiheng/NMR: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/L-yiheng/NMR/resolve/main/src/datasets/utils.py
- Command line
-
hf download hf://L-yiheng/NMR/src/datasets/utils.py
-
curl -L -o utils.py https://huggingface.co/L-yiheng/NMR/resolve/main/src/datasets/utils.py
1.25 kB
| import torch | |
| from torch.nn.utils.rnn import pad_sequence | |
| from mmengine.registry import FUNCTIONS | |
| def motion_collate_fn(batch): | |
| motion = [item['motion'] for item in batch] # [motion: T, C] | |
| motion_length = [item['motion_length'] for item in batch] | |
| # caption = [item['caption'] for item in batch] | |
| motion = pad_sequence(motion, batch_first=True) | |
| mean = torch.stack([item['mean'] for item in batch], dim=0) | |
| std = torch.stack([item['std'] for item in batch], dim=0) | |
| return dict( | |
| std=std, mean=mean, motion=motion, | |
| motion_length=torch.tensor(motion_length), | |
| # caption=caption | |
| ) | |
| def motion_collate_fn_no_translation(batch): | |
| motion = [item['motion'] for item in batch] # [motion: T, C] | |
| motion_length = [item['motion_length'] for item in batch] | |
| # caption = [item['caption'] for item in batch] | |
| motion = pad_sequence(motion, batch_first=True) | |
| mean = torch.stack([item['mean'] for item in batch], dim=0) | |
| std = torch.stack([item['std'] for item in batch], dim=0) | |
| return dict( | |
| std=std, mean=mean, motion=motion[..., 3:], | |
| motion_length=torch.tensor(motion_length), | |
| # caption=caption | |
| ) |