-
Notifications
You must be signed in to change notification settings - Fork 0
/
gener_batch_mem_eco.py
60 lines (45 loc) · 1.27 KB
/
gener_batch_mem_eco.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
import random
from threading import Thread, RLock
from queue import Queue
import os
import time
import pandas as pd
import numpy as np
L = [f for f in os.listdir('./Dataset.csv') if f[:6] == 'attack']
frames=[]
for el in L :
frames.append(pd.read_csv('./Dataset.csv/'+el+''))
database = pd.concat(frames)
database.iloc[[i for i in range(len(database))],0]= [i for i in range(len(database))]
database =database.to_numpy()
batchs = Queue(100)
verrou = RLock()
def file_len(f):
i=0
for i, l in enumerate(f):
pass
f.seek(0,0)
return i + 1
def visit_line(line):
l=line[:-2].split(" ")
res = database.iloc[int(float(l[0])),:-1].to_numpy()
for i in range(1,len(l)):
res = np.vstack((res,database.iloc[int(float(l[i])), :-1]))
return res,(np.hstack((np.zeros(len(res)-1,dtype=int),int(database.iloc[int(float(l[-1])),-1]))))
def get_line(f, index):
for i, line in enumerate(f):
if i == index:
f.seek(0,0)
return visit_line(line)
def fit(tmp):
a,b=tmp
print(a.shape,b[-1])
def entrainement(file_name):
f = open(file_name)
l=[i for i in range(file_len(f))]
random.shuffle(l)
for line in l:
tmp = get_line(f, line)
fit(tmp)
f.close()
entrainement('sets/test_x')