Spaces:
Runtime error
Runtime error
RRoundTable
commited on
Commit
·
691eb11
1
Parent(s):
adb0128
refac
Browse files
app.py
CHANGED
@@ -75,19 +75,20 @@ def calculate_embedding(
|
|
75 |
embedding = infer(image)
|
76 |
database.append((img_path, embedding))
|
77 |
print(f"Embedding Calculation: {time.time() - start}")
|
78 |
-
filepath = "database.
|
79 |
with open(filepath, "wb") as f:
|
80 |
pickle.dump(database, f)
|
81 |
return filepath
|
82 |
|
83 |
|
84 |
def instance_recognition(
|
85 |
-
|
|
|
86 |
image_path: str,
|
87 |
) -> List[np.ndarray]:
|
88 |
-
with open(
|
89 |
embeddings = pickle.load(f)
|
90 |
-
|
91 |
embedding_vectors = []
|
92 |
image_paths = []
|
93 |
for img_path, embedding in embeddings:
|
@@ -132,6 +133,7 @@ with gr.Blocks() as demo:
|
|
132 |
infer_btn = gr.Button(value="Inference")
|
133 |
input_image = gr.Image(type="filepath", label="Input Image")
|
134 |
image_embedding_file = gr.File(type="file", label="Image Embeddings")
|
|
|
135 |
|
136 |
with gr.Row():
|
137 |
output_images = [
|
@@ -143,7 +145,7 @@ with gr.Blocks() as demo:
|
|
143 |
|
144 |
infer_btn.click(
|
145 |
instance_recognition,
|
146 |
-
inputs=[image_embedding_file, input_image],
|
147 |
outputs=output_images + distances,
|
148 |
)
|
149 |
|
|
|
75 |
embedding = infer(image)
|
76 |
database.append((img_path, embedding))
|
77 |
print(f"Embedding Calculation: {time.time() - start}")
|
78 |
+
filepath = "database.pickle"
|
79 |
with open(filepath, "wb") as f:
|
80 |
pickle.dump(database, f)
|
81 |
return filepath
|
82 |
|
83 |
|
84 |
def instance_recognition(
|
85 |
+
embedding_file,
|
86 |
+
zipfile,
|
87 |
image_path: str,
|
88 |
) -> List[np.ndarray]:
|
89 |
+
with open(embedding_file.name, "rb") as f:
|
90 |
embeddings = pickle.load(f)
|
91 |
+
unzip(zipfile.name)
|
92 |
embedding_vectors = []
|
93 |
image_paths = []
|
94 |
for img_path, embedding in embeddings:
|
|
|
133 |
infer_btn = gr.Button(value="Inference")
|
134 |
input_image = gr.Image(type="filepath", label="Input Image")
|
135 |
image_embedding_file = gr.File(type="file", label="Image Embeddings")
|
136 |
+
image_zip_file = gr.File(type="file", label="Image Zip File")
|
137 |
|
138 |
with gr.Row():
|
139 |
output_images = [
|
|
|
145 |
|
146 |
infer_btn.click(
|
147 |
instance_recognition,
|
148 |
+
inputs=[image_embedding_file, image_zip_file, input_image],
|
149 |
outputs=output_images + distances,
|
150 |
)
|
151 |
|