Skip to content

Instantly share code, notes, and snippets.

@jurand71
Created November 16, 2022 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jurand71/989d64a50809ff8a7d7e1a45bcfdc9d0 to your computer and use it in GitHub Desktop.
Save jurand71/989d64a50809ff8a7d7e1a45bcfdc9d0 to your computer and use it in GitHub Desktop.
print("Klasyfikacja obrazu odpadu")
img = cv2.imread("VAL/O/O_14000.jpg")
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_pred = cv2.resize(img, (81, 81), interpolation=cv2.INTER_AREA)
img_pred = img_to_array(img_pred)
img_pred = img_pred/255
img_pred = np.reshape(img_pred, (1, img_pred.shape[0]*img_pred.shape[1]))
# Trenujemy klasyfikator
classifier2 = KNearestNeighbor()
classifier2.train(X_train, y_train)
dists2 = classifier2.compute_distances_no_loops(img_pred)
# Prognozujemy kategorię obrazu przy określonym k
y_test_pred = classifier2.predict_labels(dists2, k=76)
# Określenie rodzaju
labels = ["Organic", "Recyclable"]
print(labels[int(y_test_pred)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment