Instructions to use phi-lab-rice/GRADE with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use phi-lab-rice/GRADE with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("phi-lab-rice/GRADE", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Download src/Baselines/radarcam-depth/utils/log_utils.py from phi-lab-rice/GRADE: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/phi-lab-rice/GRADE/resolve/main/src/Baselines/radarcam-depth/utils/log_utils.py
- Command line
-
hf download hf://phi-lab-rice/GRADE/src/Baselines/radarcam-depth/utils/log_utils.py
-
curl -L -o log_utils.py https://huggingface.co/phi-lab-rice/GRADE/resolve/main/src/Baselines/radarcam-depth/utils/log_utils.py
1.83 kB
| import os | |
| import torch | |
| import numpy as np | |
| from matplotlib import pyplot as plt | |
| def log(s, filepath=None, to_console=True): | |
| ''' | |
| Logs a string to either file or console | |
| Arg(s): | |
| s : str | |
| string to log | |
| filepath | |
| output filepath for logging | |
| to_console : bool | |
| log to console | |
| ''' | |
| if to_console: | |
| print(s) | |
| if filepath is not None: | |
| if not os.path.isdir(os.path.dirname(filepath)): | |
| os.makedirs(os.path.dirname(filepath)) | |
| with open(filepath, 'w+') as o: | |
| o.write(s + '\n') | |
| else: | |
| with open(filepath, 'a+') as o: | |
| o.write(s + '\n') | |
| def colorize(T, colormap='magma', return_numpy=False): | |
| ''' | |
| Colorizes a 1-channel tensor with matplotlib colormaps | |
| Arg(s): | |
| T : torch.Tensor[float32] | |
| 1-channel tensor | |
| colormap : str | |
| matplotlib colormap | |
| ''' | |
| cm = plt.cm.get_cmap(colormap) | |
| shape = T.shape | |
| # Convert to numpy array and transpose | |
| if shape[0] > 1: | |
| T = np.squeeze(np.transpose(T.cpu().numpy(), (0, 2, 3, 1))) | |
| else: | |
| T = np.squeeze(np.transpose(T.cpu().numpy(), (0, 2, 3, 1)), axis=-1) | |
| # Colorize using colormap | |
| color = np.concatenate([ | |
| np.expand_dims(cm(T[n, ...])[..., 0:3], 0) for n in range(T.shape[0])], | |
| axis=0) | |
| if return_numpy: | |
| return color | |
| else: | |
| # Transpose back to torch format | |
| color = np.transpose(color, (0, 3, 1, 2)) | |
| # Convert back to tensor | |
| return torch.from_numpy(color.astype(np.float32)) | |
| def log_params(log_path, params_dict): | |
| with open(log_path, 'w') as log_file: | |
| for param_name, param_value in params_dict.items(): | |
| log_file.write(f"{param_name}: {param_value}\n") |