Spaces:
Runtime error
Runtime error
Commit
·
bda7138
1
Parent(s):
27dab1f
Update app.py
Browse files
app.py
CHANGED
@@ -130,6 +130,8 @@ def pil_image_to_base64(pil_image):
|
|
130 |
return base64_image
|
131 |
|
132 |
image_cache = {}
|
|
|
|
|
133 |
def compute_image_state(image):
|
134 |
base64_image = pil_image_to_base64(image)
|
135 |
if base64_image in image_cache:
|
@@ -139,10 +141,10 @@ def compute_image_state(image):
|
|
139 |
image = image.to(device)
|
140 |
image_features = visual_encoder.encode_images(image.unsqueeze(0)).squeeze(0) # [L, D]
|
141 |
# apply layer norm to image feature, very important
|
142 |
-
image_features = F.layer_norm(image_features
|
143 |
(image_features.shape[-1],),
|
144 |
-
weight=
|
145 |
-
bias=
|
146 |
_, image_state = model.forward(embs=image_features, state=None)
|
147 |
image_cache[base64_image] = image_state
|
148 |
return image_state
|
|
|
130 |
return base64_image
|
131 |
|
132 |
image_cache = {}
|
133 |
+
ln0_weight = model.w['blocks.0.ln0.weight'].to(torch.float32).to(device)
|
134 |
+
ln0_bias = model.w['blocks.0.ln0.bias'].to(torch.float32).to(device)
|
135 |
def compute_image_state(image):
|
136 |
base64_image = pil_image_to_base64(image)
|
137 |
if base64_image in image_cache:
|
|
|
141 |
image = image.to(device)
|
142 |
image_features = visual_encoder.encode_images(image.unsqueeze(0)).squeeze(0) # [L, D]
|
143 |
# apply layer norm to image feature, very important
|
144 |
+
image_features = F.layer_norm(image_features,
|
145 |
(image_features.shape[-1],),
|
146 |
+
weight=ln0_weight,
|
147 |
+
bias=ln0_bias)
|
148 |
_, image_state = model.forward(embs=image_features, state=None)
|
149 |
image_cache[base64_image] = image_state
|
150 |
return image_state
|