-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomanda_principal.py
106 lines (81 loc) · 3.84 KB
/
comanda_principal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
import glob
import shlex
import subprocess
import concurrent.futures
from itertools import product
# limpa_arquivos_csv = []
# caminhos = [ 'NIID', 'IID']
# for caminho in caminhos:
# padroes = [
# f'TESTES/{caminho}/LABELS/*.csv',
# f'TESTES/{caminho}/LOG_EVALUATE/*.csv',
# f'TESTES/{caminho}/LOG_ACERTOS/*.csv',
# f'TESTES/{caminho}/LOG_ACERTOS/GRAFICOS/*.png',
# f'TESTES/{caminho}/GRAFICOS/*.png',
# f'TESTES/{caminho}/GRADIENTES/*/*.csv',
# ]
# for i in padroes:
# limpa_arquivos_csv.extend(glob.glob(i))
arquivos_teste = ['simulacao_principal.py']
def executar_arquivo(arquivo):
try:
num_round = [2]
total_clients = [10]
modelos = ['DNN']
niid_iid = ['IID']
ataques = ['INVERTE_TREINANDO']
data_set = ['MNIST']
alpha_dirichlet = [0.0]
noise_gaussiano = [0.0]
round_inicio = [1]
per_cents_atacantes = [40]
combinacoes_unicas = set()
# try:
# for arquivo in limpa_arquivos_csv:
# os.remove(arquivo)
# except OSError as e:
# print(f'Erro ao limpar arquivo: {e}')
for i, j, k, l, m, n, o, p, q, r in product(niid_iid, ataques, data_set, modelos, round_inicio, per_cents_atacantes, noise_gaussiano, alpha_dirichlet, num_round, total_clients):
combinacao = (i, j, k, l, m, n, o, p, q, r)
if i == 'NIID' and p == 0:
continue
elif i == 'IID' and p > 0:
continue
elif j != 'RUIDO_GAUSSIANO' and o > 0:
continue
elif j == 'RUIDO_GAUSSIANO' and o != 0:
continue
elif (k == 'MNIST' and l == 'CNN') or (k == 'CIFAR10' and l == 'DNN'):
continue
else:
if combinacao not in combinacoes_unicas:
combinacoes_unicas.add(combinacao)
print(f'Executando {arquivo}')
comando = f'python3 {arquivo} --iid_niid {i} --modo_ataque {j} --dataset {k} --modelo_definido {l} --round_inicio {m} --per_cents_atacantes {n} --noise_gaussiano {o} --alpha_dirichlet {p} --num_rounds {q} --total_clients {r}'
print(f'\n\n################################################################################################')
print(f'\n\n{comando}\n\n')
print(f'################################################################################################\n\n')
subprocess.run(shlex.split(comando), check=True)
print(f'Executou com sucesso: {arquivo}')
except subprocess.CalledProcessError as e:
print(f'Erro ao executar o arquivo: {e}')
except Exception as e:
print(f'Erro inesperado: {e}')
def processar_dados(arquivos):
for arquivo in arquivos:
try:
subprocess.run(['python3', arquivo], check=True)
except subprocess.CalledProcessError as e:
print(f"Erro ao executar {arquivo}: {e}")
max_threads = 1
with concurrent.futures.ThreadPoolExecutor(max_threads) as executor:
resultados = list(executor.map(executar_arquivo, arquivos_teste))
def processar_graficos(arquivos):
for arquivo in arquivos:
try:
subprocess.run(['python3', arquivo], check=True)
except subprocess.CalledProcessError as e:
print(f"Erro ao executar {arquivo}: {e}")
gera_graficos = ['ferramentas/retira_caracter_nome.py','ferramentas/matriz_confusao.py', 'ferramentas/Visualizacao_em_grupo.py','ferramentas/gera_grafico_niid.py','ferramentas/gera_tabela.py','ferramentas/mede_similaridade.py']
# processar_dados(gera_graficos)