text_plain_output_1.png
from keras.layers import Dense

from keras.layers.core import Reshape, Flatten, Dropout

from keras.models import Sequential

from sklearn.preprocessing import normalize

import numpy as np

import pickle

file = open('/kaggle/input/rml2016/RML2016.10b.dat', 'rb')

Xd = pickle.load(file, encoding='bytes')

snrs, mods = map(lambda j: sorted(list(set(map(lambda x: x[j], Xd.keys())))), [1, 0])
X = []
lbl = []
for mod in mods:
    for snr in snrs:
        X.append(Xd[mod, snr])
        for i in range(Xd[mod, snr].shape[0]):
            lbl.append((mod, snr))
X = np.vstack(X)
file.close()

features = {}
features['raw'] = (X[:, 0], X[:, 1])
features['derivative'] = (normalize(np.gradient(X[:, 0], axis=1)), normalize(np.gradient(X[:, 1], axis=1)))
features['integral'] = (normalize(np.cumsum(X[:, 0], axis=1)), normalize(np.cumsum(X[:, 1], axis=1)))

def extract_features(*arguments):
    desired = ()
    for arg in arguments:
        desired += features[arg]
    return np.stack(desired, axis=1)

data = extract_features('raw')
labels = np.array(lbl)

in_shape = data[0].shape
out_shape = tuple([1]) + in_shape

model = Sequential()
model.add(Dense(128, activation='relu', input_shape=in_shape))
model.add(Dense(256, activation='relu'))
model.add(Dense(128, activation='relu'))
model.add(Flatten())
model.add(Dense(10, activation='softmax'))

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
model.summary()