Spaces:
Runtime error
Runtime error
RRoundTable
commited on
Commit
•
b9901e2
1
Parent(s):
0e6d4e1
Use clip scaler
Browse files
app.py
CHANGED
@@ -36,6 +36,10 @@ imgs_tensor = torch.zeros(4, 3, patch_h * 14, patch_w * 14)
|
|
36 |
# PCA
|
37 |
pca = PCA(n_components=3)
|
38 |
|
|
|
|
|
|
|
|
|
39 |
def query_image(
|
40 |
img1, img2, img3, img4,
|
41 |
background_threshold,
|
@@ -57,7 +61,8 @@ def query_image(
|
|
57 |
# PCA Feature
|
58 |
pca.fit(features)
|
59 |
pca_features = pca.transform(features)
|
60 |
-
|
|
|
61 |
|
62 |
# Foreground/Background
|
63 |
if is_foreground_larger_than_threshold:
|
@@ -71,7 +76,8 @@ def query_image(
|
|
71 |
pca_features_rem = pca.transform(features[pca_features_fg])
|
72 |
|
73 |
# Min Max Normalization
|
74 |
-
|
|
|
75 |
|
76 |
pca_features_rgb = np.zeros((4 * patch_h * patch_w, 3))
|
77 |
pca_features_rgb[pca_features_bg] = 0
|
@@ -92,7 +98,7 @@ 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 |
"""
|
|
|
36 |
# PCA
|
37 |
pca = PCA(n_components=3)
|
38 |
|
39 |
+
# Min-Max Scaler
|
40 |
+
from sklearn.preprocessing import MinMaxScaler
|
41 |
+
scaler = MinMaxScaler(clip=True)
|
42 |
+
|
43 |
def query_image(
|
44 |
img1, img2, img3, img4,
|
45 |
background_threshold,
|
|
|
61 |
# PCA Feature
|
62 |
pca.fit(features)
|
63 |
pca_features = pca.transform(features)
|
64 |
+
scaler.fit(pca_features)
|
65 |
+
pca_feature = scaler.transform(pca_features)
|
66 |
|
67 |
# Foreground/Background
|
68 |
if is_foreground_larger_than_threshold:
|
|
|
76 |
pca_features_rem = pca.transform(features[pca_features_fg])
|
77 |
|
78 |
# Min Max Normalization
|
79 |
+
scaler.fit(pca_features_rem)
|
80 |
+
pca_features_rem = scaler.transform(pca_features_rem)
|
81 |
|
82 |
pca_features_rgb = np.zeros((4 * patch_h * patch_w, 3))
|
83 |
pca_features_rgb[pca_features_bg] = 0
|
|
|
98 |
1. Compute the features of patches from 4 images. We can get a feature that have (4 * patch_w * patch_h, feature_dim) shape.
|
99 |
2. PCA the feature with 3 dims. After PCA, Min-Max normalization is performed.
|
100 |
3. Use first component to split foreground and background. (threshold and checkbox)
|
101 |
+
4. All the feature of patches included in the background are set to 0.
|
102 |
5. PCA is performed based on the remaining features. Afer PCA, Min-Max normalization is performed.
|
103 |
6. Visualize
|
104 |
"""
|