nnibras commited on
Commit
e5ff97c
·
verified ·
1 Parent(s): 8c785df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -14,9 +14,9 @@ from skimage.feature import local_binary_pattern
14
  def plot_features(features, title):
15
  plt.figure(figsize=(10, 6))
16
  for i, feature in enumerate(features.T): # Transpose to plot feature by feature
17
- plt.plot(feature, label=f"Feature {i+1}")
18
  plt.title(title)
19
- plt.legend()
20
  plt.show()
21
 
22
  # Define directories for grass and wood images
@@ -163,6 +163,10 @@ for train_index, test_index in kf.split(lbp_features):
163
  x_train, x_test = lbp_features[train_index], lbp_features[test_index]
164
  y_train, y_test = y[train_index], y[test_index]
165
 
 
 
 
 
166
  lbp_classifier.fit(x_train, y_train)
167
  y_pred = lbp_classifier.predict(x_test)
168
 
@@ -181,7 +185,7 @@ def classify_uploaded_image(image, algorithm):
181
  prediction = glcm_knn.predict(features)
182
  elif algorithm == "LBP":
183
  features = extract_lbp_features([image])
184
- prediction = lbp_knn.predict(features)
185
  else:
186
  raise ValueError(f"Algorithm '{algorithm}' is not recognized.")
187
 
 
14
  def plot_features(features, title):
15
  plt.figure(figsize=(10, 6))
16
  for i, feature in enumerate(features.T): # Transpose to plot feature by feature
17
+ plt.plot(feature) # Remove label if no legend is needed
18
  plt.title(title)
19
+ # plt.legend() # Removed the legend to avoid warning
20
  plt.show()
21
 
22
  # Define directories for grass and wood images
 
163
  x_train, x_test = lbp_features[train_index], lbp_features[test_index]
164
  y_train, y_test = y[train_index], y[test_index]
165
 
166
+ lbp_classifier = KNeighborsClassifier(
167
+ n_neighbors=lbp_grid_search.best_params_["n_neighbors"],
168
+ p=lbp_grid_search.best_params_["p"]
169
+ )
170
  lbp_classifier.fit(x_train, y_train)
171
  y_pred = lbp_classifier.predict(x_test)
172
 
 
185
  prediction = glcm_knn.predict(features)
186
  elif algorithm == "LBP":
187
  features = extract_lbp_features([image])
188
+ prediction = lbp_classifier.predict(features)
189
  else:
190
  raise ValueError(f"Algorithm '{algorithm}' is not recognized.")
191