mirror of
https://github.com/3x4byte/StreetsignRecognition.git
synced 2025-12-21 09:25:52 +00:00
updated main
This commit is contained in:
65
src/main.py
65
src/main.py
@@ -99,21 +99,64 @@ def load_fv(path_to_training_data = os.path.abspath(os.path.join(__file__, "..",
|
||||
|
||||
return training_data
|
||||
|
||||
|
||||
from concurrent.futures import ProcessPoolExecutor
|
||||
output = os.path.abspath(os.path.join(__file__, "..", "output.csv"))
|
||||
def process_epoch(input, epoch, all_vectors):
|
||||
"""Function to process a single epoch."""
|
||||
l = []
|
||||
for i in range(0, 101):
|
||||
training_set = random.sample(all_vectors, input)
|
||||
testing_set_size = int(input*0.15) # 15% test daten
|
||||
testing_set = random.sample(list(set(all_vectors) - set(training_set)), testing_set_size)
|
||||
|
||||
# Replace `neural_network` with your actual function
|
||||
correct, false, ammount = neural_network(training_set, testing_set, epoch)
|
||||
#print(f"run {i} for epoch {epoch}: correct_percentage={(correct / ammount) * 100}%")
|
||||
l.append(false / ammount)
|
||||
|
||||
print(f"finished {input} | {epoch}")
|
||||
avg = np.mean(l)
|
||||
with open(output, 'a') as csv_file:
|
||||
writer = csv.writer(csv_file, delimiter=";", lineterminator="\n")
|
||||
writer.writerow([input, testing_set_size, epoch, avg, l])
|
||||
return avg
|
||||
|
||||
if __name__ == "__main__":
|
||||
all_vectors = load_fv()
|
||||
with open(output, 'w') as csv_file:
|
||||
writer =csv.writer(csv_file, delimiter=";", lineterminator="\n")
|
||||
writer.writerow(["num_train_vectors", "num_test_vectors","num_epochs", "epochs_avg", "epochs_results"])
|
||||
|
||||
for input in range(40000, len(all_vectors), 400):
|
||||
for input in range(1000, int(len(all_vectors)*0.85), 5000):
|
||||
inp_res = []
|
||||
for epoch in range(10, 1000, 10):
|
||||
l = []
|
||||
for test in range(0, 1):
|
||||
training_set = random.sample(all_vectors, input)
|
||||
testing_set = list(set(all_vectors)-set(training_set))
|
||||
# Use ProcessPoolExecutor for parallelism
|
||||
with ProcessPoolExecutor(max_workers=12) as executor:
|
||||
# Submit tasks for parallel execution
|
||||
futures = [
|
||||
executor.submit(process_epoch, input, epoch, all_vectors)
|
||||
for epoch in range(1, 21, 1)
|
||||
]
|
||||
# Collect results as they complete
|
||||
for future in futures:
|
||||
inp_res.append(future.result())
|
||||
|
||||
# print(f"Start for {input} trainingsdata and test number {test} with epoch {epoch}")
|
||||
correct, false, ammount = neural_network(training_set, testing_set, epoch)
|
||||
print(f"Epoch {epoch}: correct_percentage={(correct/ammount)*100}%")
|
||||
l.append(false/ammount)
|
||||
# if __name__ == "__main__":
|
||||
# all_vectors = load_fv()
|
||||
|
||||
inp_res.append(np.mean(l))
|
||||
# for input in range(40000, len(all_vectors), 400):
|
||||
# inp_res = []
|
||||
# for epoch in range(10, 1000, 10):
|
||||
# l = []
|
||||
# multiprocessing.Process
|
||||
# for test in range(0, 1):
|
||||
# training_set = random.sample(all_vectors, input)
|
||||
# testing_set = list(set(all_vectors)-set(training_set))
|
||||
|
||||
# # print(f"Start for {input} trainingsdata and test number {test} with epoch {epoch}")
|
||||
# correct, false, ammount = neural_network(training_set, testing_set, epoch)
|
||||
# print(f"Epoch {epoch}: correct_percentage={(correct/ammount)*100}%")
|
||||
# l.append(false/ammount)
|
||||
|
||||
# inp_res.append(np.mean(l))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user