-
Notifications
You must be signed in to change notification settings - Fork 3
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
Review of master branch #7
base: main
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,31 @@ | |||
# Created by https://www.toptal.com/developers/gitignore/api/macos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to add in Windows, Linux, and Python to this list.
image = st.file_uploader( | ||
"Upload Query Image", type=["png", "jpeg", "jpg", "tif"] | ||
) | ||
submitted_1 = st.form_submit_button("Search") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of using submit_result
as the variable name here?
uploaded_image = create_temp_file(image) | ||
image = read_image(image) | ||
st.image(image) | ||
# placeholder.empty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented code.
image = read_image(image) | ||
st.image(image) | ||
# placeholder.empty() | ||
fig = st.session_state["indexer"].process_image(image, n_neighbors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it explain it better if the variable name was something like processed_image
instead?
|
||
|
||
class Indexer: | ||
# @st.cache(suppress_st_warning=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented line
with torch.no_grad(): | ||
data_matrix = ( | ||
torch.empty(size=(0, size)).cuda() | ||
if device == "cuda" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand this construct in Python. Is this an empty statement with an else
clause that gets executed? If so, I'll recommend using something like:
if device is not "cuda":
torch.empty(size=(0, size))
d = embeddings.shape[-1] | ||
index = faiss.IndexFlatL2(d) | ||
index.add(embeddings) | ||
faiss.write_index(index, "index.bin") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be useful to parameterise the index.bin
file?
|
||
|
||
def get_fig(neighbours, images_list): | ||
fig, axarr = plt.subplots(1, len(neighbours), figsize=(7, 7)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fig
and axarr
don't convey very much.
|
||
|
||
def get_embedding(model, im): | ||
def to_tensor(pil): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is pil
a PIL image? If so might be worthwhile naming it pil_image
.
def to_tensor(pil): | ||
return torch.tensor(np.array(pil)).permute(2, 0, 1).float() | ||
|
||
t = transforms.Compose( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what t
here is. Might be worthwhile giving it a more descriptive name.
No description provided.