Spaces:
Sleeping
Sleeping
Download src/utils/numpy.py from ceccurr/EquiFusion: direct link, hf CLI and curl.
- Browser
- Download file 365 Bytes
-
https://huggingface.co/spaces/ceccurr/EquiFusion/resolve/main/src/utils/numpy.py
- Command line
-
hf download hf://spaces/ceccurr/EquiFusion/src/utils/numpy.py
-
curl -L -o numpy.py https://huggingface.co/spaces/ceccurr/EquiFusion/resolve/main/src/utils/numpy.py
365 Bytes
| import torch | |
| import numpy as np | |
| def numpy_img_to_tensor(np_array): | |
| return torch.tensor(np_array).permute(2, 0, 1) | |
| def get_fig_as_nparray(fig): | |
| fig.canvas.draw() # draw the canvas, cache the renderer | |
| image = np.frombuffer(fig.canvas.tostring_rgb(), dtype='uint8') | |
| image = image.reshape(fig.canvas.get_width_height()[::-1] + (3,)) | |
| return image |