mirror of
https://github.com/3x4byte/StreetsignRecognition.git
synced 2026-03-21 21:25:06 +00:00
nupdated feature vectors | added functionality to specify number of training vectors
This commit is contained in:
@@ -27,14 +27,14 @@ def split_all_data(all_data_path: str, future_training_path: str, future_testing
|
||||
random.shuffle(training_data)
|
||||
random.shuffle(testing_data)
|
||||
with open(future_training_path, 'w') as csv_file:
|
||||
writer = csv.writer(csv_file, delimiter=";")
|
||||
writer.writerow(['filename','concept', 'vector'])
|
||||
writer = csv.writer(csv_file, delimiter=";", lineterminator="\n")
|
||||
writer.writerow(['brightness','filename','concept', 'vector'])
|
||||
for sing in training_data:
|
||||
writer.writerow(sing)
|
||||
|
||||
with open(future_testing_path, 'w') as csv_file:
|
||||
writer = csv.writer(csv_file, delimiter=";")
|
||||
writer.writerow(['filename','concept', 'vector'])
|
||||
writer = csv.writer(csv_file, delimiter=";", lineterminator="\n")
|
||||
writer.writerow(['brightness','filename','concept', 'vector'])
|
||||
for sing in testing_data:
|
||||
writer.writerow(sing)
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -37,7 +37,7 @@ class NeuralNetwork:
|
||||
|
||||
correct_amount = 0
|
||||
false_amount = 0
|
||||
for i in range(len(training_set)*30):
|
||||
for i in range(len(training_set)):
|
||||
fv_to_train = random.choice(training_set)
|
||||
classified_concept, correct = self.classify(fv_to_train)
|
||||
|
||||
|
||||
17
src/main.py
17
src/main.py
@@ -58,7 +58,7 @@ def decision_tree(training = os.path.abspath(os.path.join(__file__, "..", "train
|
||||
# print(f"classified {cnt_correct}/{cnt_data} correctly ({round(cnt_correct/cnt_data*100, 3)}%)")
|
||||
return [cnt_correct, cnt_data - cnt_correct, cnt_data] # richtig, falsch, amount of testing data
|
||||
|
||||
def neural_network(training = os.path.abspath(os.path.join(__file__, "..", "training.csv")), testing = os.path.abspath(os.path.join(__file__, "..", "testing.csv")), cycles = 3):
|
||||
def neural_network(training = os.path.abspath(os.path.join(__file__, "..", "training.csv")), testing = os.path.abspath(os.path.join(__file__, "..", "testing.csv")), num_training_vectors = 100):
|
||||
from classes.neural.network import NeuralNetwork
|
||||
from classes.neural.neuron import Neuron
|
||||
|
||||
@@ -66,11 +66,20 @@ def neural_network(training = os.path.abspath(os.path.join(__file__, "..", "trai
|
||||
with open(training, 'r') as csv_file:
|
||||
reader = csv.reader(csv_file, delimiter=";")
|
||||
next(reader)
|
||||
i = 0
|
||||
for row in reader:
|
||||
float_list = ast.literal_eval(row[2])
|
||||
i += 1
|
||||
if i > num_training_vectors:
|
||||
break
|
||||
|
||||
fv = FeatureVector(concept = Concept.identify_by_str(row[1].split(".")[1]), features_list = [element * 0.01 for element in float_list], loaded = True)
|
||||
float_list = ast.literal_eval(row[3])
|
||||
|
||||
fv = FeatureVector(concept = Concept.identify_by_str(row[2].split(".")[1]), features_list = [element * 0.01 for element in float_list], loaded = True)
|
||||
training_data.append(fv)
|
||||
|
||||
while len(training_data) < num_training_vectors:
|
||||
training_data += training_data
|
||||
training_data = training_data[:num_training_vectors+1]
|
||||
|
||||
nn = NeuralNetwork()
|
||||
nn.learn(training_data)
|
||||
@@ -82,7 +91,7 @@ def neural_network(training = os.path.abspath(os.path.join(__file__, "..", "trai
|
||||
next(reader)
|
||||
for row in reader:
|
||||
cnt_data += 1
|
||||
fv = FeatureVector(concept = Concept.identify_by_str(row[1].split(".")[1]), features_list = ast.literal_eval(row[2]), loaded = True)
|
||||
fv = FeatureVector(concept = Concept.identify_by_str(row[2].split(".")[1]), features_list = ast.literal_eval(row[3]), loaded = True)
|
||||
classified_concept, _ = nn.classify(fv)
|
||||
cnt_correct += 1 if fv.concept == classified_concept else 0
|
||||
# print(f"{fv.concept} was classified as {classified_concept}")
|
||||
|
||||
2087
src/testing.csv
2087
src/testing.csv
File diff suppressed because it is too large
Load Diff
8322
src/training.csv
8322
src/training.csv
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user