added fcnn classifier
5
.gitignore
vendored
@ -60,4 +60,7 @@ Thumbs.db.meta
|
|||||||
*.DS_Store
|
*.DS_Store
|
||||||
|
|
||||||
# VS Code
|
# VS Code
|
||||||
*.vscode
|
*.vscode
|
||||||
|
|
||||||
|
data/*
|
||||||
|
venv/*
|
43
fcnn/main.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import os
|
||||||
|
import cv2
|
||||||
|
from sklearn.neural_network import MLPClassifier
|
||||||
|
from sklearn.model_selection import train_test_split
|
||||||
|
from sklearn.metrics import classification_report
|
||||||
|
|
||||||
|
def preprocess(img):
|
||||||
|
scale_percent = 15
|
||||||
|
width = int(img.shape[1] * scale_percent / 100)
|
||||||
|
height = int(img.shape[0] * scale_percent / 100)
|
||||||
|
dim = (width, height)
|
||||||
|
resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
|
||||||
|
resized = resized.flatten()
|
||||||
|
return resized
|
||||||
|
|
||||||
|
def readData(data_links):
|
||||||
|
x, y = [], []
|
||||||
|
for link in data_links:
|
||||||
|
img = cv2.imread(link, cv2.IMREAD_GRAYSCALE)
|
||||||
|
img = preprocess(img)
|
||||||
|
label = link.split("/")[1].split('_')[1]
|
||||||
|
x.append(img)
|
||||||
|
y.append(label)
|
||||||
|
|
||||||
|
return x, y
|
||||||
|
|
||||||
|
data_links = os.listdir("data/")
|
||||||
|
data_links = ["data/" + x for x in data_links]
|
||||||
|
|
||||||
|
x, y = readData(data_links)
|
||||||
|
|
||||||
|
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=42)
|
||||||
|
|
||||||
|
clf = MLPClassifier(solver='adam', alpha=1e-5, hidden_layer_sizes=(1000, 500, 500), random_state=1,
|
||||||
|
activation='relu', batch_size='auto', shuffle=True, verbose=True)
|
||||||
|
clf.fit(X_train, y_train)
|
||||||
|
|
||||||
|
print("Score:")
|
||||||
|
print(clf.score(X_test, y_test))
|
||||||
|
|
||||||
|
print("Summary:")
|
||||||
|
Y_pred = clf.predict(X_test)
|
||||||
|
print(classification_report(y_test, Y_pred))
|
2
fcnn/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
opencv_python==4.5.4.60
|
||||||
|
scikit_learn==1.0.1
|
Before Width: | Height: | Size: 7.4 MiB After Width: | Height: | Size: 7.4 MiB |
Before Width: | Height: | Size: 599 KiB After Width: | Height: | Size: 599 KiB |
Before Width: | Height: | Size: 7.7 MiB After Width: | Height: | Size: 7.7 MiB |
Before Width: | Height: | Size: 20 MiB After Width: | Height: | Size: 20 MiB |
Before Width: | Height: | Size: 21 MiB After Width: | Height: | Size: 21 MiB |
Before Width: | Height: | Size: 980 KiB After Width: | Height: | Size: 980 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 524 KiB After Width: | Height: | Size: 524 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 259 KiB After Width: | Height: | Size: 259 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 1.7 MiB After Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |