Spaces:
Runtime error
Runtime error
RRoundTable
commited on
Commit
•
0e6d4e1
1
Parent(s):
5e1f859
refac and add more document
Browse files
app.py
CHANGED
@@ -71,8 +71,7 @@ def query_image(
|
|
71 |
pca_features_rem = pca.transform(features[pca_features_fg])
|
72 |
|
73 |
# Min Max Normalization
|
74 |
-
|
75 |
-
pca_features_rem[:, i] = (pca_features_rem[:, i] - pca_features_rem[:, i].min()) / (pca_features_rem[:, i].max() - pca_features_rem[:, i].min())
|
76 |
|
77 |
pca_features_rgb = np.zeros((4 * patch_h * patch_w, 3))
|
78 |
pca_features_rgb[pca_features_bg] = 0
|
@@ -82,7 +81,20 @@ def query_image(
|
|
82 |
return [pca_features_rgb[i] for i in range(4)]
|
83 |
|
84 |
description = """
|
85 |
-
DINOV2 PCA
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
"""
|
87 |
demo = gr.Interface(
|
88 |
query_image,
|
|
|
71 |
pca_features_rem = pca.transform(features[pca_features_fg])
|
72 |
|
73 |
# Min Max Normalization
|
74 |
+
pca_features_rem = sklearn.preprocessing.minmax_scale(pca_features_rem)
|
|
|
75 |
|
76 |
pca_features_rgb = np.zeros((4 * patch_h * patch_w, 3))
|
77 |
pca_features_rgb[pca_features_bg] = 0
|
|
|
81 |
return [pca_features_rgb[i] for i in range(4)]
|
82 |
|
83 |
description = """
|
84 |
+
DINOV2 PCA demo for <a href="https://arxiv.org/abs/2304.07193">DINOv2: Learning Robust Visual Features without Supervision(Figure 1)</a>
|
85 |
+
|
86 |
+
How to Use:
|
87 |
+
|
88 |
+
1. Enter 4 images that have clean background and similar object.
|
89 |
+
2. Edit threshold and checkbox to split background/foreground.
|
90 |
+
|
91 |
+
Method:
|
92 |
+
1. Compute the features of patches from 4 images. We can get a feature that have (4 * patch_w * patch_h, feature_dim) shape.
|
93 |
+
2. PCA the feature with 3 dims. After PCA, Min-Max normalization is performed.
|
94 |
+
3. Use first component to split foreground and background. (threshold and checkbox)
|
95 |
+
4. All the feature of patches included in the background are set to 0.=
|
96 |
+
5. PCA is performed based on the remaining features. Afer PCA, Min-Max normalization is performed.
|
97 |
+
6. Visualize
|
98 |
"""
|
99 |
demo = gr.Interface(
|
100 |
query_image,
|