File size: 1,518 Bytes
ba2ab36 c5c3fa2 ba2ab36 c5c3fa2 ba2ab36 c5c3fa2 ba2ab36 c5c3fa2 ba2ab36 c5c3fa2 ba2ab36 c5c3fa2 ba2ab36 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import streamlit as st
from lib.utils.model import get_model, get_similarities
from PIL import Image
st.title('IRRA Text-To-Image-Retrival')
st.markdown('A text-to-image retrieval model implemented from [arXiv: Cross-Modal Implicit Relation Reasoning and Aligning for Text-to-Image Person Retrieval](https://arxiv.org/abs/2303.12501)')
st.header('Inputs')
caption = st.text_input('Description Input')
images = st.file_uploader('Upload images', accept_multiple_files=True)
if images is not None:
st.image(images) # type: ignore
st.header('Options')
st.subheader('Ranks', help='How many predictions the model is allowed to make')
ranks = st.slider('slider_ranks', min_value=1, max_value=10, label_visibility='collapsed',value=5)
button = st.button('Match most similar', disabled=len(images) == 0 or caption == '')
if button:
st.header('Results')
with st.spinner('Loading model'):
model = get_model()
st.text(f'IRRA model loaded with {sum(p.numel() for p in model.parameters()) / 1e6:.0f}M parameters')
with st.spinner('Computing and ranking similarities'):
similarities = get_similarities(caption, images, model).squeeze(0)
indices = similarities.argsort(descending=True).cpu().tolist()[:ranks]
for i, idx in enumerate(indices):
c1, c2, c3 = st.columns(3)
with c1:
st.text(f'Rank {i + 1}')
with c2:
st.image(images[idx])
with c3:
st.text(f'Cosine sim {similarities[idx].cpu():.2f}')
|