added fcnn classifier

This commit is contained in:
wangobango 2021-11-28 17:33:52 +01:00
parent 3c48ee28f9
commit 8833430697
105 changed files with 49 additions and 1 deletions

5
.gitignore vendored
View File

@ -60,4 +60,7 @@ Thumbs.db.meta
*.DS_Store
# VS Code
*.vscode
*.vscode
data/*
venv/*

43
fcnn/main.py Normal file
View 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
View File

@ -0,0 +1,2 @@
opencv_python==4.5.4.60
scikit_learn==1.0.1

View File

Before

Width:  |  Height:  |  Size: 7.4 MiB

After

Width:  |  Height:  |  Size: 7.4 MiB

View File

Before

Width:  |  Height:  |  Size: 599 KiB

After

Width:  |  Height:  |  Size: 599 KiB

View File

Before

Width:  |  Height:  |  Size: 7.7 MiB

After

Width:  |  Height:  |  Size: 7.7 MiB

View File

Before

Width:  |  Height:  |  Size: 20 MiB

After

Width:  |  Height:  |  Size: 20 MiB

View File

Before

Width:  |  Height:  |  Size: 21 MiB

After

Width:  |  Height:  |  Size: 21 MiB

View File

Before

Width:  |  Height:  |  Size: 980 KiB

After

Width:  |  Height:  |  Size: 980 KiB

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

Before

Width:  |  Height:  |  Size: 524 KiB

After

Width:  |  Height:  |  Size: 524 KiB

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

Before

Width:  |  Height:  |  Size: 259 KiB

After

Width:  |  Height:  |  Size: 259 KiB

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 MiB

After

Width:  |  Height:  |  Size: 1.7 MiB

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 51 KiB

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Some files were not shown because too many files have changed in this diff Show More