Commit
·
66a46f6
1
Parent(s):
c6f74e6
fix: add fallback model loading with multiple Stable Diffusion model paths
Browse files- configs/hair_transfer.yaml +1 -1
- infer_full.py +22 -1
configs/hair_transfer.yaml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
pretrained_model_path: "
|
| 2 |
|
| 3 |
pretrained_folder: "./models/stage2"
|
| 4 |
encoder_path: "pytorch_model.bin"
|
|
|
|
| 1 |
+
pretrained_model_path: "runwayml/stable-diffusion-v1-5" # Original model path
|
| 2 |
|
| 3 |
pretrained_folder: "./models/stage2"
|
| 4 |
encoder_path: "pytorch_model.bin"
|
infer_full.py
CHANGED
|
@@ -35,7 +35,28 @@ class StableHair:
|
|
| 35 |
|
| 36 |
try:
|
| 37 |
### Load controlnet
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
controlnet = ControlNetModel.from_unet(unet).to(device)
|
| 40 |
|
| 41 |
# Try to load custom controlnet weights, fallback to default if not available
|
|
|
|
| 35 |
|
| 36 |
try:
|
| 37 |
### Load controlnet
|
| 38 |
+
# Try multiple model paths in case of access issues
|
| 39 |
+
model_paths = [
|
| 40 |
+
"runwayml/stable-diffusion-v1-5",
|
| 41 |
+
"stabilityai/stable-diffusion-2-1",
|
| 42 |
+
"stabilityai/stable-diffusion-2-1-base"
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
unet = None
|
| 46 |
+
for model_path in model_paths:
|
| 47 |
+
try:
|
| 48 |
+
print(f"Trying to load model from: {model_path}")
|
| 49 |
+
unet = UNet2DConditionModel.from_pretrained(model_path, subfolder="unet").to(device)
|
| 50 |
+
self.config.pretrained_model_path = model_path # Update config with working path
|
| 51 |
+
print(f"Successfully loaded model from: {model_path}")
|
| 52 |
+
break
|
| 53 |
+
except Exception as e:
|
| 54 |
+
print(f"Failed to load {model_path}: {str(e)}")
|
| 55 |
+
continue
|
| 56 |
+
|
| 57 |
+
if unet is None:
|
| 58 |
+
raise Exception("Could not load any Stable Diffusion model")
|
| 59 |
+
|
| 60 |
controlnet = ControlNetModel.from_unet(unet).to(device)
|
| 61 |
|
| 62 |
# Try to load custom controlnet weights, fallback to default if not available
|