14
14
from LightGlue .lightglue import LightGlue , SuperPoint
15
15
from LightGlue .lightglue .utils import rbd
16
16
17
- from models_diffusers .unet_spatio_temporal_condition import UNetSpatioTemporalConditionModel
17
+ from models_diffusers .unet_spatio_temporal_condition import (
18
+ UNetSpatioTemporalConditionModel ,
19
+ )
18
20
from models_diffusers .controlnet_svd import ControlNetSVDModel
19
21
20
- from cotracker .predictor import CoTrackerPredictor , sample_trajectories_with_ref
22
+ try :
23
+ from cotracker .predictor import CoTrackerPredictor , sample_trajectories_with_ref
24
+ except :
25
+ pass
21
26
22
27
from lineart_extractor .canny import CannyDetector
23
28
from lineart_extractor .hed import HEDdetector
50
55
folder_paths .supported_pt_extensions ,
51
56
)
52
57
58
+
53
59
class AniDocLoader :
54
60
@classmethod
55
61
def INPUT_TYPES (cls ):
@@ -80,17 +86,20 @@ def load_anidoc(
80
86
if self .pipeline is None :
81
87
pbar = ProgressBar (5 )
82
88
83
- if not os .path .exists (anidoc_path ):
84
- log .info (f"Downloading AniDoc model to: { anidoc_path } " )
89
+ pbar .update (1 )
90
+
91
+ log .info (f"Loading model from: { anidoc_path } " )
92
+ log .info ("Missing models will be downloaded" )
93
+
94
+ try :
85
95
snapshot_download (
86
96
repo_id = "Yhmeng1106/anidoc" ,
97
+ ignore_patterns = ["*.md" ],
87
98
local_dir = DIFFUSERS_DIR ,
88
99
local_dir_use_symlinks = False ,
89
100
)
90
-
91
- pbar .update (1 )
92
-
93
- log .info (f"Loading model from: { anidoc_path } " )
101
+ except :
102
+ log .info ("Couldn't download models" )
94
103
95
104
unet = UNetSpatioTemporalConditionModel .from_pretrained (
96
105
anidoc_path ,
@@ -111,23 +120,25 @@ def load_anidoc(
111
120
pbar .update (1 )
112
121
113
122
if XFORMERS_IS_AVAILABLE :
114
- log .info (f "Enabling XFormers" )
123
+ log .info ("Enabling XFormers" )
115
124
unet .enable_xformers_memory_efficient_attention ()
116
125
117
- if not os .path .exists (svd_img2vid_path ):
118
- log .info (f"Downloading stable diffusion video img2vid to: { svd_img2vid_path } " )
126
+ log .info (f"Loading model from: { svd_img2vid_path } " )
127
+ log .info ("Missing models will be downloaded" )
128
+
129
+ try :
119
130
snapshot_download (
120
131
repo_id = "vdo/stable-video-diffusion-img2vid-xt-1-1" ,
121
- allow_patterns = [f "*.json" , "*fp16*" ],
132
+ allow_patterns = ["*.json" , "*fp16*" ],
122
133
ignore_patterns = ["*unet*" ],
123
134
local_dir = svd_img2vid_path ,
124
135
local_dir_use_symlinks = False ,
125
136
)
137
+ except :
138
+ log .info ("Couldn't download models" )
126
139
127
140
pbar .update (1 )
128
141
129
- log .info (f"Loading model from: { svd_img2vid_path } " )
130
-
131
142
pipeline = AniDocPipeline .from_pretrained (
132
143
svd_img2vid_path ,
133
144
unet = unet ,
@@ -190,6 +201,11 @@ def load_tracker(
190
201
device = "cuda" ,
191
202
dtype = torch .float32 ,
192
203
):
204
+ try :
205
+ import cotracker
206
+ except :
207
+ raise ImportError ("Couldn't import cotracker module. Please install it to use this node" )
208
+
193
209
if tracking :
194
210
if self .tracker is None or self .tracker_shift_grid != tracker_shift_grid :
195
211
cotracker_model_path = folder_paths .get_full_path (
@@ -278,7 +294,7 @@ def invert_images(self, image):
278
294
return cv2 .bitwise_not (image )
279
295
else :
280
296
return 255 - image
281
-
297
+
282
298
def get_controlnet_images (
283
299
self ,
284
300
input_images ,
@@ -295,7 +311,7 @@ def get_controlnet_images(
295
311
296
312
pbar .update (1 )
297
313
298
- log .info (f "Processing images with lineart detector" )
314
+ log .info ("Processing images with lineart detector" )
299
315
300
316
controlnet_images = []
301
317
@@ -307,7 +323,7 @@ def get_controlnet_images(
307
323
sketch = detector (sketch , 100 , 200 )
308
324
else :
309
325
sketch = detector (sketch )
310
-
326
+
311
327
if lineart_detector in ["canny" , "hed" ]:
312
328
sketch = self .invert_images (sketch )
313
329
@@ -689,7 +705,9 @@ def sample(
689
705
noise_aug_strength = noise_aug ,
690
706
decode_chunk_size = decode_chunk_size ,
691
707
generator = generator ,
692
- callback_on_step_end = lambda * args , ** kwargs : (pbar .update (1 ), kwargs )[- 1 ],
708
+ callback_on_step_end = lambda * args , ** kwargs : (pbar .update (1 ), kwargs )[
709
+ - 1
710
+ ],
693
711
).frames [0 ]
694
712
695
713
tensor_frames = [T .ToTensor ()(img ) for img in video_frames ]
0 commit comments