-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcnn.py
53 lines (44 loc) · 1.27 KB
/
cnn.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
import cPickle
import numpy as np
from numpy import zeros, newaxis
def loadRadio():
radioml = cPickle.load(open("2016.04C.multisnr.pkl",'rb'))
data = {}
allm = []
for k in radioml.keys():
data[k[0]] = {}
allm.append(k[0])
mod = sorted(set(allm))
for m in mod:
dat = []
for k in radioml.keys():
if k[0] == m :
for sig in range(len(radioml[k])):
a = np.array(radioml[k][sig][0])[:, newaxis]
b = np.array(radioml[k][sig][1])[:, newaxis]
if k[1] not in data[k[0]]:
data[k[0]][k[1]] = []
data[k[0]][k[1]].append([a,b])
X = []
Y = []
x = {}
y = {}
mval = {}
count = 0
for m in mod:
z = np.zeros((len(mod),))
z[count] = 1
mval[m] = z
for snr in data[m]:
dat = data[m][snr]
for d in dat[:int(len(dat)//1.5)]:
X.append(d)
Y.append(z)
for d in dat[int(len(dat)//1.5):]:
if not snr in x:
x[snr] = []
y[snr] = []
x[snr].append(d)
y[snr].append(z)
count += 1
return X,Y,x,y,mod