Spaces:
Sleeping
Sleeping
Adding DT
Browse files
app.py
CHANGED
|
@@ -29,7 +29,6 @@ from LogisticRegresssion.LogisticRegression import LogReg
|
|
| 29 |
# "block_norm": "L2-Hys"
|
| 30 |
# }
|
| 31 |
# }
|
| 32 |
-
|
| 33 |
import pickle
|
| 34 |
with open("gnb_digit6_package.pkl" , "rb") as f:
|
| 35 |
package = pickle.load(f)
|
|
@@ -38,7 +37,7 @@ pca = package['pca']
|
|
| 38 |
best_weight = package['best_weight']
|
| 39 |
hog_params = package['hog_params']
|
| 40 |
|
| 41 |
-
def preprocess_image(image):
|
| 42 |
|
| 43 |
image = np.array(image)
|
| 44 |
#Normalize
|
|
@@ -47,6 +46,8 @@ def preprocess_image(image):
|
|
| 47 |
image_N,
|
| 48 |
**hog_params #Zay el ... fi el JS el spread
|
| 49 |
)
|
|
|
|
|
|
|
| 50 |
image_hog = image_hog.reshape(1, -1)
|
| 51 |
image_pca = pca.transform(image_hog)
|
| 52 |
return image_pca
|
|
@@ -103,6 +104,13 @@ def classify_with_logreg(image):
|
|
| 103 |
prediction = logreg_trained_model.predict(processed_image)
|
| 104 |
|
| 105 |
return "Target Detected: This is a 6!" if prediction[0] == 1 else "Not a 6."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
def predict_with_selected_model(image, model_choice):
|
| 108 |
if image is None:
|
|
@@ -112,6 +120,8 @@ def predict_with_selected_model(image, model_choice):
|
|
| 112 |
return classify_image(image)
|
| 113 |
elif model_choice == "Logistic Regression":
|
| 114 |
return classify_with_logreg(image)
|
|
|
|
|
|
|
| 115 |
else:
|
| 116 |
return "Unknown model selected."
|
| 117 |
|
|
@@ -124,7 +134,7 @@ demo = gr.Interface(
|
|
| 124 |
label="Upload Digit Image"
|
| 125 |
),
|
| 126 |
gr.Radio(
|
| 127 |
-
choices=["Gaussian Naive Bayes", "Logistic Regression"],
|
| 128 |
value="Gaussian Naive Bayes",
|
| 129 |
label="Choose Classifier"
|
| 130 |
)
|
|
|
|
| 29 |
# "block_norm": "L2-Hys"
|
| 30 |
# }
|
| 31 |
# }
|
|
|
|
| 32 |
import pickle
|
| 33 |
with open("gnb_digit6_package.pkl" , "rb") as f:
|
| 34 |
package = pickle.load(f)
|
|
|
|
| 37 |
best_weight = package['best_weight']
|
| 38 |
hog_params = package['hog_params']
|
| 39 |
|
| 40 |
+
def preprocess_image(image , model):
|
| 41 |
|
| 42 |
image = np.array(image)
|
| 43 |
#Normalize
|
|
|
|
| 46 |
image_N,
|
| 47 |
**hog_params #Zay el ... fi el JS el spread
|
| 48 |
)
|
| 49 |
+
if model == "DT":
|
| 50 |
+
return image_hog
|
| 51 |
image_hog = image_hog.reshape(1, -1)
|
| 52 |
image_pca = pca.transform(image_hog)
|
| 53 |
return image_pca
|
|
|
|
| 104 |
prediction = logreg_trained_model.predict(processed_image)
|
| 105 |
|
| 106 |
return "Target Detected: This is a 6!" if prediction[0] == 1 else "Not a 6."
|
| 107 |
+
def classify_with_DT(image):
|
| 108 |
+
if image is None:
|
| 109 |
+
return "Please upload an image."
|
| 110 |
+
processedImage = preprocess_image(image , "DT")
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
|
| 114 |
|
| 115 |
def predict_with_selected_model(image, model_choice):
|
| 116 |
if image is None:
|
|
|
|
| 120 |
return classify_image(image)
|
| 121 |
elif model_choice == "Logistic Regression":
|
| 122 |
return classify_with_logreg(image)
|
| 123 |
+
elif model_choice == "Decision Tree":
|
| 124 |
+
return classify_with_DT(image)
|
| 125 |
else:
|
| 126 |
return "Unknown model selected."
|
| 127 |
|
|
|
|
| 134 |
label="Upload Digit Image"
|
| 135 |
),
|
| 136 |
gr.Radio(
|
| 137 |
+
choices=["Gaussian Naive Bayes", "Logistic Regression" , "Decision Tree"],
|
| 138 |
value="Gaussian Naive Bayes",
|
| 139 |
label="Choose Classifier"
|
| 140 |
)
|