|
2 | 2 | # Adopted and optimized for Invoke AI |
3 | 3 |
|
4 | 4 | import pathlib |
5 | | -from typing import Any, Literal, OrderedDict |
| 5 | +from typing import Any, Literal |
6 | 6 |
|
7 | 7 | import cv2 |
8 | 8 | import numpy as np |
9 | 9 | import numpy.typing as npt |
10 | 10 | import torch |
11 | 11 | from PIL import Image |
12 | | -from torch.serialization import add_safe_globals |
| 12 | +from safetensors.torch import load_file |
13 | 13 |
|
14 | 14 | from invokeai.backend.image_util.pbr_maps.architecture.pbr_rrdb_net import PBR_RRDB_Net |
15 | 15 | from invokeai.backend.image_util.pbr_maps.utils.image_ops import crop_seamless, esrgan_launcher_split_merge |
16 | 16 |
|
17 | | -NORMAL_MAP_MODEL = "https://github.com/joeyballentine/Material-Map-Generator/blob/master/utils/models/1x_NormalMapGenerator-CX-Lite_200000_G.pth" |
18 | | -OTHER_MAP_MODEL = "https://github.com/joeyballentine/Material-Map-Generator/blob/master/utils/models/1x_FrankenMapGenerator-CX-Lite_215000_G.pth" |
| 17 | +NORMAL_MAP_MODEL = ( |
| 18 | + "https://huggingface.co/InvokeAI/pbr-material-maps/resolve/main/normal_map_generator.safetensors?download=true" |
| 19 | +) |
| 20 | +OTHER_MAP_MODEL = ( |
| 21 | + "https://huggingface.co/InvokeAI/pbr-material-maps/resolve/main/franken_map_generator.safetensors?download=true" |
| 22 | +) |
19 | 23 |
|
20 | 24 |
|
21 | 25 | class PBRMapsGenerator: |
22 | 26 | def __init__(self, normal_map_model: PBR_RRDB_Net, other_map_model: PBR_RRDB_Net, device: torch.device) -> None: |
23 | 27 | self.normal_map_model = normal_map_model |
24 | 28 | self.other_map_model = other_map_model |
25 | 29 | self.device = device |
26 | | - add_safe_globals([PBR_RRDB_Net, OrderedDict]) |
27 | 30 |
|
28 | 31 | @staticmethod |
29 | 32 | def load_model(model_path: pathlib.Path, device: torch.device) -> PBR_RRDB_Net: |
30 | | - state_dict = torch.load(model_path.as_posix(), map_location="cpu") |
| 33 | + state_dict = load_file(model_path.as_posix(), device=device.type) |
31 | 34 |
|
32 | 35 | model = PBR_RRDB_Net( |
33 | 36 | 3, |
|
0 commit comments