Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update core.py #632

Open
wants to merge 1 commit into
base: Main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 4 additions & 31 deletions modules/impact/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,38 +420,11 @@ def enhance_detail_for_animatediff(image_frames, model, clip, vae, guide_size, g
# upscale the mask tensor by a factor of 2 using bilinear interpolation
if isinstance(noise_mask, np.ndarray):
noise_mask = torch.from_numpy(noise_mask)
noise_mask = noise_mask.unsqueeze(0) if len(noise_mask.shape) == 2 else noise_mask
upscaled_mask = [torch.nn.functional.interpolate(m.unsqueeze(0).unsqueeze(0), size=(new_h, new_w), mode='bilinear', align_corners=False).squeeze(0) for m in noise_mask]
upscaled_mask = torch.stack(upscaled_mask, dim=0) if len(upscaled_mask) > 1 else upscaled_mask[0]

if len(noise_mask.shape) == 2:
noise_mask = noise_mask.unsqueeze(0)
else: # == 3
noise_mask = noise_mask

upscaled_mask = None

for single_mask in noise_mask:
single_mask = single_mask.unsqueeze(0).unsqueeze(0)
upscaled_single_mask = torch.nn.functional.interpolate(single_mask, size=(new_h, new_w), mode='bilinear', align_corners=False)
upscaled_single_mask = upscaled_single_mask.squeeze(0)

if upscaled_mask is None:
upscaled_mask = upscaled_single_mask
else:
upscaled_mask = torch.cat((upscaled_mask, upscaled_single_mask), dim=0)

latent_frames = None
for image in image_frames:
image = torch.from_numpy(image).unsqueeze(0)

# upscale
upscaled_image = tensor_resize(image, new_w, new_h)

# ksampler
samples = to_latent_image(upscaled_image, vae)['samples']

if latent_frames is None:
latent_frames = samples
else:
latent_frames = torch.concat((latent_frames, samples), dim=0)
latent_frames = torch.cat([to_latent_image(tensor_resize(torch.from_numpy(frame).unsqueeze(0), new_w, new_h)['samples']) for frame in image_frames], dim=0)

cnet_images = None
if control_net_wrapper is not None:
Expand Down