Spaces:
Build error
Build error
feature: extract feature from user input image
Browse files- image2text.py +6 -2
image2text.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import numpy as np
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
from utils import load_model
|
|
@@ -22,8 +23,11 @@ def app(model_name):
|
|
| 22 |
st.error("Please upload an image query.")
|
| 23 |
else:
|
| 24 |
image = Image.open(query)
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
# ids, dists = index.knnQuery(vec, k=10)
|
| 28 |
# result_files = map(lambda id: files[id], ids)
|
| 29 |
# result_imgs, result_captions = [], []
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import numpy as np
|
| 3 |
+
import jax.numpy as jnp
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
from utils import load_model
|
|
|
|
| 23 |
st.error("Please upload an image query.")
|
| 24 |
else:
|
| 25 |
image = Image.open(query)
|
| 26 |
+
pixel_values = processor(
|
| 27 |
+
text=[""], images=image, return_tensors="jax", padding=True
|
| 28 |
+
).pixel_values
|
| 29 |
+
pixel_values = jnp.transpose(pixel_values, axes=[0, 2, 3, 1])
|
| 30 |
+
vec = np.asarray(model.get_image_features(pixel_values))
|
| 31 |
# ids, dists = index.knnQuery(vec, k=10)
|
| 32 |
# result_files = map(lambda id: files[id], ids)
|
| 33 |
# result_imgs, result_captions = [], []
|