Spaces:
Configuration error
Configuration error
englert
commited on
Commit
·
ebf1c68
1
Parent(s):
1f88a07
update app.py
Browse files
app.py
CHANGED
@@ -51,14 +51,15 @@ def predict(input_file, downsample_size):
|
|
51 |
in_img = torch.from_numpy(in_img).float()
|
52 |
encoded = avg_pool(model(in_img))[0, :, 0, 0].cpu().numpy()
|
53 |
img_vecs += [encoded]
|
54 |
-
|
55 |
img_vecs = np.asarray(img_vecs)
|
|
|
56 |
rv_indices, _ = furthest_neighbours(
|
57 |
img_vecs,
|
58 |
downsample_size,
|
59 |
seed=0)
|
60 |
indices = np.zeros((img_vecs.shape[0],))
|
61 |
indices[np.asarray(rv_indices)] = 1
|
|
|
62 |
|
63 |
global_ctr = 0
|
64 |
for fp_i, file_path in enumerate([input_file]):
|
@@ -69,6 +70,7 @@ def predict(input_file, downsample_size):
|
|
69 |
if indices[global_ctr] == 1:
|
70 |
cv2.imwrite(join(selected_directory, str(global_ctr) + ".jpg"), img)
|
71 |
global_ctr += 1
|
|
|
72 |
|
73 |
all_selected_imgs_path = [join(selected_directory, f) for f in os.listdir(selected_directory) if
|
74 |
isfile(join(selected_directory, f))]
|
@@ -77,6 +79,7 @@ def predict(input_file, downsample_size):
|
|
77 |
for i, f in enumerate(all_selected_imgs_path):
|
78 |
zipf.write(f, basename(f))
|
79 |
zipf.close()
|
|
|
80 |
|
81 |
return zip_path
|
82 |
|
@@ -87,4 +90,4 @@ demo = gr.Interface(
|
|
87 |
gr.inputs.Number(label="Downsample size")],
|
88 |
outputs=gr.outputs.File(label="Zip"))
|
89 |
|
90 |
-
demo.launch()
|
|
|
51 |
in_img = torch.from_numpy(in_img).float()
|
52 |
encoded = avg_pool(model(in_img))[0, :, 0, 0].cpu().numpy()
|
53 |
img_vecs += [encoded]
|
|
|
54 |
img_vecs = np.asarray(img_vecs)
|
55 |
+
print("images encoded")
|
56 |
rv_indices, _ = furthest_neighbours(
|
57 |
img_vecs,
|
58 |
downsample_size,
|
59 |
seed=0)
|
60 |
indices = np.zeros((img_vecs.shape[0],))
|
61 |
indices[np.asarray(rv_indices)] = 1
|
62 |
+
print("images selected")
|
63 |
|
64 |
global_ctr = 0
|
65 |
for fp_i, file_path in enumerate([input_file]):
|
|
|
70 |
if indices[global_ctr] == 1:
|
71 |
cv2.imwrite(join(selected_directory, str(global_ctr) + ".jpg"), img)
|
72 |
global_ctr += 1
|
73 |
+
print("selected images extracted")
|
74 |
|
75 |
all_selected_imgs_path = [join(selected_directory, f) for f in os.listdir(selected_directory) if
|
76 |
isfile(join(selected_directory, f))]
|
|
|
79 |
for i, f in enumerate(all_selected_imgs_path):
|
80 |
zipf.write(f, basename(f))
|
81 |
zipf.close()
|
82 |
+
print("selected images zipped")
|
83 |
|
84 |
return zip_path
|
85 |
|
|
|
90 |
gr.inputs.Number(label="Downsample size")],
|
91 |
outputs=gr.outputs.File(label="Zip"))
|
92 |
|
93 |
+
demo.launch(cache_examples=False)
|