Skip to content
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

Open
wants to merge 51 commits into
base: main
Choose a base branch
from
Open

Review of master branch #7

wants to merge 51 commits into from

Conversation

meherkasam
Copy link
Member

No description provided.

@@ -0,0 +1,31 @@
# Created by https://www.toptal.com/developers/gitignore/api/macos
Copy link
Member Author

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")
Copy link
Member Author

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()
Copy link
Member Author

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)
Copy link
Member Author

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)
Copy link
Member Author

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"
Copy link
Member Author

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")
Copy link
Member Author

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))
Copy link
Member Author

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):
Copy link
Member Author

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(
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants