amirTamer commited on
Commit
f779568
·
1 Parent(s): 397cb09

Tam ta3deel el pre-processing

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -2,8 +2,6 @@ import gradio as gr
2
  import numpy as np
3
  from skimage.feature import hog
4
  import cv2
5
- import sys
6
- sys.path.append('./SVM')
7
 
8
 
9
  # =========================
@@ -53,17 +51,28 @@ with open("svm.pkl", "rb") as f:
53
  with open("svmScaler.pkl", "rb") as f:
54
  svm_scaler = pickle.load(f)
55
 
56
- def preprocess_image(image , model="GNB"):
57
-
58
  image = np.array(image)
59
- #Normalize
 
 
 
 
 
60
  image_N = image / 255.0
 
61
  image_hog = hog(
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)
69
  return image_pca
 
2
  import numpy as np
3
  from skimage.feature import hog
4
  import cv2
 
 
5
 
6
 
7
  # =========================
 
51
  with open("svmScaler.pkl", "rb") as f:
52
  svm_scaler = pickle.load(f)
53
 
54
+ def preprocess_image(image, model="GNB"):
 
55
  image = np.array(image)
56
+
57
+ image = cv2.resize(image, (28, 28))
58
+
59
+ if np.mean(image) > 127:
60
+ image = cv2.bitwise_not(image)
61
+
62
  image_N = image / 255.0
63
+
64
  image_hog = hog(
65
+ image_N,
66
+ orientations=9,
67
+ pixels_per_cell=(4, 4),
68
+ cells_per_block=(2, 2),
69
+ block_norm="L2-Hys",
70
+ feature_vector=True
71
+ )
72
+
73
  if model == "DT" or model == "SVM":
74
  return image_hog
75
+
76
  image_hog = image_hog.reshape(1, -1)
77
  image_pca = pca.transform(image_hog)
78
  return image_pca