Spaces:
Sleeping
Sleeping
SVM
Browse files
app.py
CHANGED
|
@@ -62,7 +62,7 @@ def preprocess_image(image , model="GNB"):
|
|
| 62 |
image_N,
|
| 63 |
**hog_params #Zay el ... fi el JS el spread
|
| 64 |
)
|
| 65 |
-
if model == "DT":
|
| 66 |
return image_hog
|
| 67 |
image_hog = image_hog.reshape(1, -1)
|
| 68 |
image_pca = pca.transform(image_hog)
|
|
@@ -126,22 +126,26 @@ def classify_with_DT(image):
|
|
| 126 |
|
| 127 |
|
| 128 |
def classify_with_SVM(image):
|
| 129 |
-
if len(image.shape) == 3:
|
| 130 |
-
|
| 131 |
|
| 132 |
-
image = cv2.resize(image, (28, 28))
|
| 133 |
|
| 134 |
|
| 135 |
-
if np.mean(image) > 127:
|
| 136 |
-
|
| 137 |
|
| 138 |
|
| 139 |
-
image = image.reshape(1, -1)
|
| 140 |
-
scaled_img = svm_scaler.transform(image)
|
| 141 |
|
| 142 |
-
prediction = svm_model.predict(scaled_img)
|
| 143 |
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
|
| 147 |
|
|
|
|
| 62 |
image_N,
|
| 63 |
**hog_params #Zay el ... fi el JS el spread
|
| 64 |
)
|
| 65 |
+
if model == "DT" or model == "SVM":
|
| 66 |
return image_hog
|
| 67 |
image_hog = image_hog.reshape(1, -1)
|
| 68 |
image_pca = pca.transform(image_hog)
|
|
|
|
| 126 |
|
| 127 |
|
| 128 |
def classify_with_SVM(image):
|
| 129 |
+
# if len(image.shape) == 3:
|
| 130 |
+
# image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 131 |
|
| 132 |
+
# image = cv2.resize(image, (28, 28))
|
| 133 |
|
| 134 |
|
| 135 |
+
# if np.mean(image) > 127:
|
| 136 |
+
# image = cv2.bitwise_not(image)
|
| 137 |
|
| 138 |
|
| 139 |
+
# image = image.reshape(1, -1)
|
| 140 |
+
# scaled_img = svm_scaler.transform(image)
|
| 141 |
|
|
|
|
| 142 |
|
| 143 |
+
if image is None:
|
| 144 |
+
return "Please upload an image."
|
| 145 |
+
processedImage = preprocess_image(image , "SVM")
|
| 146 |
+
processedImage = processedImage.reshape(1, -1)
|
| 147 |
+
result = svm_model.predict(processedImage)
|
| 148 |
+
return "Target Detected: This is a 6!" if result[0] == 1 else "Not a 6."
|
| 149 |
|
| 150 |
|
| 151 |
|