|
2 | 2 | import torch |
3 | 3 | import torch.nn as nn |
4 | 4 | from huggingface_hub import hf_hub_download |
5 | | - |
6 | 5 | from diffusers import DDPMScheduler, UNet1DModel |
7 | | - |
| 6 | +from torch.serialization import add_safe_globals |
| 7 | +import numpy.core.multiarray as multiarray |
| 8 | +add_safe_globals([multiarray._reconstruct, np.ndarray, np.dtype, np.dtype(np.float32).type, np.dtype(np.float64).type, np.dtype(np.int32).type, np.dtype(np.int64).type, type(np.dtype(np.float32)), type(np.dtype(np.float64)), type(np.dtype(np.int32)), type(np.dtype(np.int64))]) |
8 | 9 |
|
9 | 10 | """ |
10 | 11 | An example of using HuggingFace's diffusers library for diffusion policy, |
@@ -65,7 +66,7 @@ class DiffusionPolicy: |
65 | 66 | The model expects observations in pixel coordinates (0-512 range) and block angle in radians. |
66 | 67 | It generates trajectories as sequences of (x,y) coordinates also in the 0-512 range. |
67 | 68 | """ |
68 | | - def __init__(self, state_dim=5, device="cuda" if torch.cuda.is_available() else "cpu"): |
| 69 | + def __init__(self, state_dim=5, device="cpu"): |
69 | 70 | self.device = device |
70 | 71 |
|
71 | 72 | # define valid ranges for inputs/outputs |
@@ -94,8 +95,7 @@ def __init__(self, state_dim=5, device="cuda" if torch.cuda.is_available() else |
94 | 95 | ) |
95 | 96 |
|
96 | 97 | # load pre-trained weights from HuggingFace |
97 | | - checkpoint = torch.load(hf_hub_download("dorsar/diffusion_policy", "push_tblock.pt"), map_location=device) |
98 | | - |
| 98 | + checkpoint = torch.load(hf_hub_download("dorsar/diffusion_policy", "push_tblock.pt"), weights_only=True, map_location=device) |
99 | 99 | self.model.load_state_dict(checkpoint['model_state_dict']) |
100 | 100 | self.obs_encoder.load_state_dict(checkpoint['encoder_state_dict']) |
101 | 101 | self.obs_projection.load_state_dict(checkpoint['projection_state_dict']) |
|
0 commit comments