fix the plus models with image batches

This commit is contained in:
matt3o
2023-09-27 12:24:45 +02:00
parent b5f2782b54
commit 7171f5b117
+2 -3
View File
@@ -94,8 +94,7 @@ def image_add_noise(image, noise):
image = image + ((0.25*(1-noise)+0.05) * torch.randn_like(image) ) # add random noise
return image
def zeroed_hidden_states(clip_vision):
image = torch.zeros( [1, 224, 224, 3] )
def zeroed_hidden_states(clip_vision, image):
img = torch.clip((255. * image), 0, 255).round().int()
img = list(map(lambda a: a, img))
inputs = clip_vision.processor(images=img, return_tensors="pt")
@@ -314,7 +313,7 @@ class IPAdapterApply:
if noise > 0:
clip_embed_zeroed = clip_vision.encode_image(neg_image).penultimate_hidden_states
else:
clip_embed_zeroed = zeroed_hidden_states(clip_vision)
clip_embed_zeroed = zeroed_hidden_states(clip_vision, image)
else:
clip_extra_context_tokens = 4
clip_embed = clip_embed.image_embeds