├── HisarMod ├── CGDNN │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── CGDNN.py ├── CLDNN │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── CLDNNLikeModel.py ├── CLDNN2 │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── CLDNNLikeModel.py ├── CNN1 │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── CNN2Model.py ├── CNN2 │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── CNN.py ├── DAE │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ ├── DAE.py │ │ └── __pycache__ │ │ └── CuDNNLSTMModel.cpython-36.pyc ├── DenseNet │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ ├── DenseNet.py │ │ └── __pycache__ │ │ └── SCCLSTM.cpython-36.pyc ├── GRU2 │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── GRUModel.py ├── IC-AMCNet │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── ICAMC.py ├── LSTM2 │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── CuDNNLSTMModel.py ├── MCLDNN │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── MCLDNN.py ├── MCNET │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── MCLDNN.py ├── PET-CGDNN │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── PETCGDNN.py └── ResNet │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ └── ResNet.py ├── README.md ├── RML201610a ├── 1DCNN-PF │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── DCNNPF.py ├── CGDNet │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ ├── CGDNN.py │ │ └── __pycache__ │ │ ├── CENET.cpython-36.pyc │ │ ├── CGDNN.cpython-36.pyc │ │ ├── CLDNN.cpython-36.pyc │ │ ├── CLDNN1.cpython-36.pyc │ │ ├── CM.cpython-36.pyc │ │ ├── MCLDNN.cpython-36.pyc │ │ ├── SCCLSTM.cpython-36.pyc │ │ └── TSDNN.cpython-36.pyc ├── CLDNN │ ├── main.py │ ├── mltools.py │ ├── rmldataset2016.py │ └── rmlmodels │ │ └── CLDNNLikeModel.py ├── CLDNN2 │ ├── main.py │ ├── mltools.py │ ├── rmldataset2016.py │ └── rmlmodels │ │ └── CLDNNLikeModel.py ├── CNN1 │ ├── main.py │ ├── mltools.py │ ├── rmldataset2016.py │ └── rmlmodels │ │ └── CNN2Model.py ├── CNN2 │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── CNN2.py ├── DAE │ ├── main.py │ ├── mltools.py │ ├── rmldataset2016.py │ └── rmlmodels │ │ ├── DAE.py │ │ └── __pycache__ │ │ └── CuDNNLSTMModel.cpython-36.pyc ├── DenseNet │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── DenseNet.py ├── GRU2 │ ├── main.py │ ├── mltools.py │ ├── rmldataset2016.py │ └── rmlmodels │ │ └── GRUModel.py ├── IC-AMCNet │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── ICAMC.py ├── LSTM2 │ ├── main.py │ ├── mltools.py │ ├── rmldataset2016.py │ └── rmlmodels │ │ ├── CuDNNLSTMModel.py │ │ └── __pycache__ │ │ └── CuDNNLSTMModel.cpython-36.pyc ├── MCLDNN │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── MCLDNN.py ├── MCNET │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ ├── MCNET.py │ │ └── __pycache__ │ │ ├── MCNET.cpython-36.pyc │ │ └── SCCLSTM.cpython-36.pyc ├── PET-CGDNN │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── PETCGDNN.py └── ResNet │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ └── ResNet.py ├── RML201610b ├── 1DCNN-PF │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ ├── DCNNPF.py │ │ └── __pycache__ │ │ └── SCCLSTM.cpython-36.pyc ├── CGDNet │ ├── main.py │ ├── mltools.py │ ├── rmldataset2016.py │ └── rmlmodels │ │ ├── CGDNN.py │ │ └── __pycache__ │ │ └── CGDNN.cpython-36.pyc ├── CLDNN │ ├── main.py │ ├── mltools.py │ ├── rmldataset2016.py │ └── rmlmodels │ │ └── CLDNNLikeModel.py ├── CLDNN2 │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── CLDNN.py ├── CNN1 │ ├── main.py │ ├── mltools.py │ ├── rmldataset2016.py │ └── rmlmodels │ │ └── CNN2Model.py ├── CNN2 │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── CNN.py ├── DAE │ ├── main.py │ ├── mltools.py │ ├── rmldataset2016.py │ └── rmlmodels │ │ └── DAE.py ├── DenseNet │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── DenseNet.py ├── GRU2 │ ├── main.py │ ├── mltools.py │ ├── rmldataset2016.py │ └── rmlmodels │ │ └── GRUModel.py ├── IC-AMCNET │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── ICAMC.py ├── LSTM2 │ ├── main.py │ ├── rmldataset2016.py │ └── rmlmodels │ │ └── CuDNNLSTMModel.py ├── MCLDNN │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ │ └── MCLDNN.py ├── MCNET │ ├── main.py │ ├── mltools.py │ ├── rmldataset2016.py │ └── rmlmodels │ │ └── MCNET.py ├── PET-CGDNN │ ├── main.py │ ├── mltools.py │ ├── rmldataset2016.py │ └── rmlmodels │ │ └── PETCGDNN.py └── ResNet │ ├── dataset2016.py │ ├── main.py │ ├── mltools.py │ └── rmlmodels │ └── ResNet.py └── RML2018 ├── 1DCNN-PF ├── main.py ├── mltools.py └── rmlmodels │ └── DCNNPF.py ├── CGDNet ├── main.py ├── mltools.py └── rmlmodels │ └── CGDNN.py ├── CLDNN ├── main.py ├── mltools.py └── rmlmodels │ └── CLDNNLikeModel.py ├── CLDNN2 ├── main.py ├── mltools.py └── rmlmodels │ └── CLDNNLikeModel.py ├── CNN1 ├── main.py ├── mltools.py └── rmlmodels │ └── CNN2Model.py ├── CNN2 ├── dataset2016.py ├── main.py ├── mltools.py └── rmlmodels │ └── CNN.py ├── DAE ├── main.py ├── mltools.py └── rmlmodels │ ├── DAE.py │ └── __pycache__ │ └── CuDNNLSTMModel.cpython-36.pyc ├── DenseNet ├── main.py ├── mltools.py └── rmlmodels │ └── DenseNet.py ├── GRU2 ├── main.py ├── mltools.py └── rmlmodels │ └── GRUModel.py ├── IC-AMCNet ├── main.py ├── mltools.py └── rmlmodels │ └── ICAMC.py ├── LSTM2 ├── main.py ├── mltools.py └── rmlmodels │ └── CuDNNLSTMModel.py ├── MCLDNN ├── dataset2016.py ├── main.py ├── mltools.py └── rmlmodels │ └── MCLDNN.py ├── MCNET ├── main.py ├── mltools.py └── rmlmodels │ └── MCNET.py ├── PET-CGDNN ├── main.py ├── mltools.py └── rmlmodels │ ├── PETCGDNN.py │ └── __pycache__ │ └── SCCLSTM.cpython-36.pyc ├── ResNet ├── main.py ├── mltools.py └── rmlmodels │ └── ResNet.py └── SubsampleRML2018.py /HisarMod/CGDNN/rmlmodels/CGDNN.py: -------------------------------------------------------------------------------- 1 | import os 2 | import tensorflow as tf 3 | WEIGHTS_PATH = ('resnet_like_weights_tf_dim_ordering_tf_kernels.h5') 4 | import math 5 | from keras.models import Model 6 | from keras.layers import Input, Dense, Conv1D, MaxPool1D, ReLU, Dropout, Softmax, concatenate, Flatten, Reshape, \ 7 | GaussianNoise,GaussianDropout 8 | from keras.layers.convolutional import Conv2D 9 | from keras.layers import CuDNNLSTM,Lambda,Multiply,Add,Subtract,MaxPool2D,CuDNNGRU,LeakyReLU,BatchNormalization 10 | import tensorflow as tf 11 | 12 | 13 | def CGDNN(weights=None, 14 | input_shape=[1, 2, 1024], 15 | classes=26, 16 | **kwargs): 17 | if weights is not None and not (os.path.exists(weights)): 18 | raise ValueError('The `weights` argument should be either ' 19 | '`None` (random initialization), ' 20 | 'or the path to the weights file to be loaded.') 21 | 22 | dr = 0.2 # dropout rate (%) 23 | input = Input(input_shape, name='input1') 24 | x1 = Conv2D(50, (1, 6), activation='relu', kernel_initializer='lecun_uniform', data_format="channels_first")(input) 25 | x1 = MaxPool2D(pool_size=(2, 2), strides=1, padding='same', data_format="channels_first")(x1) 26 | x1 = GaussianDropout(dr)(x1) 27 | x2 = Conv2D(50, (1, 6), activation='relu', kernel_initializer='glorot_uniform', data_format="channels_first")(x1) 28 | x2 = MaxPool2D(pool_size=(2, 2), strides=1, padding='same', data_format="channels_first")(x2) 29 | x2 = GaussianDropout(dr)(x2) 30 | x3 = Conv2D(50, (1, 6), activation='relu', kernel_initializer='glorot_uniform', data_format="channels_first")(x2) 31 | x3 = MaxPool2D(pool_size=(2, 2), strides=1, padding='same', data_format="channels_first")(x3) 32 | x3 = GaussianDropout(dr)(x3) 33 | x11 = concatenate([x1, x3], 3) 34 | x4 = Reshape(target_shape=((50, 4056)), name='reshape4')(x11) 35 | x4 = CuDNNGRU(units=50)(x4) 36 | x4 = GaussianDropout(dr)(x4) 37 | x = Dense(256, activation='relu', name='fc4',kernel_initializer='he_normal')(x4) 38 | x = GaussianDropout(dr)(x) 39 | x = Dense(classes, activation='softmax', name='softmax')(x) 40 | model = Model(inputs=input, outputs=x) 41 | 42 | # Load weights. 43 | if weights is not None: 44 | model.load_weights(weights) 45 | 46 | return model 47 | 48 | 49 | import keras 50 | from keras.utils.vis_utils import plot_model 51 | 52 | if __name__ == '__main__': 53 | model = CGDNN(None, classes=10) 54 | 55 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 56 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 57 | plot_model(model, to_file='model.png', show_shapes=True) # print model 58 | print('models layers:', model.layers) 59 | print('models config:', model.get_config()) 60 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /HisarMod/CLDNN/rmlmodels/CLDNNLikeModel.py: -------------------------------------------------------------------------------- 1 | import os 2 | import numpy as np 3 | 4 | from keras.models import Model 5 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,concatenate,Conv2D 6 | from keras.layers import LSTM,Permute,Reshape,ZeroPadding2D,Activation 7 | 8 | 9 | 10 | 11 | def CLDNNLikeModel(weights=None, 12 | input_shape1=[2,1024], 13 | classes=26, 14 | **kwargs): 15 | if weights is not None and not (os.path.exists(weights)): 16 | raise ValueError('The `weights` argument should be either ' 17 | '`None` (random initialization), ' 18 | 'or the path to the weights file to be loaded.') 19 | 20 | # %% 21 | dr = 0.5 22 | input_x = Input(shape=(1, 2, 1024)) 23 | 24 | input_x_padding = ZeroPadding2D((0, 2), data_format="channels_first")(input_x) 25 | 26 | layer11 = Conv2D(50, (1, 8), padding='valid', activation="relu", name="conv11", init='glorot_uniform', 27 | data_format="channels_first")(input_x_padding) 28 | layer11 = Dropout(dr)(layer11) 29 | 30 | layer11_padding = ZeroPadding2D((0, 2), data_format="channels_first")(layer11) 31 | layer12 = Conv2D(50, (1, 8), padding="valid", activation="relu", name="conv12", init='glorot_uniform', 32 | data_format="channels_first")(layer11_padding) 33 | layer12 = Dropout(dr)(layer12) 34 | 35 | layer12 = ZeroPadding2D((0, 2), data_format="channels_first")(layer12) 36 | layer13 = Conv2D(50, (1, 8), padding='valid', activation="relu", name="conv13", init='glorot_uniform', 37 | data_format="channels_first")(layer12) 38 | layer13 = Dropout(dr)(layer13) 39 | 40 | concat = keras.layers.concatenate([layer11, layer13]) 41 | concat_size = list(np.shape(concat)) 42 | input_dim = int(concat_size[-1] * concat_size[-2]) 43 | timesteps = int(concat_size[-3]) 44 | concat = Reshape((timesteps, input_dim))(concat) 45 | # 形如(samples,timesteps,input_dim)的3D张量 46 | lstm_out = LSTM(50, input_dim=input_dim, input_length=timesteps)(concat) 47 | layer_dense1 = Dense(256, activation='relu', init='he_normal', name="dense1")(lstm_out) 48 | layer_dropout = Dropout(dr)(layer_dense1) 49 | layer_dense2 = Dense(26, init='he_normal', name="dense2")(layer_dropout) 50 | layer_softmax = Activation('softmax')(layer_dense2) 51 | output = Reshape([26])(layer_softmax) 52 | 53 | model = Model(inputs=input_x, outputs=output) 54 | 55 | # Load weights. 56 | if weights is not None: 57 | model.load_weights(weights) 58 | 59 | return model 60 | 61 | import keras 62 | if __name__ == '__main__': 63 | model = CLDNNLikeModel(None,input_shape=(2,1024),classes=24) 64 | 65 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 66 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 67 | 68 | print('models layers:', model.layers) 69 | print('models config:', model.get_config()) 70 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /HisarMod/CLDNN2/rmlmodels/CLDNNLikeModel.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | import numpy as np 11 | 12 | from keras.models import Model 13 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,concatenate,Conv2D 14 | from keras.layers import LSTM,Permute,Reshape,ZeroPadding2D,Activation 15 | 16 | 17 | 18 | 19 | def CLDNNLikeModel(weights=None, 20 | input_shape1=[2,1024], 21 | classes=26, 22 | **kwargs): 23 | if weights is not None and not (os.path.exists(weights)): 24 | raise ValueError('The `weights` argument should be either ' 25 | '`None` (random initialization), ' 26 | 'or the path to the weights file to be loaded.') 27 | 28 | # %% 29 | dr = 0.5 30 | input_x = Input(input_shape1+[1],name='input') 31 | 32 | x = Conv2D(256, (1, 3), activation="relu", name="conv1", init='glorot_uniform')(input_x) # (b,c,h,w) (b,h,w,c) 33 | x = Dropout(dr)(x) 34 | x = Conv2D(256, (2, 3), activation="relu", name="conv2", init='glorot_uniform')(x) # (b,c,h,w) (b,h,w,c) 35 | x = Dropout(dr)(x) 36 | x = Conv2D(80, (1, 3), activation="relu", name="conv3", init='glorot_uniform')(x) # (b,c,h,w) (b,h,w,c) 37 | x = Dropout(dr)(x) 38 | x = Conv2D(80, (1, 3), activation="relu", name="conv4", init='glorot_uniform')(x) # (b,c,h,w) (b,h,w,c) 39 | x = Dropout(dr)(x) 40 | x1 = Reshape((80, 1016))(x) 41 | lstm_out = LSTM(units=50)(x1) 42 | 43 | # layer_Flatten = Flatten()(lstm_out) 44 | x = Dense(128, activation='relu', name="dense1")(lstm_out) 45 | x = Dropout(dr)(x) 46 | output = Dense(26, activation='softmax',name="dense2")(x) 47 | 48 | model = Model(inputs=input_x, outputs=output) 49 | 50 | # Load weights. 51 | if weights is not None: 52 | model.load_weights(weights) 53 | 54 | return model 55 | 56 | import keras 57 | if __name__ == '__main__': 58 | model = CLDNNLikeModel(None,input_shape=(2,1024),classes=24) 59 | 60 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 61 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 62 | 63 | print('models layers:', model.layers) 64 | print('models config:', model.get_config()) 65 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /HisarMod/CNN1/rmlmodels/CNN2Model.py: -------------------------------------------------------------------------------- 1 | import os 2 | os.environ["KERAS_BACKEND"] = "tensorflow" 3 | # os.environ["THEANO_FLAGS"] = "device=gpu%d"%(0) 4 | import numpy as np 5 | import keras.models as models 6 | from keras.layers.core import Reshape,Dense,Dropout,Activation,Flatten 7 | from keras.layers.convolutional import Convolution2D,Conv2D, MaxPooling2D, ZeroPadding2D 8 | from keras.layers.core import Activation 9 | from keras.layers import Input, Dense, Conv1D, MaxPool1D, ReLU, Dropout, Softmax, concatenate, Flatten, Reshape, \ 10 | GaussianNoise,Activation,GaussianDropout 11 | from keras.models import Model 12 | 13 | 14 | def CNN2Model(weights=None, 15 | input_shape=[2,1024], 16 | classes=26, 17 | **kwargs): 18 | if weights is not None and not (os.path.exists(weights)): 19 | raise ValueError('The `weights` argument should be either ' 20 | '`None` (random initialization), ' 21 | 'or the path to the weights file to be loaded.') 22 | dr = 0.5 23 | input = Input(input_shape + [1], name='input1') 24 | 25 | x = Conv2D(50, (1, 8), padding='same', activation="relu", name="conv1", kernel_initializer='glorot_uniform')(input) 26 | x = Dropout(dr)(x) 27 | x = Conv2D(50, (2, 8), padding="valid", activation="relu", name="conv2", kernel_initializer='glorot_uniform')(x) 28 | x = Dropout(dr)(x) 29 | x = Flatten()(x) 30 | x = Dense(256, activation='relu', kernel_initializer='he_normal', name="dense1")(x) 31 | x = Dropout(dr)(x) 32 | x = Dense(classes, activation='softmax', name='softmax')(x) 33 | model = Model(inputs=input, outputs=x) 34 | 35 | # Load weights. 36 | if weights is not None: 37 | model.load_weights(weights) 38 | 39 | return model 40 | 41 | if __name__ == '__main__': 42 | print(CNN2Model().summary()) 43 | -------------------------------------------------------------------------------- /HisarMod/CNN2/rmlmodels/CNN.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | from keras.models import Model 12 | from keras.layers import Input,Dense,ReLU,Dropout,Softmax,Conv2D,MaxPool2D 13 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 14 | from keras.utils.vis_utils import plot_model 15 | 16 | def CNN(weights=None, 17 | input_shape=[2,1024], 18 | classes=26, 19 | **kwargs): 20 | if weights is not None and not (os.path.exists(weights)): 21 | raise ValueError('The `weights` argument should be either ' 22 | '`None` (random initialization), ' 23 | 'or the path to the weights file to be loaded.') 24 | 25 | input = Input(input_shape+[1],name='input') 26 | x = input 27 | 28 | x=Conv2D(256,(2,8),padding='same', activation="relu", name="conv1", kernel_initializer='glorot_uniform')(input) 29 | x=MaxPool2D(pool_size=(1,2))(x) 30 | x=Dropout(0.5)(x) 31 | x=Conv2D(128,(2,8),padding='same', activation="relu", name="conv2", kernel_initializer='glorot_uniform')(x) 32 | x=MaxPool2D(pool_size=(1,2))(x) 33 | x=Dropout(0.5)(x) 34 | x=Conv2D(64,(2,8),padding='same', activation="relu", name="conv3", kernel_initializer='glorot_uniform')(x) 35 | x=MaxPool2D(pool_size=(1,2))(x) 36 | x=Dropout(0.5)(x) 37 | x=Conv2D(64,(2,8),padding='same', activation="relu", name="conv4", kernel_initializer='glorot_uniform')(x) 38 | x=MaxPool2D(pool_size=(1,2))(x) 39 | x=Dropout(0.5)(x) 40 | x=Flatten()(x) 41 | x = Dense(128,activation='relu',name='dense1')(x) 42 | x = Dense(26,activation='softmax',name='dense2')(x) 43 | 44 | model = Model(inputs = input,outputs = x) 45 | 46 | # Load weights. 47 | if weights is not None: 48 | model.load_weights(weights) 49 | 50 | return model 51 | 52 | import keras 53 | if __name__ == '__main__': 54 | model = CNN(None,input_shape=[2,1024],classes=24) 55 | 56 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 57 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 58 | 59 | print('models layers:', model.layers) 60 | print('models config:', model.get_config()) 61 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /HisarMod/DAE/rmlmodels/DAE.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | from keras.models import Model 12 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,BatchNormalization,TimeDistributed 13 | from keras.layers import LSTM,CuDNNLSTM,Bidirectional,Flatten,LSTM,Reshape,Lambda 14 | from keras.utils.vis_utils import plot_model 15 | 16 | def DAE(weights=None, 17 | input_shape=[1024,2], 18 | classes=26, 19 | **kwargs): 20 | if weights is not None and not (os.path.exists(weights)): 21 | raise ValueError('The `weights` argument should be either ' 22 | '`None` (random initialization), ' 23 | 'or the path to the weights file to be loaded.') 24 | 25 | input = Input(input_shape,name='input') 26 | x = input 27 | dr=0 28 | #LSTM Unit 29 | x,s,c = CuDNNLSTM(units=32,return_state = True,return_sequences = True)(x) 30 | x = Dropout(dr)(x) 31 | x,s1,c1 = CuDNNLSTM(units=32,return_state = True,return_sequences = True)(x) 32 | #Classifier 33 | xc = Dense(32,activation='relu')(s1) 34 | xc = BatchNormalization()(xc) 35 | xc = Dropout(dr)(xc) 36 | xc = Dense(16,activation='relu')(xc) 37 | xc = BatchNormalization()(xc) 38 | xc = Dropout(dr)(xc) 39 | xc = Dense(classes,activation='softmax',name='xc')(xc) 40 | 41 | #Decoder 42 | xd = TimeDistributed(Dense(2),name='xd')(x) 43 | 44 | model = Model(inputs = input,outputs = [xc,xd]) 45 | 46 | # Load weights. 47 | if weights is not None: 48 | model.load_weights(weights) 49 | 50 | return model -------------------------------------------------------------------------------- /HisarMod/DAE/rmlmodels/__pycache__/CuDNNLSTMModel.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/HisarMod/DAE/rmlmodels/__pycache__/CuDNNLSTMModel.cpython-36.pyc -------------------------------------------------------------------------------- /HisarMod/DenseNet/rmlmodels/DenseNet.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | from keras.models import Model 12 | from keras.layers import Input,Dense,ReLU,Dropout,Softmax,Conv2D,MaxPool2D,Add,concatenate,Activation 13 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 14 | from keras.utils.vis_utils import plot_model 15 | 16 | def DenseNet(weights=None, 17 | input_shape=[2,1024], 18 | classes=26, 19 | **kwargs): 20 | if weights is not None and not (os.path.exists(weights)): 21 | raise ValueError('The `weights` argument should be either ' 22 | '`None` (random initialization), ' 23 | 'or the path to the weights file to be loaded.') 24 | dr=0.6 25 | input = Input(input_shape+[1],name='input') 26 | x=Conv2D(256,(1,3), activation="relu", name="conv1", padding='same')(input) 27 | x1=Conv2D(256,(2,3), name="conv2", padding='same')(x) 28 | x2 = concatenate([x, x1]) 29 | x2 = Activation('relu')(x2) 30 | x3=Conv2D(80,(1,3), name="conv3", padding='same')(x2) 31 | x4 = concatenate([x, x1, x3]) 32 | x4 = Activation('relu')(x4) 33 | x=Conv2D(80,(1,3), activation="relu", name="conv4", padding='same')(x4) 34 | x = Dropout(dr)(x) 35 | x=Flatten()(x) 36 | 37 | x = Dense(128, activation='relu', name='fc1')(x) 38 | x = Dropout(dr)(x) 39 | x = Dense(classes, activation='softmax', name='softmax')(x) 40 | 41 | model = Model(inputs = input,outputs = x) 42 | 43 | # Load weights. 44 | if weights is not None: 45 | model.load_weights(weights) 46 | 47 | return model 48 | 49 | import keras 50 | if __name__ == '__main__': 51 | model = DenseNet(None,input_shape=[2,128],classes=11) 52 | 53 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 54 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 55 | 56 | print('models layers:', model.layers) 57 | print('models config:', model.get_config()) 58 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /HisarMod/DenseNet/rmlmodels/__pycache__/SCCLSTM.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/HisarMod/DenseNet/rmlmodels/__pycache__/SCCLSTM.cpython-36.pyc -------------------------------------------------------------------------------- /HisarMod/GRU2/rmlmodels/GRUModel.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | from keras.models import Model 12 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax 13 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 14 | from keras.utils.vis_utils import plot_model 15 | 16 | def GRUModel(weights=None, 17 | input_shape=[1024,2], 18 | classes=26, 19 | **kwargs): 20 | if weights is not None and not (os.path.exists(weights)): 21 | raise ValueError('The `weights` argument should be either ' 22 | '`None` (random initialization), ' 23 | 'or the path to the weights file to be loaded.') 24 | 25 | input = Input(input_shape,name='input') 26 | x = input 27 | 28 | #LSTM Unit 29 | x = CuDNNGRU(units=128,return_sequences = True)(x) 30 | x = CuDNNGRU(units=128)(x) 31 | 32 | #DNN 33 | x = Dense(classes,activation='softmax',name='softmax')(x) 34 | 35 | model = Model(inputs = input,outputs = x) 36 | 37 | # Load weights. 38 | if weights is not None: 39 | model.load_weights(weights) 40 | 41 | return model 42 | 43 | import keras 44 | if __name__ == '__main__': 45 | model = GRUModel(None,input_shape=(128,2),classes=11) 46 | 47 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 48 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 49 | plot_model(model, to_file='model.png',show_shapes=True) # print model 50 | 51 | print('models layers:', model.layers) 52 | print('models config:', model.get_config()) 53 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /HisarMod/IC-AMCNet/rmlmodels/ICAMC.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | from keras.models import Model 12 | from keras.layers import Input,Dense,ReLU,Dropout,Softmax,Conv2D,MaxPool2D,Lambda,GaussianNoise 13 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 14 | from keras.utils.vis_utils import plot_model 15 | 16 | def ICAMC(weights=None, 17 | input_shape=[2,1024], 18 | classes=26, 19 | **kwargs): 20 | if weights is not None and not (os.path.exists(weights)): 21 | raise ValueError('The `weights` argument should be either ' 22 | '`None` (random initialization), ' 23 | 'or the path to the weights file to be loaded.') 24 | dr = 0.4 25 | input = Input(input_shape+[1],name='input') 26 | x=Conv2D(64,(1,8), activation="relu", name="conv1", padding='same', kernel_initializer='glorot_uniform')(input) 27 | x= MaxPool2D(pool_size=(2, 2))(x) 28 | x=Conv2D(64,(1,4), activation="relu", name="conv2", padding='same', kernel_initializer='glorot_uniform')(x) 29 | x=Conv2D(128,(1,8),activation="relu", name="conv3", padding='same', kernel_initializer='glorot_uniform')(x) 30 | x = MaxPool2D(pool_size=(1, 1))(x) 31 | x = Dropout(dr)(x) 32 | x=Conv2D(128,(1,8), activation="relu", name="conv4", padding='same', kernel_initializer='glorot_uniform')(x) 33 | x = Dropout(dr)(x) 34 | x=Flatten()(x) 35 | x = Dense(128,activation='relu',name='dense1')(x) 36 | x=Dropout(dr)(x) 37 | x = GaussianNoise(1)(x) 38 | x = Dense(26,activation='softmax',name='dense2')(x) 39 | 40 | model = Model(inputs = input,outputs = x) 41 | 42 | # Load weights. 43 | if weights is not None: 44 | model.load_weights(weights) 45 | 46 | return model 47 | 48 | import keras 49 | if __name__ == '__main__': 50 | model = ICAMC(None,input_shape=[2,128],classes=11) 51 | 52 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 53 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 54 | 55 | print('models layers:', model.layers) 56 | print('models config:', model.get_config()) 57 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /HisarMod/LSTM2/rmlmodels/CuDNNLSTMModel.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | from keras.models import Model 12 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax 13 | from keras.layers import LSTM,CuDNNLSTM,Bidirectional,Flatten,LSTM 14 | from keras.utils.vis_utils import plot_model 15 | 16 | def LSTMModel(weights=None, 17 | input_shape=[1024,2], 18 | classes=26, 19 | **kwargs): 20 | if weights is not None and not (os.path.exists(weights)): 21 | raise ValueError('The `weights` argument should be either ' 22 | '`None` (random initialization), ' 23 | 'or the path to the weights file to be loaded.') 24 | 25 | input = Input(input_shape,name='input') 26 | x = input 27 | 28 | #LSTM Unit 29 | x = CuDNNLSTM(units=128,return_sequences = True)(x) 30 | x = CuDNNLSTM(units=128)(x) 31 | 32 | #DNN 33 | x = Dense(classes,activation='softmax',name='softmax')(x) 34 | 35 | model = Model(inputs = input,outputs = x) 36 | 37 | # Load weights. 38 | if weights is not None: 39 | model.load_weights(weights) 40 | 41 | return model 42 | 43 | import keras 44 | if __name__ == '__main__': 45 | model = LSTMModel(None,input_shape=(128,2),classes=11) 46 | 47 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 48 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 49 | plot_model(model, to_file='model.png',show_shapes=True) # print model 50 | 51 | print('models layers:', model.layers) 52 | print('models config:', model.get_config()) 53 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /HisarMod/MCLDNN/rmlmodels/MCLDNN.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | WEIGHTS_PATH = ('resnet_like_weights_tf_dim_ordering_tf_kernels.h5') 12 | 13 | from keras.models import Model 14 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,concatenate,Flatten,Reshape 15 | from keras.layers.convolutional import Conv2D 16 | from keras.layers import CuDNNLSTM 17 | 18 | 19 | def MCLDNN(weights=None, 20 | input_shape1=[2,1024], 21 | input_shape2=[1024,1], 22 | classes=26, 23 | **kwargs): 24 | if weights is not None and not (os.path.exists(weights)): 25 | raise ValueError('The `weights` argument should be either ' 26 | '`None` (random initialization), ' 27 | 'or the path to the weights file to be loaded.') 28 | 29 | dr = 0.5 # dropout rate (%) 30 | input1 =Input(input_shape1+[1],name='input1') 31 | input2 =Input(input_shape2,name='input2') 32 | input3=Input(input_shape2,name='input3') 33 | 34 | # SeparateChannel Combined Convolutional Neural Networks 35 | x1=Conv2D(50,(2,8),padding='same', activation="relu", name="conv1_1", kernel_initializer='glorot_uniform')(input1) 36 | x2=Conv1D(50,8,padding='causal', activation="relu", name="conv1_2", kernel_initializer='glorot_uniform')(input2) 37 | x2_reshape=Reshape([-1,1024,50])(x2) 38 | x3=Conv1D(50,8,padding='causal', activation="relu", name="conv1_3", kernel_initializer='glorot_uniform')(input3) 39 | x3_reshape=Reshape([-1,1024,50],name='reshap2')(x3) 40 | x=concatenate([x2_reshape,x3_reshape],axis=1) 41 | x=Conv2D(50,(1,8),padding='same', activation="relu", name="conv2", kernel_initializer='glorot_uniform')(x) 42 | x=concatenate([x1,x]) 43 | x=Conv2D(100,(2,5),padding='valid', activation="relu", name="conv4", kernel_initializer='glorot_uniform')(x) 44 | #LSTM Unit 45 | # batch_size,64,2 46 | x= Reshape(target_shape=((1020,100)),name='reshape')(x) 47 | x = CuDNNLSTM(units=128,return_sequences = True)(x) 48 | x = CuDNNLSTM(units=128)(x) 49 | 50 | #DNN 51 | x = Dense(128,activation='selu',name='fc1')(x) 52 | x=Dropout(dr)(x) 53 | x = Dense(128,activation='selu',name='fc2')(x) 54 | x=Dropout(dr)(x) 55 | x = Dense(classes,activation='softmax',name='softmax')(x) 56 | 57 | model = Model(inputs = [input1,input2,input3],outputs = x) 58 | 59 | # Load weights. 60 | if weights is not None: 61 | model.load_weights(weights) 62 | 63 | return model 64 | 65 | 66 | import keras 67 | from keras.utils.vis_utils import plot_model 68 | if __name__ == '__main__': 69 | model = MCLDNN(None,classes=10) 70 | 71 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 72 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 73 | plot_model(model, to_file='model.png',show_shapes=True) # print model 74 | print('models layers:', model.layers) 75 | print('models config:', model.get_config()) 76 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /HisarMod/PET-CGDNN/rmlmodels/PETCGDNN.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | import tensorflow as tf 11 | WEIGHTS_PATH = ('resnet_like_weights_tf_dim_ordering_tf_kernels.h5') 12 | import math 13 | from keras.models import Model 14 | from keras.layers import Input, Dense, Conv1D, MaxPool1D, ReLU, Dropout, Softmax, concatenate, Flatten, Reshape, \ 15 | GaussianNoise 16 | from keras.layers.convolutional import Conv2D 17 | from keras.layers import CuDNNLSTM,Lambda,Multiply,Add,Subtract,MaxPool2D,CuDNNGRU,LeakyReLU,BatchNormalization 18 | import tensorflow as tf 19 | 20 | def cal1(x): 21 | y = tf.keras.backend.cos(x) 22 | return y 23 | 24 | def cal2(x): 25 | y = tf.keras.backend.sin(x) 26 | return y 27 | 28 | def PETCGDNN(weights=None, 29 | input_shape=[1024, 2], 30 | input_shape2=[1024], 31 | classes=26, 32 | **kwargs): 33 | if weights is not None and not (os.path.exists(weights)): 34 | raise ValueError('The `weights` argument should be either ' 35 | '`None` (random initialization), ' 36 | 'or the path to the weights file to be loaded.') 37 | 38 | dr = 0.5 # dropout rate (%) 39 | input = Input(input_shape+[1], name='input1') 40 | input1 = Input(input_shape2, name='input2') 41 | input2 = Input(input_shape2, name='input3') 42 | # x1 = Flatten()(input) 43 | # x1 = GaussianNoise(0.1)(x1) 44 | # x1 = Conv2D(8,(8,2),activation='relu')(input) 45 | 46 | x1 = Flatten()(input) 47 | # x1 = BatchNormalization()(x1) 48 | # x1 = Dense(64,name='fc1')(x1) 49 | # x1 = LeakyReLU(alpha=0.3)(x1) 50 | # x1 = Dropout(dr)(x1) 51 | x1 = Dense(1, name='fc2',activation="linear")(x1) 52 | # x1 = Dropout(dr)(x1) 53 | # x1 = Reshape(target_shape=(128, 1), name='reshape1')(x1),activation='linear' 54 | # x2 = Dense(128, name='fc3')(input2) 55 | # x2 = LeakyReLU(alpha=0.3)(x2) 56 | # x2 = Dropout(dr)(x2) 57 | # x2 = Reshape(target_shape=(128, 1), name='reshape2')(x2) 58 | cos1= Lambda(cal1)(x1) 59 | sin1 = Lambda(cal2)(x1) 60 | x11 = Multiply()([input1, cos1]) 61 | x12 = Multiply()([input2, sin1]) 62 | x21 = Multiply()([input2, cos1]) 63 | x22 = Multiply()([input1, sin1]) 64 | y1 = Add()([x11,x12]) 65 | y2 = Subtract()([x21,x22]) 66 | y1 = Reshape(target_shape=(1024, 1), name='reshape1')(y1) 67 | y2 = Reshape(target_shape=(1024, 1), name='reshape2')(y2) 68 | x11 = concatenate([y1, y2]) 69 | x3 = Reshape(target_shape=((1024, 2, 1)), name='reshape3')(x11) 70 | 71 | # SeparateChannel Combined Convolutional Neural Networks 72 | # spatial feature 73 | x3 = Conv2D(75, (8,2), padding='valid', activation="relu", name="conv1_1", kernel_initializer='glorot_uniform')( 74 | x3) 75 | x3 = Conv2D(25, (5,1), padding='valid', activation="relu", name="conv1_2", kernel_initializer='glorot_uniform')( 76 | x3) 77 | # temporal feature 78 | x4 = Reshape(target_shape=((1013,25)), name='reshape4')(x3) 79 | # x4 = CuDNNLSTM(units=128, return_sequences=True)(x4) 80 | x4= CuDNNGRU(units=128)(x4) 81 | 82 | # x = Dense(128, activation='relu', name='fc4')(x4) 83 | # x = Dropout(dr)(x) 84 | # x = GaussianNoise(0.1)(x4) 85 | x = Dense(classes, activation='softmax', name='softmax')(x4) 86 | 87 | model = Model(inputs = [input,input1,input2], outputs=x) 88 | 89 | # Load weights. 90 | if weights is not None: 91 | model.load_weights(weights) 92 | 93 | return model 94 | 95 | 96 | import keras 97 | from keras.utils.vis_utils import plot_model 98 | 99 | if __name__ == '__main__': 100 | model = PETCGDNN(None, classes=10) 101 | 102 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 103 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 104 | plot_model(model, to_file='model.png', show_shapes=True) # print model 105 | print('models layers:', model.layers) 106 | print('models config:', model.get_config()) 107 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /HisarMod/ResNet/rmlmodels/ResNet.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | from keras.models import Model 12 | from keras.layers import Input,Dense,ReLU,Dropout,Activation,concatenate,Softmax,Conv2D,MaxPool2D,Add,BatchNormalization 13 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 14 | from keras.utils.vis_utils import plot_model 15 | 16 | def ResNet(weights=None, 17 | input_shape=[2,1024], 18 | classes=26, 19 | **kwargs): 20 | if weights is not None and not (os.path.exists(weights)): 21 | raise ValueError('The `weights` argument should be either ' 22 | '`None` (random initialization), ' 23 | 'or the path to the weights file to be loaded.') 24 | dr=0.6 25 | input = Input(input_shape+[1],name='input') 26 | 27 | x=Conv2D(256,(1,3), name="conv1",kernel_initializer='glorot_uniform', padding='same')(input) 28 | x = Activation('relu')(x) 29 | # x = Dropout(dr)(x) 30 | x=Conv2D(256,(2,3), name="conv2", kernel_initializer='glorot_uniform',padding='same')(x) 31 | # x = Dropout(dr)(x) 32 | x1 = Add()([input, x]) 33 | x1 = Activation('relu')(x1) 34 | x=Conv2D(80,(1,3), activation="relu", name="conv3", kernel_initializer='glorot_uniform',padding='same')(x1) 35 | x=Conv2D(80,(1,3), activation="relu", name="conv4", kernel_initializer='glorot_uniform',padding='same')(x) 36 | x = Dropout(dr)(x) 37 | x=Flatten()(x) 38 | x = Dense(128, activation='relu', name='fc1')(x) 39 | x = Dropout(dr)(x) 40 | output = Dense(classes, activation='softmax', name='softmax')(x) 41 | 42 | model = Model(inputs = input,outputs = output) 43 | 44 | # Load weights. 45 | if weights is not None: 46 | model.load_weights(weights) 47 | 48 | return model 49 | 50 | import keras 51 | if __name__ == '__main__': 52 | model = ResNet(None,input_shape=[2,128],classes=11) 53 | 54 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 55 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 56 | 57 | print('models layers:', model.layers) 58 | print('models config:', model.get_config()) 59 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610a/1DCNN-PF/rmlmodels/DCNNPF.py: -------------------------------------------------------------------------------- 1 | import os 2 | from keras.models import Model 3 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,concatenate,Flatten,Reshape 4 | from keras.layers.convolutional import Conv2D 5 | from keras.layers import CuDNNLSTM 6 | 7 | 8 | def DLmodel(weights=None, 9 | input_shape=[128], 10 | classes=11, 11 | **kwargs): 12 | if weights is not None and not (os.path.exists(weights)): 13 | raise ValueError('The `weights` argument should be either ' 14 | '`None` (random initialization), ' 15 | 'or the path to the weights file to be loaded.') 16 | 17 | dr = 0.5 # dropout rate (%) 18 | tap = 8 19 | 20 | input1 =Input(input_shape,name='input1') 21 | Reshape1=Reshape(input_shape+[1])(input1) 22 | input2=Input(input_shape,name='input2') 23 | Reshape2=Reshape(input_shape+[1])(input2) 24 | 25 | x2=Conv1D(64,3, activation="relu" )(Reshape1) 26 | x2=Dropout(0.2)(x2) 27 | x2=Conv1D(64,3, activation="relu" )(x2) 28 | x2=Dropout(0.2)(x2) 29 | x2=Conv1D(64,3, activation="relu" )(x2) 30 | x2=Dropout(0.2)(x2) 31 | x2=Conv1D(64,3, activation="relu" )(x2) 32 | x2=Dropout(0.2)(x2) 33 | 34 | x3=Conv1D(64,3, activation="relu" )(Reshape2) 35 | x3=Dropout(0.2)(x3) 36 | x3=Conv1D(64,3, activation="relu" )(x3) 37 | x3=Dropout(0.2)(x3) 38 | x3=Conv1D(64,3, activation="relu" )(x3) 39 | x3=Dropout(0.2)(x3) 40 | x3=Conv1D(64,3, activation="relu" )(x3) 41 | x3=Dropout(0.2)(x3) 42 | 43 | x=concatenate([x2,x3]) 44 | x=Conv1D(64,3, activation="relu" )(x) 45 | x=Dropout(0.2)(x) 46 | x=MaxPool1D(pool_size=2)(x) 47 | x=Conv1D(64,3, activation="relu")(x) 48 | x=Dropout(0.2)(x) 49 | x=MaxPool1D(pool_size=2)(x) 50 | x=Conv1D(64,3, activation="relu")(x) 51 | x=Dropout(0.2)(x) 52 | x=MaxPool1D(pool_size=2)(x) 53 | x=Conv1D(64,3, activation="relu")(x) 54 | x=Dropout(0.2)(x) 55 | x=MaxPool1D(pool_size=2)(x) 56 | x=Conv1D(64,3, activation="relu")(x) 57 | x=Dropout(0.2)(x) 58 | x=MaxPool1D(pool_size=2)(x) 59 | x=Flatten()(x) 60 | x = Dense(128,activation='selu',name='fc1')(x) 61 | x=Dropout(dr)(x) 62 | x = Dense(128,activation='selu',name='fc2')(x) 63 | x=Dropout(dr)(x) 64 | x = Dense(classes,activation='softmax',name='softmax')(x) 65 | 66 | model = Model(inputs = [input1,input2],outputs = x) 67 | 68 | # Load weights. 69 | if weights is not None: 70 | model.load_weights(weights) 71 | 72 | return model 73 | 74 | import keras 75 | from keras.utils.vis_utils import plot_model 76 | if __name__ == '__main__': 77 | model = DLmodel(None,classes=11) 78 | 79 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 80 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 81 | #plot_model(model, to_file='model.png',show_shapes=True) # print model 82 | print('models layers:', model.layers) 83 | print('models config:', model.get_config()) 84 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610a/CGDNet/dataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | from numpy import linalg as la 4 | 5 | maxlen=128 6 | def l2_normalize(x, axis=-1): 7 | y = np.max(np.sum(x ** 2, axis, keepdims=True), axis, keepdims=True) 8 | return x / np.sqrt(y) 9 | 10 | def norm_pad_zeros(X_train,nsamples): 11 | print ("Pad:", X_train.shape) 12 | for i in range(X_train.shape[0]): 13 | X_train[i,:,0] = X_train[i,:,0]/la.norm(X_train[i,:,0],2) 14 | return X_train 15 | 16 | 17 | def to_amp_phase(X_train,X_val,X_test,nsamples): 18 | X_train_cmplx = X_train[:,0,:] + 1j* X_train[:,1,:] 19 | X_val_cmplx = X_val[:,0,:] + 1j* X_val[:,1,:] 20 | X_test_cmplx = X_test[:,0,:] + 1j* X_test[:,1,:] 21 | 22 | X_train_amp = np.abs(X_train_cmplx) 23 | X_train_ang = np.arctan2(X_train[:,1,:],X_train[:,0,:])/np.pi 24 | 25 | 26 | X_train_amp = np.reshape(X_train_amp,(-1,1,nsamples)) 27 | X_train_ang = np.reshape(X_train_ang,(-1,1,nsamples)) 28 | 29 | X_train = np.concatenate((X_train_amp,X_train_ang), axis=1) 30 | X_train = np.transpose(np.array(X_train),(0,2,1)) 31 | 32 | X_val_amp = np.abs(X_val_cmplx) 33 | X_val_ang = np.arctan2(X_val[:,1,:],X_val[:,0,:])/np.pi 34 | 35 | 36 | X_val_amp = np.reshape(X_val_amp,(-1,1,nsamples)) 37 | X_val_ang = np.reshape(X_val_ang,(-1,1,nsamples)) 38 | 39 | X_val = np.concatenate((X_val_amp,X_val_ang), axis=1) 40 | X_val = np.transpose(np.array(X_val),(0,2,1)) 41 | 42 | X_test_amp = np.abs(X_test_cmplx) 43 | X_test_ang = np.arctan2(X_test[:,1,:],X_test[:,0,:])/np.pi 44 | 45 | 46 | X_test_amp = np.reshape(X_test_amp,(-1,1,nsamples)) 47 | X_test_ang = np.reshape(X_test_ang,(-1,1,nsamples)) 48 | 49 | X_test = np.concatenate((X_test_amp,X_test_ang), axis=1) 50 | X_test = np.transpose(np.array(X_test),(0,2,1)) 51 | return (X_train,X_val,X_test) 52 | # 53 | # def load_data(filename=r'F:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code\data\RML2016.10a_dict.pkl'): 54 | def load_data(filename=r'/home/neural/ZhangFuXin/AMR/tranining/RML2016.10a_dict.pkl'): 55 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd(1cd 20W,2,128) 10calss*20SNR*6000samples 56 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] #mods['8PSK', 'AM-DSB', 'BPSK', 'CPFSK', 'GFSK', 'PAM4', 'QAM16', 'QAM64', 'QPSK', 'WBFM'] 57 | X = [] 58 | lbl = [] 59 | train_idx=[] 60 | val_idx=[] 61 | np.random.seed(2016) 62 | a=0 63 | 64 | for mod in mods: 65 | for snr in snrs: 66 | X.append(Xd[(mod,snr)]) #ndarray(6000,2,128) 67 | for i in range(Xd[(mod,snr)].shape[0]): 68 | lbl.append((mod,snr)) 69 | train_idx+=list(np.random.choice(range(a*1000,(a+1)*1000), size=600, replace=False)) 70 | val_idx+=list(np.random.choice(list(set(range(a*1000,(a+1)*1000))-set(train_idx)), size=200, replace=False)) 71 | a+=1 72 | X = np.vstack(X) 73 | n_examples=X.shape[0] 74 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 75 | np.random.shuffle(train_idx) 76 | np.random.shuffle(val_idx) 77 | np.random.shuffle(test_idx) 78 | X_train = X[train_idx] 79 | X_val=X[val_idx] 80 | X_test = X[test_idx] 81 | # print(len(train_idx)) 82 | # print(len(val_idx)) 83 | # print(len(test_idx)) 84 | 85 | # transfor the label form to one-hot 86 | def to_onehot(yy): 87 | # yy1 = np.zeros([len(yy), max(yy)+1]) 88 | yy1 = np.zeros([len(yy), len(mods)]) 89 | yy1[np.arange(len(yy)), yy] = 1 90 | return yy1 91 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 92 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 93 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 94 | 95 | print(X_train.shape) 96 | print(X_val.shape) 97 | print(X_test.shape) 98 | print(Y_train.shape) 99 | print(Y_val.shape) 100 | print(Y_test.shape) 101 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 102 | 103 | if __name__ == '__main__': 104 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 105 | -------------------------------------------------------------------------------- /RML201610a/CGDNet/rmlmodels/CGDNN.py: -------------------------------------------------------------------------------- 1 | import os 2 | import tensorflow as tf 3 | import math 4 | from keras.models import Model 5 | from keras.layers import Input, Dense, Conv1D, MaxPool1D, ReLU, Dropout, Softmax, concatenate, Flatten, Reshape, \ 6 | GaussianNoise,Activation,GaussianDropout 7 | from keras.layers.convolutional import Conv2D 8 | from keras.layers import CuDNNLSTM,Lambda,Multiply,Add,Subtract,MaxPool2D,CuDNNGRU,LeakyReLU,BatchNormalization 9 | import tensorflow as tf 10 | 11 | def CGDNN(weights=None, 12 | input_shape=[1,2, 128], 13 | input_shape2=[128], 14 | classes=11, 15 | **kwargs): 16 | if weights is not None and not (os.path.exists(weights)): 17 | raise ValueError('The `weights` argument should be either ' 18 | '`None` (random initialization), ' 19 | 'or the path to the weights file to be loaded.') 20 | 21 | dr = 0.2 # dropout rate (%) 22 | input = Input(input_shape, name='input1') 23 | input1 = Input(input_shape2, name='input2') 24 | input2 = Input(input_shape2, name='input3') 25 | 26 | x1 = Conv2D(50,(1,6),activation='relu',kernel_initializer='lecun_uniform',data_format="channels_first")(input) 27 | x1 = MaxPool2D(pool_size=(2, 2),strides=1,padding='same',data_format="channels_first")(x1) 28 | x1 = GaussianDropout(dr)(x1) 29 | x2 = Conv2D(50, (1, 6), activation='relu',kernel_initializer='glorot_uniform',data_format="channels_first")(x1) 30 | x2 = MaxPool2D(pool_size=(2, 2),strides=1,padding='same',data_format="channels_first")(x2) 31 | x2 = GaussianDropout(dr)(x2) 32 | x3 = Conv2D(50, (1, 6), activation='relu',kernel_initializer='glorot_uniform',data_format="channels_first")(x2) 33 | x3 = MaxPool2D(pool_size=(2, 2),strides=1,padding='same',data_format="channels_first")(x3) 34 | x3 = GaussianDropout(dr)(x3) 35 | x11 = concatenate([x1, x3],3) 36 | x4 = Reshape(target_shape=((50, 472)), name='reshape4')(x11) 37 | x4 = CuDNNGRU(units=50)(x4) 38 | x4 = GaussianDropout(dr)(x4) 39 | x = Dense(256, activation='relu', name='fc4',kernel_initializer='he_normal')(x4) 40 | x = GaussianDropout(dr)(x) 41 | x = Dense(classes, activation='softmax', name='softmax')(x) 42 | model = Model(inputs = input, outputs=x) 43 | 44 | # Load weights. 45 | if weights is not None: 46 | model.load_weights(weights) 47 | 48 | return model 49 | 50 | 51 | import keras 52 | from keras.utils.vis_utils import plot_model 53 | 54 | if __name__ == '__main__': 55 | model = CGDNN(None, classes=10) 56 | 57 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 58 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 59 | plot_model(model, to_file='model.png', show_shapes=True) # print model 60 | print('models layers:', model.layers) 61 | print('models config:', model.get_config()) 62 | -------------------------------------------------------------------------------- /RML201610a/CGDNet/rmlmodels/__pycache__/CENET.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML201610a/CGDNet/rmlmodels/__pycache__/CENET.cpython-36.pyc -------------------------------------------------------------------------------- /RML201610a/CGDNet/rmlmodels/__pycache__/CGDNN.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML201610a/CGDNet/rmlmodels/__pycache__/CGDNN.cpython-36.pyc -------------------------------------------------------------------------------- /RML201610a/CGDNet/rmlmodels/__pycache__/CLDNN.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML201610a/CGDNet/rmlmodels/__pycache__/CLDNN.cpython-36.pyc -------------------------------------------------------------------------------- /RML201610a/CGDNet/rmlmodels/__pycache__/CLDNN1.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML201610a/CGDNet/rmlmodels/__pycache__/CLDNN1.cpython-36.pyc -------------------------------------------------------------------------------- /RML201610a/CGDNet/rmlmodels/__pycache__/CM.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML201610a/CGDNet/rmlmodels/__pycache__/CM.cpython-36.pyc -------------------------------------------------------------------------------- /RML201610a/CGDNet/rmlmodels/__pycache__/MCLDNN.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML201610a/CGDNet/rmlmodels/__pycache__/MCLDNN.cpython-36.pyc -------------------------------------------------------------------------------- /RML201610a/CGDNet/rmlmodels/__pycache__/SCCLSTM.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML201610a/CGDNet/rmlmodels/__pycache__/SCCLSTM.cpython-36.pyc -------------------------------------------------------------------------------- /RML201610a/CGDNet/rmlmodels/__pycache__/TSDNN.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML201610a/CGDNet/rmlmodels/__pycache__/TSDNN.cpython-36.pyc -------------------------------------------------------------------------------- /RML201610a/CLDNN/rmldataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | 5 | def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code1080ti-experiment\data\RML2016.10a_dict.pkl'): 6 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 7 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 8 | X = [] 9 | # X2=[] 10 | lbl = [] 11 | # lbl2=[] 12 | train_idx=[] 13 | val_idx=[] 14 | np.random.seed(2016) 15 | a=0 16 | 17 | for mod in mods: 18 | for snr in snrs: 19 | X.append(Xd[(mod,snr)]) #ndarray(1000,2,128) 20 | for i in range(Xd[(mod,snr)].shape[0]): 21 | lbl.append((mod,snr)) 22 | train_idx+=list(np.random.choice(range(a*1000,(a+1)*1000), size=600, replace=False)) 23 | val_idx+=list(np.random.choice(list(set(range(a*1000,(a+1)*1000))-set(train_idx)), size=200, replace=False)) 24 | a+=1 25 | X = np.vstack(X) #(220000,2,128) mods * snr * 1000,total 220000 samples 26 | print(len(lbl)) 27 | n_examples=X.shape[0] 28 | # n_test=X2.shape[0] 29 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 30 | np.random.shuffle(train_idx) 31 | np.random.shuffle(val_idx) 32 | np.random.shuffle(test_idx) 33 | # test_idx=np.random.choice(range(0,n_test),size=n_test,replace=False) 34 | X_train = X[train_idx] 35 | X_val=X[val_idx] 36 | X_test = X[test_idx] 37 | print(len(train_idx)) 38 | print(len(val_idx)) 39 | print(len(test_idx)) 40 | 41 | print(X_train.shape) 42 | print(X_val.shape) 43 | print(X_test.shape) 44 | def to_onehot(yy): 45 | # yy1 = np.zeros([len(yy), max(yy)+1]) 46 | yy1 = np.zeros([len(yy), len(mods)]) 47 | yy1[np.arange(len(yy)), yy] = 1 48 | return yy1 49 | 50 | 51 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 52 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 53 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 54 | 55 | print(Y_train.shape) 56 | print(Y_val.shape) 57 | print(Y_test.shape) 58 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 59 | 60 | if __name__ == '__main__': 61 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 62 | -------------------------------------------------------------------------------- /RML201610a/CLDNN/rmlmodels/CLDNNLikeModel.py: -------------------------------------------------------------------------------- 1 | import os 2 | import numpy as np 3 | 4 | from keras.models import Model 5 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,concatenate,Conv2D,CuDNNLSTM 6 | from keras.layers import LSTM,Permute,Reshape,ZeroPadding2D,Activation 7 | 8 | 9 | 10 | 11 | def CLDNNLikeModel(weights=None, 12 | input_shape1=[2,128], 13 | classes=11, 14 | **kwargs): 15 | if weights is not None and not (os.path.exists(weights)): 16 | raise ValueError('The `weights` argument should be either ' 17 | '`None` (random initialization), ' 18 | 'or the path to the weights file to be loaded.') 19 | 20 | dr = 0.5 21 | input_x = Input(shape=(1, 2, 128)) 22 | 23 | input_x_padding = ZeroPadding2D((0, 2), data_format="channels_first")(input_x) 24 | 25 | layer11 = Conv2D(50, (1, 8), padding='valid', activation="relu", name="conv11", init='glorot_uniform', 26 | data_format="channels_first")(input_x_padding) 27 | layer11 = Dropout(dr)(layer11) 28 | 29 | layer11_padding = ZeroPadding2D((0, 2), data_format="channels_first")(layer11) 30 | layer12 = Conv2D(50, (1, 8), padding="valid", activation="relu", name="conv12", init='glorot_uniform', 31 | data_format="channels_first")(layer11_padding) 32 | layer12 = Dropout(dr)(layer12) 33 | 34 | layer12 = ZeroPadding2D((0, 2), data_format="channels_first")(layer12) 35 | layer13 = Conv2D(50, (1, 8), padding='valid', activation="relu", name="conv13", init='glorot_uniform', 36 | data_format="channels_first")(layer12) 37 | layer13 = Dropout(dr)(layer13) 38 | 39 | concat = keras.layers.concatenate([layer11, layer13]) 40 | concat_size = list(np.shape(concat)) 41 | input_dim = int(concat_size[-1] * concat_size[-2]) 42 | timesteps = int(concat_size[-3]) 43 | concat = Reshape((timesteps, input_dim))(concat) 44 | lstm_out = CuDNNLSTM(units=50)(concat) 45 | 46 | layer_dense1 = Dense(256, activation='relu', init='he_normal', name="dense1")(lstm_out) 47 | layer_dropout = Dropout(dr)(layer_dense1) 48 | layer_dense2 = Dense(11, init='he_normal', name="dense2")(layer_dropout) 49 | layer_softmax = Activation('softmax')(layer_dense2) 50 | output = Reshape([11])(layer_softmax) 51 | 52 | model = Model(inputs=input_x, outputs=output) 53 | 54 | # Load weights. 55 | if weights is not None: 56 | model.load_weights(weights) 57 | 58 | return model 59 | 60 | import keras 61 | if __name__ == '__main__': 62 | model = CLDNNLikeModel(None,input_shape=(2,128),classes=11) 63 | 64 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 65 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 66 | 67 | print('models layers:', model.layers) 68 | print('models config:', model.get_config()) 69 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610a/CLDNN2/rmldataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | 5 | def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code1080ti-experiment\data\RML2016.10a_dict.pkl'): 6 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 7 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 8 | X = [] 9 | lbl = [] 10 | train_idx=[] 11 | val_idx=[] 12 | np.random.seed(2016) 13 | a=0 14 | 15 | for mod in mods: 16 | for snr in snrs: 17 | X.append(Xd[(mod,snr)]) #ndarray(1000,2,128) 18 | for i in range(Xd[(mod,snr)].shape[0]): 19 | lbl.append((mod,snr)) 20 | train_idx+=list(np.random.choice(range(a*1000,(a+1)*1000), size=600, replace=False)) 21 | val_idx+=list(np.random.choice(list(set(range(a*1000,(a+1)*1000))-set(train_idx)), size=200, replace=False)) 22 | a+=1 23 | X = np.vstack(X) #(220000,2,128) mods * snr * 1000,total 220000 samples 24 | print(len(lbl)) 25 | n_examples=X.shape[0] 26 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 27 | np.random.shuffle(train_idx) 28 | np.random.shuffle(val_idx) 29 | np.random.shuffle(test_idx) 30 | # test_idx=np.random.choice(range(0,n_test),size=n_test,replace=False) 31 | X_train = X[train_idx] 32 | X_val=X[val_idx] 33 | X_test = X[test_idx] 34 | print(len(train_idx)) 35 | print(len(val_idx)) 36 | print(len(test_idx)) 37 | 38 | print(X_train.shape) 39 | print(X_val.shape) 40 | print(X_test.shape) 41 | def to_onehot(yy): 42 | # yy1 = np.zeros([len(yy), max(yy)+1]) 43 | yy1 = np.zeros([len(yy), len(mods)]) 44 | yy1[np.arange(len(yy)), yy] = 1 45 | return yy1 46 | 47 | # yy = list(map(lambda x: mods.index(lbl[x][0]), train_idx)) 48 | 49 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 50 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 51 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 52 | 53 | print(Y_train.shape) 54 | print(Y_val.shape) 55 | print(Y_test.shape) 56 | 57 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 58 | 59 | if __name__ == '__main__': 60 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 61 | -------------------------------------------------------------------------------- /RML201610a/CLDNN2/rmlmodels/CLDNNLikeModel.py: -------------------------------------------------------------------------------- 1 | import os 2 | import numpy as np 3 | 4 | from keras.models import Model 5 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,concatenate,Conv2D,CuDNNLSTM 6 | from keras.layers import LSTM,Permute,Reshape,ZeroPadding2D,Activation 7 | 8 | 9 | def CLDNNLikeModel(weights=None, 10 | input_shape1=[2,128], 11 | classes=11, 12 | **kwargs): 13 | if weights is not None and not (os.path.exists(weights)): 14 | raise ValueError('The `weights` argument should be either ' 15 | '`None` (random initialization), ' 16 | 'or the path to the weights file to be loaded.') 17 | 18 | dr = 0.5 19 | input_x = Input(input_shape1+[1],name='input') 20 | 21 | x = Conv2D(256, (1, 3), activation="relu", name="conv1", init='glorot_uniform')(input_x) # (b,c,h,w) (b,h,w,c) 22 | x = Dropout(dr)(x) 23 | x = Conv2D(256, (2, 3), activation="relu", name="conv2", init='glorot_uniform')(x) # (b,c,h,w) (b,h,w,c) 24 | x = Dropout(dr)(x) 25 | x = Conv2D(80, (1, 3), activation="relu", name="conv3", init='glorot_uniform')(x) # (b,c,h,w) (b,h,w,c) 26 | x = Dropout(dr)(x) 27 | x = Conv2D(80, (1, 3), activation="relu", name="conv4", init='glorot_uniform')(x) # (b,c,h,w) (b,h,w,c) 28 | x = Dropout(dr)(x) 29 | x1 = Reshape((80, 120))(x) 30 | lstm_out = CuDNNLSTM(units=50)(x1) 31 | x = Dense(128, activation='relu', name="dense1")(lstm_out) 32 | x = Dropout(dr)(x) 33 | output = Dense(11, activation='softmax',name="dense2")(x) 34 | 35 | model = Model(inputs=input_x, outputs=output) 36 | 37 | # Load weights. 38 | if weights is not None: 39 | model.load_weights(weights) 40 | 41 | return model 42 | 43 | import keras 44 | if __name__ == '__main__': 45 | model = CLDNNLikeModel(None,input_shape=(2,128),classes=11) 46 | 47 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 48 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 49 | 50 | print('models layers:', model.layers) 51 | print('models config:', model.get_config()) 52 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610a/CNN1/rmldataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | 5 | 6 | # def load_data(filename=r'/home/xujialang/ZhangFuXin/AMR/tranining/RML2016.10a_dict.pkl'): 7 | def load_data(filename=r'F:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code1080ti-experiment\data\RML2016.10a_dict.pkl'): 8 | # Xd1 = pickle.load(open(filename1,'rb'),encoding='iso-8859-1')#Xd1.keys() mod中没有AM-SSB Xd1(120W,2,128) 9 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 10 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 11 | X = [] 12 | # X2=[] 13 | lbl = [] 14 | # lbl2=[] 15 | train_idx=[] 16 | val_idx=[] 17 | np.random.seed(2016) 18 | a=0 19 | 20 | for mod in mods: 21 | for snr in snrs: 22 | X.append(Xd[(mod,snr)]) #ndarray(1000,2,128) 23 | for i in range(Xd[(mod,snr)].shape[0]): 24 | lbl.append((mod,snr)) 25 | train_idx+=list(np.random.choice(range(a*1000,(a+1)*1000), size=600, replace=False)) 26 | val_idx+=list(np.random.choice(list(set(range(a*1000,(a+1)*1000))-set(train_idx)), size=200, replace=False)) 27 | a+=1 28 | X = np.vstack(X) #(220000,2,128) mods * snr * 1000,total 220000 samples #(162060,2,128) 29 | print(len(lbl)) 30 | n_examples=X.shape[0] 31 | # n_test=X2.shape[0] 32 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 33 | np.random.shuffle(train_idx) 34 | np.random.shuffle(val_idx) 35 | np.random.shuffle(test_idx) 36 | # test_idx=np.random.choice(range(0,n_test),size=n_test,replace=False) 37 | X_train = X[train_idx] 38 | X_val=X[val_idx] 39 | X_test = X[test_idx] 40 | print(len(train_idx)) 41 | print(len(val_idx)) 42 | print(len(test_idx)) 43 | 44 | print(X_train.shape) 45 | print(X_val.shape) 46 | print(X_test.shape) 47 | def to_onehot(yy): 48 | # yy1 = np.zeros([len(yy), max(yy)+1]) 49 | yy1 = np.zeros([len(yy), len(mods)]) 50 | yy1[np.arange(len(yy)), yy] = 1 51 | return yy1 52 | 53 | # yy = list(map(lambda x: mods.index(lbl[x][0]), train_idx)) 54 | 55 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 56 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 57 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 58 | 59 | print(Y_train.shape) 60 | print(Y_val.shape) 61 | print(Y_test.shape) 62 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 63 | 64 | if __name__ == '__main__': 65 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 66 | -------------------------------------------------------------------------------- /RML201610a/CNN1/rmlmodels/CNN2Model.py: -------------------------------------------------------------------------------- 1 | import os 2 | os.environ["KERAS_BACKEND"] = "tensorflow" 3 | # os.environ["THEANO_FLAGS"] = "device=gpu%d"%(0) 4 | import numpy as np 5 | import keras.models as models 6 | from keras.layers.core import Reshape,Dense,Dropout,Activation,Flatten 7 | from keras.layers.convolutional import Convolution2D,Conv2D, MaxPooling2D, ZeroPadding2D 8 | from keras.layers.core import Activation 9 | 10 | 11 | # Build VT-CNN2 Neural Net model using Keras primitives -- 12 | # - Reshape [N,2,128] to [N,2,128,1] on input 13 | # - Pass through 2 2DConv/ReLu layers 14 | # - Pass through 2 Dense layers (ReLu and Softmax) 15 | # - Perform categorical cross entropy optimization 16 | 17 | def CNN2Model(weights=None, 18 | input_shape=[2,128], 19 | classes=11, 20 | **kwargs): 21 | if weights is not None and not (os.path.exists(weights)): 22 | raise ValueError('The `weights` argument should be either ' 23 | '`None` (random initialization), ' 24 | 'or the path to the weights file to be loaded.') 25 | dr = 0.5 # dropout rate (%) 26 | model = models.Sequential() 27 | model.add(Reshape(input_shape + [1], input_shape=input_shape)) 28 | model.add(Convolution2D(50, (1, 8), padding='same', activation="relu", name="conv1", kernel_initializer='glorot_uniform')) 29 | model.add(Dropout(dr)) 30 | model.add(Convolution2D(50, (2, 8), padding="valid", activation="relu", name="conv2", kernel_initializer='glorot_uniform')) 31 | model.add(Dropout(dr)) 32 | model.add(Flatten()) 33 | model.add(Dense(256, activation='relu', kernel_initializer='he_normal', name="dense1")) 34 | model.add(Dropout(dr)) 35 | model.add(Dense( classes, kernel_initializer='he_normal', name="dense2" )) 36 | model.add(Activation('softmax')) 37 | 38 | 39 | # Load weights. 40 | if weights is not None: 41 | model.load_weights(weights) 42 | 43 | return model 44 | 45 | if __name__ == '__main__': 46 | print(CNN2Model().summary()) 47 | -------------------------------------------------------------------------------- /RML201610a/CNN2/dataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | 5 | def load_data(filename=r'F:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code\data\RML2016.10a_dict.pkl'): 6 | # Xd1 = pickle.load(open(filename1,'rb'),encoding='iso-8859-1')#Xd1.keys() mod中没有AM-SSB Xd1(120W,2,128) 7 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 8 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 9 | X = [] 10 | # X2=[] 11 | lbl = [] 12 | # lbl2=[] 13 | train_idx=[] 14 | val_idx=[] 15 | np.random.seed(2016) 16 | a=0 17 | 18 | for mod in mods: 19 | for snr in snrs: 20 | X.append(Xd[(mod,snr)]) #ndarray(1000,2,128) 21 | for i in range(Xd[(mod,snr)].shape[0]): 22 | lbl.append((mod,snr)) 23 | train_idx+=list(np.random.choice(range(a*1000,(a+1)*1000), size=600, replace=False)) 24 | val_idx+=list(np.random.choice(list(set(range(a*1000,(a+1)*1000))-set(train_idx)), size=200, replace=False)) 25 | a+=1 26 | X = np.vstack(X) #(220000,2,128) mods * snr * 1000,total 220000 samples 27 | # X2=np.vstack(X2) #(162060,2,128) 28 | print(len(lbl)) 29 | n_examples=X.shape[0] 30 | # n_test=X2.shape[0] 31 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 32 | np.random.shuffle(train_idx) 33 | np.random.shuffle(val_idx) 34 | np.random.shuffle(test_idx) 35 | # test_idx=np.random.choice(range(0,n_test),size=n_test,replace=False) 36 | X_train = X[train_idx] 37 | X_val=X[val_idx] 38 | X_test = X[test_idx] 39 | print(len(train_idx)) 40 | print(len(val_idx)) 41 | print(len(test_idx)) 42 | 43 | print(X_train.shape) 44 | print(X_val.shape) 45 | print(X_test.shape) 46 | def to_onehot(yy): 47 | # yy1 = np.zeros([len(yy), max(yy)+1]) 48 | yy1 = np.zeros([len(yy), len(mods)]) 49 | yy1[np.arange(len(yy)), yy] = 1 50 | return yy1 51 | 52 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 53 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 54 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 55 | 56 | print(Y_train.shape) 57 | print(Y_val.shape) 58 | print(Y_test.shape) 59 | 60 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 61 | 62 | if __name__ == '__main__': 63 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 64 | -------------------------------------------------------------------------------- /RML201610a/CNN2/rmlmodels/CNN2.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | from keras.models import Model 12 | from keras.layers import Input,Dense,ReLU,Dropout,Softmax,Conv2D,MaxPool2D 13 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 14 | from keras.utils.vis_utils import plot_model 15 | 16 | def CNN2(weights=None, 17 | input_shape=[2,128], 18 | classes=11, 19 | **kwargs): 20 | if weights is not None and not (os.path.exists(weights)): 21 | raise ValueError('The `weights` argument should be either ' 22 | '`None` (random initialization), ' 23 | 'or the path to the weights file to be loaded.') 24 | 25 | input = Input(input_shape+[1],name='input') 26 | x = input 27 | 28 | x=Conv2D(256,(2,8),padding='same', activation="relu", name="conv1", kernel_initializer='glorot_uniform')(input) 29 | x=MaxPool2D(pool_size=(1,2))(x) 30 | x=Dropout(0.5)(x) 31 | x=Conv2D(128,(2,8),padding='same', activation="relu", name="conv2", kernel_initializer='glorot_uniform')(x) 32 | x=MaxPool2D(pool_size=(1,2))(x) 33 | x=Dropout(0.5)(x) 34 | x=Conv2D(64,(2,8),padding='same', activation="relu", name="conv3", kernel_initializer='glorot_uniform')(x) 35 | x=MaxPool2D(pool_size=(1,2))(x) 36 | x=Dropout(0.5)(x) 37 | x=Conv2D(64,(2,8),padding='same', activation="relu", name="conv4", kernel_initializer='glorot_uniform')(x) 38 | x=MaxPool2D(pool_size=(1,2))(x) 39 | x=Dropout(0.5)(x) 40 | x=Flatten()(x) 41 | x = Dense(128,activation='relu',name='dense1')(x) 42 | x = Dense(11,activation='softmax',name='dense2')(x) 43 | 44 | model = Model(inputs = input,outputs = x) 45 | 46 | # Load weights. 47 | if weights is not None: 48 | model.load_weights(weights) 49 | 50 | return model 51 | 52 | import keras 53 | if __name__ == '__main__': 54 | model = MCLDNN_A(None,input_shape=[2,128],classes=11) 55 | 56 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 57 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 58 | 59 | print('models layers:', model.layers) 60 | print('models config:', model.get_config()) 61 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610a/DAE/rmlmodels/DAE.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from keras.models import Model 4 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,BatchNormalization,TimeDistributed 5 | from keras.layers import LSTM,CuDNNLSTM,Bidirectional,Flatten,LSTM,Reshape,Lambda 6 | from keras.utils.vis_utils import plot_model 7 | 8 | def DAE(weights=None, 9 | input_shape=[128,2], 10 | classes=11, 11 | **kwargs): 12 | if weights is not None and not (os.path.exists(weights)): 13 | raise ValueError('The `weights` argument should be either ' 14 | '`None` (random initialization), ' 15 | 'or the path to the weights file to be loaded.') 16 | 17 | input = Input(input_shape,name='input') 18 | x = input 19 | dr=0 20 | #LSTM Unit 21 | x,s,c = CuDNNLSTM(units=32,return_state = True,return_sequences = True)(x) 22 | x = Dropout(dr)(x) 23 | x,s1,c1 = CuDNNLSTM(units=32,return_state = True,return_sequences = True)(x) 24 | #Classifier 25 | xc = Dense(32,activation='relu')(s1) 26 | xc = BatchNormalization()(xc) 27 | xc = Dropout(dr)(xc) 28 | xc = Dense(16,activation='relu')(xc) 29 | xc = BatchNormalization()(xc) 30 | xc = Dropout(dr)(xc) 31 | xc = Dense(classes,activation='softmax',name='xc')(xc) 32 | 33 | #Decoder 34 | xd = TimeDistributed(Dense(2),name='xd')(x) 35 | 36 | model = Model(inputs = input,outputs = [xc,xd]) 37 | 38 | # Load weights. 39 | if weights is not None: 40 | model.load_weights(weights) 41 | 42 | return model -------------------------------------------------------------------------------- /RML201610a/DAE/rmlmodels/__pycache__/CuDNNLSTMModel.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML201610a/DAE/rmlmodels/__pycache__/CuDNNLSTMModel.cpython-36.pyc -------------------------------------------------------------------------------- /RML201610a/DenseNet/dataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | 5 | 6 | def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code\data\RML2016.10a_dict.pkl'): 7 | # def load_data(filename=r'/home/xujialang/ZhangFuXin/AMR/tranining/RML2016.10a_dict.pkl'): 8 | # Xd1 = pickle.load(open(filename1,'rb'),encoding='iso-8859-1')#Xd1.keys() mod中没有AM-SSB Xd1(120W,2,128) 9 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 10 | # Xd3=pickle.load(open(filename3,'rb'),encoding='iso-8859-1')#04c(162060,2,128) 11 | # snrs,mods = map(lambda j: sorted(list(set(map(lambda x: x[j], Xd.keys())))), [1,0]) 12 | # same with the following without using map function,but 'for' method 13 | # mods = set([ k[0] for k in Xd.keys()]) 14 | # mods = list(mods) 15 | # mods = sorted(mods) 16 | # 17 | # snrs = sorted(list(set([k[1] for print(len(Xd[:].shape[0])) 18 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 19 | X = [] 20 | # X2=[] 21 | lbl = [] 22 | # lbl2=[] 23 | train_idx=[] 24 | val_idx=[] 25 | np.random.seed(2016) 26 | a=0 27 | 28 | for mod in mods: 29 | for snr in snrs: 30 | X.append(Xd[(mod,snr)]) #ndarray(1000,2,128) 31 | for i in range(Xd[(mod,snr)].shape[0]): 32 | lbl.append((mod,snr)) 33 | train_idx+=list(np.random.choice(range(a*1000,(a+1)*1000), size=600, replace=False)) 34 | val_idx+=list(np.random.choice(list(set(range(a*1000,(a+1)*1000))-set(train_idx)), size=200, replace=False)) 35 | a+=1 36 | X = np.vstack(X) #(220000,2,128) mods * snr * 1000,total 220000 samples 37 | # X2=np.vstack(X2) #(162060,2,128) 38 | print(len(lbl)) 39 | # Partition the data 40 | # into training and test sets of the form we can train/test on 41 | # while keeping SNR and Mod labels handy for each 42 | n_examples=X.shape[0] 43 | # n_test=X2.shape[0] 44 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 45 | np.random.shuffle(train_idx) 46 | np.random.shuffle(val_idx) 47 | np.random.shuffle(test_idx) 48 | # test_idx=np.random.choice(range(0,n_test),size=n_test,replace=False) 49 | X_train = X[train_idx] 50 | X_val=X[val_idx] 51 | X_test = X[test_idx] 52 | print(len(train_idx)) 53 | print(len(val_idx)) 54 | print(len(test_idx)) 55 | 56 | print(X_train.shape) 57 | print(X_val.shape) 58 | print(X_test.shape) 59 | def to_onehot(yy): 60 | # yy1 = np.zeros([len(yy), max(yy)+1]) 61 | yy1 = np.zeros([len(yy), len(mods)]) 62 | yy1[np.arange(len(yy)), yy] = 1 63 | return yy1 64 | 65 | # yy = list(map(lambda x: mods.index(lbl[x][0]), train_idx)) 66 | 67 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 68 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 69 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 70 | 71 | print(Y_train.shape) 72 | print(Y_val.shape) 73 | print(Y_test.shape) 74 | 75 | # Y_one_hot = np.zeros([len(lbl),len(mods)]) 76 | # for i in range(len(lbl)): 77 | # Y_one_hot[i,mods.index(lbl[i][0])] = 1. 78 | # 79 | # Y_train2 = Y_one_hot[train_idx] 80 | # Y_test2 = Y_one_hot[test_idx] 81 | # 82 | # print( np.all(Y_test2 == Y_test) ) 83 | #X_train=X_train.swapaxes(2,1) 84 | #X_val=X_val.swapaxes(2,1) 85 | #X_test=X_test.swapaxes(2,1) 86 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 87 | 88 | if __name__ == '__main__': 89 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 90 | -------------------------------------------------------------------------------- /RML201610a/DenseNet/rmlmodels/DenseNet.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | from keras.models import Model 12 | from keras.layers import Input,Dense,ReLU,Dropout,Softmax,Conv2D,MaxPool2D,Add,concatenate,Activation 13 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 14 | from keras.utils.vis_utils import plot_model 15 | 16 | def DenseNet(weights=None, 17 | input_shape=[2,128], 18 | classes=11, 19 | **kwargs): 20 | if weights is not None and not (os.path.exists(weights)): 21 | raise ValueError('The `weights` argument should be either ' 22 | '`None` (random initialization), ' 23 | 'or the path to the weights file to be loaded.') 24 | dr=0.6 25 | input = Input(input_shape+[1],name='input') 26 | x=Conv2D(256,(1,3), activation="relu", name="conv1", padding='same')(input) 27 | x1=Conv2D(256,(2,3), name="conv2", padding='same')(x) 28 | x2 = concatenate([x, x1]) 29 | x2 = Activation('relu')(x2) 30 | x3=Conv2D(80,(1,3), name="conv3", padding='same')(x2) 31 | x4 = concatenate([x, x1, x3]) 32 | x4 = Activation('relu')(x4) 33 | x=Conv2D(80,(1,3), activation="relu", name="conv4", padding='same')(x4) 34 | x = Dropout(dr)(x) 35 | x=Flatten()(x) 36 | 37 | x = Dense(128, activation='relu', name='fc1')(x) 38 | x = Dropout(dr)(x) 39 | x = Dense(classes, activation='softmax', name='softmax')(x) 40 | 41 | model = Model(inputs = input,outputs = x) 42 | 43 | # Load weights. 44 | if weights is not None: 45 | model.load_weights(weights) 46 | 47 | return model 48 | 49 | import keras 50 | if __name__ == '__main__': 51 | model = MCLDNN_A(None,input_shape=[2,128],classes=11) 52 | 53 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 54 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 55 | 56 | print('models layers:', model.layers) 57 | print('models config:', model.get_config()) 58 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610a/GRU2/rmldataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | 5 | 6 | def load_data(filename=r'/home/xujialang/ZhangFuXin/AMR/tranining/RML2016.10a_dict.pkl'): 7 | 8 | # Xd1 = pickle.load(open(filename1,'rb'),encoding='iso-8859-1')#Xd1.keys() mod中没有AM-SSB Xd1(120W,2,128) 9 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 10 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 11 | X = [] 12 | # X2=[] 13 | lbl = [] 14 | # lbl2=[] 15 | train_idx=[] 16 | val_idx=[] 17 | np.random.seed(2016) 18 | a=0 19 | 20 | for mod in mods: 21 | for snr in snrs: 22 | X.append(Xd[(mod,snr)]) #ndarray(1000,2,128) 23 | for i in range(Xd[(mod,snr)].shape[0]): 24 | lbl.append((mod,snr)) 25 | train_idx+=list(np.random.choice(range(a*1000,(a+1)*1000), size=600, replace=False)) 26 | val_idx+=list(np.random.choice(list(set(range(a*1000,(a+1)*1000))-set(train_idx)), size=200, replace=False)) 27 | a+=1 28 | X = np.vstack(X) #(220000,2,128) mods * snr * 1000,total 220000 samples 29 | n_examples=X.shape[0] 30 | # n_test=X2.shape[0] 31 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 32 | np.random.shuffle(train_idx) 33 | np.random.shuffle(val_idx) 34 | np.random.shuffle(test_idx) 35 | # test_idx=np.random.choice(range(0,n_test),size=n_test,replace=False) 36 | X_train = X[train_idx] 37 | X_val=X[val_idx] 38 | X_test = X[test_idx] 39 | print(len(train_idx)) 40 | print(len(val_idx)) 41 | print(len(test_idx)) 42 | 43 | 44 | def to_onehot(yy): 45 | # yy1 = np.zeros([len(yy), max(yy)+1]) 46 | yy1 = np.zeros([len(yy), len(mods)]) 47 | yy1[np.arange(len(yy)), yy] = 1 48 | return yy1 49 | 50 | # yy = list(map(lambda x: mods.index(lbl[x][0]), train_idx)) 51 | 52 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 53 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 54 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 55 | 56 | X_train=X_train.swapaxes(2,1) 57 | X_val=X_val.swapaxes(2,1) 58 | X_test=X_test.swapaxes(2,1) 59 | 60 | print(X_train.shape) 61 | print(X_val.shape) 62 | print(X_test.shape) 63 | print(Y_train.shape) 64 | print(Y_val.shape) 65 | print(Y_test.shape) 66 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 67 | 68 | if __name__ == '__main__': 69 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 70 | -------------------------------------------------------------------------------- /RML201610a/GRU2/rmlmodels/GRUModel.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from keras.models import Model 4 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax 5 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 6 | from keras.utils.vis_utils import plot_model 7 | 8 | def GRUModel(weights=None, 9 | input_shape=[128,2], 10 | classes=11, 11 | **kwargs): 12 | if weights is not None and not (os.path.exists(weights)): 13 | raise ValueError('The `weights` argument should be either ' 14 | '`None` (random initialization), ' 15 | 'or the path to the weights file to be loaded.') 16 | 17 | input = Input(input_shape,name='input') 18 | x = input 19 | 20 | #LSTM Unit 21 | x = CuDNNGRU(units=128,return_sequences = True)(x) 22 | x = CuDNNGRU(units=128)(x) 23 | 24 | #DNN 25 | x = Dense(classes,activation='softmax',name='softmax')(x) 26 | 27 | model = Model(inputs = input,outputs = x) 28 | 29 | # Load weights. 30 | if weights is not None: 31 | model.load_weights(weights) 32 | 33 | return model 34 | 35 | import keras 36 | if __name__ == '__main__': 37 | model = GRUModel(None,input_shape=(128,2),classes=11) 38 | 39 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 40 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 41 | plot_model(model, to_file='model.png',show_shapes=True) # print model 42 | 43 | print('models layers:', model.layers) 44 | print('models config:', model.get_config()) 45 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610a/IC-AMCNet/dataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | 5 | 6 | # def load_data(filename=r'/home/xujialang/ZhangFuXin/AMR/tranining/RML2016.10a_dict.pkl'): 7 | def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code\data\RML2016.10a_dict.pkl'): 8 | # Xd1 = pickle.load(open(filename1,'rb'),encoding='iso-8859-1')#Xd1.keys() mod中没有AM-SSB Xd1(120W,2,128) 9 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 10 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 11 | X = [] 12 | # X2=[] 13 | lbl = [] 14 | # lbl2=[] 15 | train_idx=[] 16 | val_idx=[] 17 | np.random.seed(2016) 18 | a=0 19 | 20 | for mod in mods: 21 | for snr in snrs: 22 | X.append(Xd[(mod,snr)]) #ndarray(1000,2,128) 23 | for i in range(Xd[(mod,snr)].shape[0]): 24 | lbl.append((mod,snr)) 25 | train_idx+=list(np.random.choice(range(a*1000,(a+1)*1000), size=600, replace=False)) 26 | val_idx+=list(np.random.choice(list(set(range(a*1000,(a+1)*1000))-set(train_idx)), size=200, replace=False)) 27 | a+=1 28 | X = np.vstack(X) #(220000,2,128) mods * snr * 1000,total 220000 samples 29 | # X2=np.vstack(X2) #(162060,2,128) 30 | print(len(lbl)) 31 | # Partition the data 32 | # into training and test sets of the form we can train/test on 33 | # while keeping SNR and Mod labels handy for each 34 | n_examples=X.shape[0] 35 | # n_test=X2.shape[0] 36 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 37 | np.random.shuffle(train_idx) 38 | np.random.shuffle(val_idx) 39 | np.random.shuffle(test_idx) 40 | # test_idx=np.random.choice(range(0,n_test),size=n_test,replace=False) 41 | X_train = X[train_idx] 42 | X_val=X[val_idx] 43 | X_test = X[test_idx] 44 | print(len(train_idx)) 45 | print(len(val_idx)) 46 | print(len(test_idx)) 47 | 48 | print(X_train.shape) 49 | print(X_val.shape) 50 | print(X_test.shape) 51 | def to_onehot(yy): 52 | # yy1 = np.zeros([len(yy), max(yy)+1]) 53 | yy1 = np.zeros([len(yy), len(mods)]) 54 | yy1[np.arange(len(yy)), yy] = 1 55 | return yy1 56 | 57 | # yy = list(map(lambda x: mods.index(lbl[x][0]), train_idx)) 58 | 59 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 60 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 61 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 62 | 63 | print(Y_train.shape) 64 | print(Y_val.shape) 65 | print(Y_test.shape) 66 | 67 | # Y_one_hot = np.zeros([len(lbl),len(mods)]) 68 | # for i in range(len(lbl)): 69 | # Y_one_hot[i,mods.index(lbl[i][0])] = 1. 70 | # 71 | # Y_train2 = Y_one_hot[train_idx] 72 | # Y_test2 = Y_one_hot[test_idx] 73 | # 74 | # print( np.all(Y_test2 == Y_test) ) 75 | #X_train=X_train.swapaxes(2,1) 76 | #X_val=X_val.swapaxes(2,1) 77 | #X_test=X_test.swapaxes(2,1) 78 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 79 | 80 | if __name__ == '__main__': 81 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 82 | -------------------------------------------------------------------------------- /RML201610a/IC-AMCNet/rmlmodels/ICAMC.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | from keras.models import Model 12 | from keras.layers import Input,Dense,ReLU,Dropout,Softmax,Conv2D,MaxPool2D,Lambda,GaussianNoise 13 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 14 | from keras.utils.vis_utils import plot_model 15 | 16 | def ICAMC(weights=None, 17 | input_shape=[2,128], 18 | classes=11, 19 | **kwargs): 20 | if weights is not None and not (os.path.exists(weights)): 21 | raise ValueError('The `weights` argument should be either ' 22 | '`None` (random initialization), ' 23 | 'or the path to the weights file to be loaded.') 24 | dr = 0.4 25 | input = Input(input_shape+[1],name='input') 26 | x=Conv2D(64,(1,8), activation="relu", name="conv1", padding='same', kernel_initializer='glorot_uniform')(input) 27 | x= MaxPool2D(pool_size=(2, 2))(x) 28 | x=Conv2D(64,(1,4), activation="relu", name="conv2", padding='same', kernel_initializer='glorot_uniform')(x) 29 | x=Conv2D(128,(1,8),activation="relu", name="conv3", padding='same', kernel_initializer='glorot_uniform')(x) 30 | x = MaxPool2D(pool_size=(1, 1))(x) 31 | x = Dropout(dr)(x) 32 | x=Conv2D(128,(1,8), activation="relu", name="conv4", padding='same', kernel_initializer='glorot_uniform')(x) 33 | x = Dropout(dr)(x) 34 | x=Flatten()(x) 35 | x = Dense(128,activation='relu',name='dense1')(x) 36 | x=Dropout(dr)(x) 37 | x = GaussianNoise(1)(x) 38 | x = Dense(11,activation='softmax',name='dense2')(x) 39 | 40 | model = Model(inputs = input,outputs = x) 41 | 42 | # Load weights. 43 | if weights is not None: 44 | model.load_weights(weights) 45 | 46 | return model 47 | 48 | import keras 49 | if __name__ == '__main__': 50 | model = MCLDNN_A(None,input_shape=[2,128],classes=11) 51 | 52 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 53 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 54 | 55 | print('models layers:', model.layers) 56 | print('models config:', model.get_config()) 57 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610a/LSTM2/rmlmodels/CuDNNLSTMModel.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | from keras.models import Model 12 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax 13 | from keras.layers import LSTM,CuDNNLSTM,Bidirectional,Flatten,LSTM 14 | from keras.utils.vis_utils import plot_model 15 | 16 | def LSTMModel(weights=None, 17 | input_shape=[128,2], 18 | classes=11, 19 | **kwargs): 20 | if weights is not None and not (os.path.exists(weights)): 21 | raise ValueError('The `weights` argument should be either ' 22 | '`None` (random initialization), ' 23 | 'or the path to the weights file to be loaded.') 24 | 25 | input = Input(input_shape,name='input') 26 | x = input 27 | 28 | #LSTM Unit 29 | x = CuDNNLSTM(units=128,return_sequences = True)(x) 30 | x = CuDNNLSTM(units=128)(x) 31 | 32 | #DNN 33 | x = Dense(classes,activation='softmax',name='softmax')(x) 34 | 35 | model = Model(inputs = input,outputs = x) 36 | 37 | # Load weights. 38 | if weights is not None: 39 | model.load_weights(weights) 40 | 41 | return model 42 | 43 | import keras 44 | if __name__ == '__main__': 45 | model = LSTMModel(None,input_shape=(128,2),classes=11) 46 | 47 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 48 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 49 | plot_model(model, to_file='model.png',show_shapes=True) # print model 50 | 51 | print('models layers:', model.layers) 52 | print('models config:', model.get_config()) 53 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610a/LSTM2/rmlmodels/__pycache__/CuDNNLSTMModel.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML201610a/LSTM2/rmlmodels/__pycache__/CuDNNLSTMModel.cpython-36.pyc -------------------------------------------------------------------------------- /RML201610a/MCLDNN/dataset2016.py: -------------------------------------------------------------------------------- 1 | "Adapted from the code (https://github.com/leena201818/radiom) contributed by leena201818" 2 | import pickle 3 | import numpy as np 4 | def l2_normalize(x, axis=-1): 5 | y = np.max(np.sum(x ** 2, axis, keepdims=True), axis, keepdims=True) 6 | return x / np.sqrt(y) 7 | 8 | # def load_data(filename=r'/home/xujialang/ZhangFuXin/AMR/tranining/RML2016.10a_dict.pkl'): 9 | def load_data( 10 | filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code1080ti-experiment\data\RML2016.10a_dict.pkl'): 11 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 12 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 13 | X = [] 14 | lbl = [] 15 | train_idx=[] 16 | val_idx=[] 17 | np.random.seed(2016) 18 | a=0 19 | 20 | for mod in mods: 21 | for snr in snrs: 22 | X.append(Xd[(mod,snr)]) #ndarray(1000,2,128) 23 | for i in range(Xd[(mod,snr)].shape[0]): 24 | lbl.append((mod,snr)) 25 | train_idx+=list(np.random.choice(range(a*1000,(a+1)*1000), size=600, replace=False)) 26 | val_idx+=list(np.random.choice(list(set(range(a*1000,(a+1)*1000))-set(train_idx)), size=200, replace=False)) 27 | a+=1 28 | X = np.vstack(X) #(220000,2,128) mods * snr * 1000,total 220000 samples chui zhi fang xiang dui die 29 | n_examples=X.shape[0] 30 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 31 | np.random.shuffle(train_idx) 32 | np.random.shuffle(val_idx) 33 | np.random.shuffle(test_idx) 34 | X_train = X[train_idx] 35 | X_val=X[val_idx] 36 | X_test = X[test_idx] 37 | def to_onehot(yy): 38 | yy1 = np.zeros([len(yy), len(mods)]) 39 | yy1[np.arange(len(yy)), yy] = 1 40 | yy2=yy1 41 | return yy1 42 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 43 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 44 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 45 | 46 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 47 | # 下的代码只有在第一种情况下(即文件作为脚本直接执行)才会被执行,而 import 到其他脚本中是不会被执行的 48 | if __name__ == '__main__': 49 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 50 | -------------------------------------------------------------------------------- /RML201610a/MCLDNN/rmlmodels/MCLDNN.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | WEIGHTS_PATH = ('resnet_like_weights_tf_dim_ordering_tf_kernels.h5') 4 | 5 | from keras.models import Model 6 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,concatenate,Flatten,Reshape 7 | from keras.layers.convolutional import Conv2D 8 | from keras.layers import CuDNNLSTM 9 | 10 | 11 | def MCLDNN(weights=None, 12 | input_shape1=[2,128], 13 | input_shape2=[128,1], 14 | classes=11, 15 | **kwargs): 16 | if weights is not None and not (os.path.exists(weights)): 17 | raise ValueError('The `weights` argument should be either ' 18 | '`None` (random initialization), ' 19 | 'or the path to the weights file to be loaded.') 20 | 21 | dr = 0.5 # dropout rate (%) 22 | tap = 8 23 | input1 =Input(input_shape1+[1],name='input1') 24 | input2 =Input(input_shape2,name='input2') 25 | input3=Input(input_shape2,name='input3') 26 | #Cnvolutional Block 27 | # L = 4 28 | # for i in range(L): 29 | # x = ConvBNReluUnit(x,kernel_size = tap,index=i) 30 | 31 | # SeparateChannel Combined Convolutional Neural Networks 32 | x1=Conv2D(50,(2,8),padding='same', activation="relu", name="conv1_1", kernel_initializer='glorot_uniform')(input1) 33 | x2=Conv1D(50,8,padding='causal', activation="relu", name="conv1_2", kernel_initializer='glorot_uniform')(input2) 34 | x2_reshape=Reshape([-1,128,50])(x2) 35 | x3=Conv1D(50,8,padding='causal', activation="relu", name="conv1_3", kernel_initializer='glorot_uniform')(input3) 36 | x3_reshape=Reshape([-1,128,50],name='reshap2')(x3) 37 | x=concatenate([x2_reshape,x3_reshape],axis=1) 38 | x=Conv2D(50,(1,8),padding='same', activation="relu", name="conv2", kernel_initializer='glorot_uniform')(x) 39 | x=concatenate([x1,x]) 40 | x=Conv2D(100,(2,5),padding='valid', activation="relu", name="conv4", kernel_initializer='glorot_uniform')(x) 41 | #LSTM Unit 42 | # batch_size,64,2 43 | x= Reshape(target_shape=((124,100)),name='reshape')(x) 44 | x = CuDNNLSTM(units=128,return_sequences = True)(x) 45 | x = CuDNNLSTM(units=128)(x) 46 | 47 | #DNN 48 | x = Dense(128,activation='selu',name='fc1')(x) 49 | x=Dropout(dr)(x) 50 | x = Dense(128,activation='selu',name='fc2')(x) 51 | x=Dropout(dr)(x) 52 | x = Dense(classes,activation='softmax',name='softmax')(x) 53 | 54 | model = Model(inputs = [input1,input2,input3],outputs = x) 55 | 56 | # Load weights. 57 | if weights is not None: 58 | model.load_weights(weights) 59 | 60 | return model 61 | 62 | 63 | import keras 64 | from keras.utils.vis_utils import plot_model 65 | if __name__ == '__main__': 66 | model = MCLDNN(None,classes=10) 67 | 68 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 69 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 70 | plot_model(model, to_file='model.png',show_shapes=True) # print model 71 | print('models layers:', model.layers) 72 | print('models config:', model.get_config()) 73 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610a/MCNET/rmlmodels/__pycache__/MCNET.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML201610a/MCNET/rmlmodels/__pycache__/MCNET.cpython-36.pyc -------------------------------------------------------------------------------- /RML201610a/MCNET/rmlmodels/__pycache__/SCCLSTM.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML201610a/MCNET/rmlmodels/__pycache__/SCCLSTM.cpython-36.pyc -------------------------------------------------------------------------------- /RML201610a/PET-CGDNN/dataset2016.py: -------------------------------------------------------------------------------- 1 | "Adapted from the code (https://github.com/leena201818/radiom) contributed by leena201818" 2 | import pickle 3 | import numpy as np 4 | from numpy import linalg as la 5 | 6 | maxlen=128 7 | 8 | def load_data(filename=r'.\RML2016.10a_dict.pkl'): 9 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd(1cd 20W,2,128) 10calss*20SNR*6000samples 10 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] #mods['8PSK', 'AM-DSB', 'BPSK', 'CPFSK', 'GFSK', 'PAM4', 'QAM16', 'QAM64', 'QPSK', 'WBFM'] 11 | X = [] 12 | lbl = [] 13 | train_idx=[] 14 | val_idx=[] 15 | np.random.seed(2016) 16 | a=0 17 | 18 | for mod in mods: 19 | for snr in snrs: 20 | X.append(Xd[(mod,snr)]) #ndarray(6000,2,128) 21 | for i in range(Xd[(mod,snr)].shape[0]): 22 | lbl.append((mod,snr)) 23 | train_idx+=list(np.random.choice(range(a*1000,(a+1)*1000), size=600, replace=False)) 24 | val_idx+=list(np.random.choice(list(set(range(a*1000,(a+1)*1000))-set(train_idx)), size=200, replace=False)) 25 | a+=1 26 | X = np.vstack(X) 27 | 28 | n_examples=X.shape[0] 29 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 30 | np.random.shuffle(train_idx) 31 | np.random.shuffle(val_idx) 32 | np.random.shuffle(test_idx) 33 | X_train = X[train_idx] 34 | X_val=X[val_idx] 35 | X_test = X[test_idx] 36 | 37 | def to_onehot(yy): 38 | yy1 = np.zeros([len(yy), len(mods)]) 39 | yy1[np.arange(len(yy)), yy] = 1 40 | return yy1 41 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 42 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 43 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 44 | 45 | X_train = X_train.swapaxes(2, 1) 46 | X_val = X_val.swapaxes(2, 1) 47 | X_test = X_test.swapaxes(2, 1) 48 | 49 | print(X_train.shape) 50 | print(X_val.shape) 51 | print(X_test.shape) 52 | print(Y_train.shape) 53 | print(Y_val.shape) 54 | print(Y_test.shape) 55 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 56 | 57 | if __name__ == '__main__': 58 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 59 | -------------------------------------------------------------------------------- /RML201610a/PET-CGDNN/mltools.py: -------------------------------------------------------------------------------- 1 | import matplotlib 2 | #matplotlib.use('Tkagg') 3 | import matplotlib.pyplot as plt 4 | import numpy as np 5 | import pickle 6 | 7 | # Show loss curves 8 | def show_history(history): 9 | plt.figure() 10 | plt.title('Training loss performance') 11 | plt.plot(history.epoch, history.history['loss'], label='train loss+error') 12 | plt.plot(history.epoch, history.history['val_loss'], label='val_error') 13 | plt.legend() 14 | plt.savefig('figure/total_loss.png') 15 | plt.close() 16 | 17 | 18 | plt.figure() 19 | plt.title('Training accuracy performance') 20 | plt.plot(history.epoch, history.history['acc'], label='train_acc') 21 | plt.plot(history.epoch, history.history['val_acc'], label='val_acc') 22 | plt.legend() 23 | plt.savefig('figure/total_acc.png') 24 | plt.close() 25 | 26 | train_acc=history.history['acc'] 27 | val_acc=history.history['val_acc'] 28 | train_loss=history.history['loss'] 29 | val_loss=history.history['val_loss'] 30 | epoch=history.epoch 31 | np_train_acc=np.array(train_acc) 32 | np_val_acc=np.array(val_acc) 33 | np_train_loss=np.array(train_loss) 34 | np_val_loss=np.array(val_loss) 35 | np_epoch=np.array(epoch) 36 | np.savetxt('train_acc.txt',np_train_acc) 37 | np.savetxt('train_loss.txt',np_train_loss) 38 | np.savetxt('val_acc.txt',np_val_acc) 39 | np.savetxt('val_loss.txt',np_val_loss) 40 | 41 | def plot_confusion_matrix(cm, title='Confusion matrix', cmap=plt.get_cmap("Blues"), labels=[],save_filename=None): 42 | plt.figure(figsize=(4, 3),dpi=600) 43 | plt.imshow(cm*100, interpolation='nearest', cmap=cmap) 44 | plt.colorbar() 45 | tick_marks = np.arange(len(labels)) 46 | plt.xticks(tick_marks, labels, rotation=90,size=12) 47 | plt.yticks(tick_marks, labels,size=12) 48 | for i in range(len(tick_marks)): 49 | for j in range(len(tick_marks)): 50 | if i!=j: 51 | text=plt.text(j,i,int(np.around(cm[i,j]*100)),ha="center",va="center",fontsize=10) 52 | elif i==j: 53 | if int(np.around(cm[i,j]*100))==100: 54 | text=plt.text(j,i,int(np.around(cm[i,j]*100)),ha="center",va="center",fontsize=7,color='darkorange') 55 | else: 56 | text=plt.text(j,i,int(np.around(cm[i,j]*100)),ha="center",va="center",fontsize=10,color='darkorange') 57 | 58 | 59 | plt.tight_layout() 60 | #plt.ylabel('True label',fontdict={'size':8,}) 61 | #plt.xlabel('Predicted label',fontdict={'size':8,}) 62 | if save_filename is not None: 63 | plt.savefig(save_filename,dpi=600,bbox_inches = 'tight') 64 | plt.close() 65 | 66 | def calculate_confusion_matrix(Y,Y_hat,classes): 67 | n_classes = len(classes) 68 | conf = np.zeros([n_classes,n_classes]) 69 | confnorm = np.zeros([n_classes,n_classes]) 70 | 71 | for k in range(0,Y.shape[0]): 72 | i = list(Y[k,:]).index(1) 73 | j = int(np.argmax(Y_hat[k,:])) 74 | conf[i,j] = conf[i,j] + 1 75 | 76 | for i in range(0,n_classes): 77 | confnorm[i,:] = conf[i,:] / np.sum(conf[i,:]) 78 | # print(confnorm) 79 | 80 | right = np.sum(np.diag(conf)) 81 | wrong = np.sum(conf) - right 82 | return confnorm,right,wrong 83 | 84 | def main(): 85 | import dataset2016 86 | import numpy as np 87 | (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) = \ 88 | dataset2016.load_data() 89 | 90 | one_sample = X_test[0] 91 | print(np.shape(one_sample)) 92 | print(one_sample[0:2]) 93 | print(np.max(one_sample,axis=1)) 94 | one_sample = np.power(one_sample,2) 95 | one_sample = np.sqrt(one_sample[0,:]+one_sample[1,:]) 96 | 97 | plt.figure() 98 | plt.title('Training Samples') 99 | one_sample_t = np.arange(128) 100 | plt.plot(one_sample_t,one_sample) 101 | # plt.scatter() 102 | plt.grid() 103 | plt.show() 104 | 105 | sum_sample = np.sum(one_sample) 106 | print(sum_sample) -------------------------------------------------------------------------------- /RML201610a/PET-CGDNN/rmlmodels/PETCGDNN.py: -------------------------------------------------------------------------------- 1 | import os 2 | import tensorflow as tf 3 | WEIGHTS_PATH = ('resnet_like_weights_tf_dim_ordering_tf_kernels.h5') 4 | import math 5 | from keras.models import Model 6 | from keras.layers import Input, Dense, Conv1D, MaxPool1D, ReLU, Dropout, Softmax, concatenate, Flatten, Reshape, \ 7 | GaussianNoise,Activation 8 | from keras.layers.convolutional import Conv2D 9 | from keras.layers import CuDNNLSTM,Lambda,Multiply,Add,Subtract,MaxPool2D,CuDNNGRU,LeakyReLU,BatchNormalization 10 | import tensorflow as tf 11 | 12 | def cal1(x): 13 | y = tf.keras.backend.cos(x) 14 | return y 15 | 16 | def cal2(x): 17 | y = tf.keras.backend.sin(x) 18 | return y 19 | 20 | def PETCGDNN(weights=None, 21 | input_shape=[128, 2], 22 | input_shape2=[128], 23 | classes=11, 24 | **kwargs): 25 | if weights is not None and not (os.path.exists(weights)): 26 | raise ValueError('The `weights` argument should be either ' 27 | '`None` (random initialization), ' 28 | 'or the path to the weights file to be loaded.') 29 | 30 | dr = 0.5 # dropout rate (%) 31 | input = Input(input_shape+[1], name='input1') 32 | input1 = Input(input_shape2, name='input2') 33 | input2 = Input(input_shape2, name='input3') 34 | 35 | x1 = Flatten()(input) 36 | x1 = Dense(1, name='fc2')(x1) 37 | x1 = Activation('linear')(x1) 38 | 39 | cos1= Lambda(cal1)(x1) 40 | sin1 = Lambda(cal2)(x1) 41 | x11 = Multiply()([input1, cos1]) 42 | x12 = Multiply()([input2, sin1]) 43 | x21 = Multiply()([input2, cos1]) 44 | x22 = Multiply()([input1, sin1]) 45 | y1 = Add()([x11,x12]) 46 | y2 = Subtract()([x21,x22]) 47 | y1 = Reshape(target_shape=(128, 1), name='reshape1')(y1) 48 | y2 = Reshape(target_shape=(128, 1), name='reshape2')(y2) 49 | x11 = concatenate([y1, y2]) 50 | x3 = Reshape(target_shape=((128, 2, 1)), name='reshape3')(x11) 51 | 52 | # spatial feature 53 | x3 = Conv2D(75, (8,2), padding='valid', activation="relu", name="conv1_1", kernel_initializer='glorot_uniform')( 54 | x3) 55 | x3 = Conv2D(25, (5,1), padding='valid', activation="relu", name="conv1_2", kernel_initializer='glorot_uniform')( 56 | x3) 57 | # temporal feature 58 | x4 = Reshape(target_shape=((117,25)), name='reshape4')(x3) 59 | x4= CuDNNGRU(units=128)(x4) 60 | 61 | x = Dense(classes, activation='softmax', name='softmax')(x4) 62 | 63 | model = Model(inputs = [input,input1,input2], outputs=x) 64 | 65 | # Load weights. 66 | if weights is not None: 67 | model.load_weights(weights) 68 | 69 | return model 70 | 71 | import keras 72 | from keras.utils.vis_utils import plot_model 73 | 74 | if __name__ == '__main__': 75 | model = PETCGDNN(None, classes=10) 76 | 77 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 78 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 79 | plot_model(model, to_file='model.png', show_shapes=True) # print model 80 | print('models layers:', model.layers) 81 | print('models config:', model.get_config()) 82 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610a/ResNet/dataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | 5 | 6 | # def load_data(filename=r'/home/xujialang/ZhangFuXin/AMR/tranining/RML2016.10a_dict.pkl'): 7 | def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code1080ti-experiment\data\RML2016.10a_dict.pkl'): 8 | # Xd1 = pickle.load(open(filename1,'rb'),encoding='iso-8859-1')#Xd1.keys() mod中没有AM-SSB Xd1(120W,2,128) 9 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 10 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 11 | X = [] 12 | # X2=[] 13 | lbl = [] 14 | # lbl2=[] 15 | train_idx=[] 16 | val_idx=[] 17 | np.random.seed(2016) 18 | a=0 19 | 20 | for mod in mods: 21 | for snr in snrs: 22 | X.append(Xd[(mod,snr)]) #ndarray(1000,2,128) 23 | for i in range(Xd[(mod,snr)].shape[0]): 24 | lbl.append((mod,snr)) 25 | train_idx+=list(np.random.choice(range(a*1000,(a+1)*1000), size=600, replace=False)) 26 | val_idx+=list(np.random.choice(list(set(range(a*1000,(a+1)*1000))-set(train_idx)), size=200, replace=False)) 27 | a+=1 28 | X = np.vstack(X) #(220000,2,128) mods * snr * 1000,total 220000 samples 29 | # X2=np.vstack(X2) #(162060,2,128) 30 | print(len(lbl)) 31 | # Partition the data 32 | # into training and test sets of the form we can train/test on 33 | # while keeping SNR and Mod labels handy for each 34 | n_examples=X.shape[0] 35 | # n_test=X2.shape[0] 36 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 37 | np.random.shuffle(train_idx) 38 | np.random.shuffle(val_idx) 39 | np.random.shuffle(test_idx) 40 | # test_idx=np.random.choice(range(0,n_test),size=n_test,replace=False) 41 | X_train = X[train_idx] 42 | X_val=X[val_idx] 43 | X_test = X[test_idx] 44 | print(len(train_idx)) 45 | print(len(val_idx)) 46 | print(len(test_idx)) 47 | 48 | print(X_train.shape) 49 | print(X_val.shape) 50 | print(X_test.shape) 51 | def to_onehot(yy): 52 | # yy1 = np.zeros([len(yy), max(yy)+1]) 53 | yy1 = np.zeros([len(yy), len(mods)]) 54 | yy1[np.arange(len(yy)), yy] = 1 55 | return yy1 56 | 57 | # yy = list(map(lambda x: mods.index(lbl[x][0]), train_idx)) 58 | 59 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 60 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 61 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 62 | 63 | print(Y_train.shape) 64 | print(Y_val.shape) 65 | print(Y_test.shape) 66 | 67 | # Y_one_hot = np.zeros([len(lbl),len(mods)]) 68 | # for i in range(len(lbl)): 69 | # Y_one_hot[i,mods.index(lbl[i][0])] = 1. 70 | # 71 | # Y_train2 = Y_one_hot[train_idx] 72 | # Y_test2 = Y_one_hot[test_idx] 73 | # 74 | # print( np.all(Y_test2 == Y_test) ) 75 | #X_train=X_train.swapaxes(2,1) 76 | #X_val=X_val.swapaxes(2,1) 77 | #X_test=X_test.swapaxes(2,1) 78 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 79 | 80 | if __name__ == '__main__': 81 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 82 | -------------------------------------------------------------------------------- /RML201610a/ResNet/rmlmodels/ResNet.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from keras.models import Model 4 | from keras.layers import Input,Dense,ReLU,Dropout,Activation,concatenate,Softmax,Conv2D,MaxPool2D,Add,BatchNormalization 5 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 6 | from keras.utils.vis_utils import plot_model 7 | 8 | def ResNet(weights=None, 9 | input_shape=[2,128], 10 | classes=11, 11 | **kwargs): 12 | if weights is not None and not (os.path.exists(weights)): 13 | raise ValueError('The `weights` argument should be either ' 14 | '`None` (random initialization), ' 15 | 'or the path to the weights file to be loaded.') 16 | dr=0.6 17 | input = Input(input_shape+[1],name='input') 18 | 19 | x=Conv2D(256,(1,3), name="conv1",kernel_initializer='glorot_uniform', padding='same')(input) 20 | x = Activation('relu')(x) 21 | # x = Dropout(dr)(x) 22 | x=Conv2D(256,(2,3), name="conv2", kernel_initializer='glorot_uniform',padding='same')(x) 23 | # x = Dropout(dr)(x) 24 | x1 = Add()([input, x]) 25 | x1 = Activation('relu')(x1) 26 | x=Conv2D(80,(1,3), activation="relu", name="conv3", kernel_initializer='glorot_uniform',padding='same')(x1) 27 | x=Conv2D(80,(1,3), activation="relu", name="conv4", kernel_initializer='glorot_uniform',padding='same')(x) 28 | x = Dropout(dr)(x) 29 | x=Flatten()(x) 30 | x = Dense(128, activation='relu', name='fc1')(x) 31 | x = Dropout(dr)(x) 32 | output = Dense(classes, activation='softmax', name='softmax')(x) 33 | 34 | model = Model(inputs = input,outputs = output) 35 | 36 | # Load weights. 37 | if weights is not None: 38 | model.load_weights(weights) 39 | 40 | return model 41 | 42 | import keras 43 | if __name__ == '__main__': 44 | model = ResNet(None,input_shape=[2,128],classes=11) 45 | 46 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 47 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 48 | 49 | print('models layers:', model.layers) 50 | print('models config:', model.get_config()) 51 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610b/1DCNN-PF/rmlmodels/DCNNPF.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | WEIGHTS_PATH = ('resnet_like_weights_tf_dim_ordering_tf_kernels.h5') 4 | 5 | from keras.models import Model 6 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,concatenate,Flatten,Reshape 7 | from keras.layers.convolutional import Conv2D 8 | from keras.layers import CuDNNLSTM 9 | 10 | 11 | def DCNNPF(weights=None, 12 | input_shape=[128], 13 | classes=10, 14 | **kwargs): 15 | if weights is not None and not (os.path.exists(weights)): 16 | raise ValueError('The `weights` argument should be either ' 17 | '`None` (random initialization), ' 18 | 'or the path to the weights file to be loaded.') 19 | 20 | dr = 0.5 # dropout rate (%) 21 | tap = 8 22 | 23 | input1 =Input(input_shape,name='input1') 24 | Reshape1=Reshape(input_shape+[1])(input1) 25 | input2=Input(input_shape,name='input2') 26 | Reshape2=Reshape(input_shape+[1])(input2) 27 | #Cnvolutional Block 28 | # L = 4 29 | # for i in range(L): 30 | # x = ConvBNReluUnit(x,kernel_size = tap,index=i) 31 | 32 | # SeparateChannel Combined Convolutional Neural Networks 33 | 34 | x2=Conv1D(64,3, activation="relu" )(Reshape1) 35 | x2=Dropout(0.2)(x2) 36 | x2=Conv1D(64,3, activation="relu" )(x2) 37 | x2=Dropout(0.2)(x2) 38 | x2=Conv1D(64,3, activation="relu" )(x2) 39 | x2=Dropout(0.2)(x2) 40 | x2=Conv1D(64,3, activation="relu" )(x2) 41 | x2=Dropout(0.2)(x2) 42 | 43 | x3=Conv1D(64,3, activation="relu" )(Reshape2) 44 | x3=Dropout(0.2)(x3) 45 | x3=Conv1D(64,3, activation="relu" )(x3) 46 | x3=Dropout(0.2)(x3) 47 | x3=Conv1D(64,3, activation="relu" )(x3) 48 | x3=Dropout(0.2)(x3) 49 | x3=Conv1D(64,3, activation="relu" )(x3) 50 | x3=Dropout(0.2)(x3) 51 | 52 | x=concatenate([x2,x3]) 53 | x=Conv1D(64,3, activation="relu" )(x) 54 | x=Dropout(0.2)(x) 55 | x=MaxPool1D(pool_size=2)(x) 56 | x=Conv1D(64,3, activation="relu")(x) 57 | x=Dropout(0.2)(x) 58 | x=MaxPool1D(pool_size=2)(x) 59 | x=Conv1D(64,3, activation="relu")(x) 60 | x=Dropout(0.2)(x) 61 | x=MaxPool1D(pool_size=2)(x) 62 | x=Conv1D(64,3, activation="relu")(x) 63 | x=Dropout(0.2)(x) 64 | x=MaxPool1D(pool_size=2)(x) 65 | x=Conv1D(64,3, activation="relu")(x) 66 | x=Dropout(0.2)(x) 67 | x=MaxPool1D(pool_size=2)(x) 68 | x=Flatten()(x) 69 | x = Dense(128,activation='selu',name='fc1')(x) 70 | x=Dropout(dr)(x) 71 | x = Dense(128,activation='selu',name='fc2')(x) 72 | x=Dropout(dr)(x) 73 | x = Dense(classes,activation='softmax',name='softmax')(x) 74 | 75 | model = Model(inputs = [input1,input2],outputs = x) 76 | 77 | # Load weights. 78 | if weights is not None: 79 | model.load_weights(weights) 80 | 81 | return model 82 | 83 | import keras 84 | from keras.utils.vis_utils import plot_model 85 | if __name__ == '__main__': 86 | model = DCNNPF(None,classes=10) 87 | 88 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 89 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 90 | #plot_model(model, to_file='model.png',show_shapes=True) # print model 91 | print('models layers:', model.layers) 92 | print('models config:', model.get_config()) 93 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610b/1DCNN-PF/rmlmodels/__pycache__/SCCLSTM.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML201610b/1DCNN-PF/rmlmodels/__pycache__/SCCLSTM.cpython-36.pyc -------------------------------------------------------------------------------- /RML201610b/CGDNet/rmldataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | from numpy import linalg as la 4 | 5 | maxlen=128 6 | def l2_normalize(x, axis=-1): 7 | y = np.max(np.sum(x ** 2, axis, keepdims=True), axis, keepdims=True) 8 | return x / np.sqrt(y) 9 | 10 | def norm_pad_zeros(X_train,nsamples): 11 | print ("Pad:", X_train.shape) 12 | for i in range(X_train.shape[0]): 13 | X_train[i,:,0] = X_train[i,:,0]/la.norm(X_train[i,:,0],2) 14 | return X_train 15 | 16 | 17 | # def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code\data\RML2016.10b.dat'): 18 | def load_data(filename=r'/home/neural/ZhangFuXin/AMR/tranining/RML2016.10b.dat'): 19 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd(120W,2,128) 10calss*20SNR*6000samples 20 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] #mods['8PSK', 'AM-DSB', 'BPSK', 'CPFSK', 'GFSK', 'PAM4', 'QAM16', 'QAM64', 'QPSK', 'WBFM'] 21 | X = [] 22 | lbl = [] 23 | train_idx=[] 24 | val_idx=[] 25 | np.random.seed(2016) 26 | a=0 27 | 28 | for mod in mods: 29 | for snr in snrs: 30 | X.append(Xd[(mod,snr)]) #ndarray(6000,2,128) 31 | for i in range(Xd[(mod,snr)].shape[0]): 32 | lbl.append((mod,snr)) 33 | train_idx+=list(np.random.choice(range(a*6000,(a+1)*6000), size=3600, replace=False)) 34 | val_idx+=list(np.random.choice(list(set(range(a*6000,(a+1)*6000))-set(train_idx)), size=1200, replace=False)) 35 | a+=1 36 | X = np.vstack(X) 37 | n_examples=X.shape[0] 38 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 39 | np.random.shuffle(train_idx) 40 | np.random.shuffle(val_idx) 41 | np.random.shuffle(test_idx) 42 | X_train = X[train_idx] 43 | X_val=X[val_idx] 44 | X_test = X[test_idx] 45 | # transfor the label form to one-hot 46 | def to_onehot(yy): 47 | # yy1 = np.zeros([len(yy), max(yy)+1]) 48 | yy1 = np.zeros([len(yy), len(mods)]) 49 | yy1[np.arange(len(yy)), yy] = 1 50 | return yy1 51 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 52 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 53 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 54 | 55 | print(X_train.shape) 56 | print(X_val.shape) 57 | print(X_test.shape) 58 | print(Y_train.shape) 59 | print(Y_val.shape) 60 | print(Y_test.shape) 61 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 62 | 63 | if __name__ == '__main__': 64 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 65 | -------------------------------------------------------------------------------- /RML201610b/CGDNet/rmlmodels/CGDNN.py: -------------------------------------------------------------------------------- 1 | import os 2 | import tensorflow as tf 3 | import math 4 | from keras.models import Model 5 | from keras.layers import Input, Dense, Conv1D, MaxPool1D, ReLU, Dropout, Softmax, concatenate, Flatten, Reshape, \ 6 | GaussianNoise,Activation,GaussianDropout 7 | from keras.layers.convolutional import Conv2D 8 | from keras.layers import CuDNNLSTM,Lambda,Multiply,Add,Subtract,MaxPool2D,CuDNNGRU,LeakyReLU,BatchNormalization 9 | import tensorflow as tf 10 | 11 | def CGDNN(weights=None, 12 | input_shape=[1,2, 128], 13 | input_shape2=[128], 14 | classes=10, 15 | **kwargs): 16 | if weights is not None and not (os.path.exists(weights)): 17 | raise ValueError('The `weights` argument should be either ' 18 | '`None` (random initialization), ' 19 | 'or the path to the weights file to be loaded.') 20 | 21 | dr = 0.2 # dropout rate (%) 22 | input = Input(input_shape, name='input1') 23 | input1 = Input(input_shape2, name='input2') 24 | input2 = Input(input_shape2, name='input3') 25 | 26 | x1 = Conv2D(50,(1,6),activation='relu',kernel_initializer='lecun_uniform',data_format="channels_first")(input) 27 | x1 = MaxPool2D(pool_size=(2, 2),strides=1,padding='same',data_format="channels_first")(x1) 28 | x1 = GaussianDropout(dr)(x1) 29 | x2 = Conv2D(50, (1, 6), activation='relu',kernel_initializer='glorot_uniform',data_format="channels_first")(x1) 30 | x2 = MaxPool2D(pool_size=(2, 2),strides=1,padding='same',data_format="channels_first")(x2) 31 | x2 = GaussianDropout(dr)(x2) 32 | x3 = Conv2D(50, (1, 6), activation='relu',kernel_initializer='glorot_uniform',data_format="channels_first")(x2) 33 | x3 = MaxPool2D(pool_size=(2, 2),strides=1,padding='same',data_format="channels_first")(x3) 34 | x3 = GaussianDropout(dr)(x3) 35 | x11 = concatenate([x1, x3],3) 36 | x4 = Reshape(target_shape=((50, 472)), name='reshape4')(x11) 37 | x4 = CuDNNGRU(units=50)(x4) 38 | x4 = GaussianDropout(dr)(x4) 39 | x = Dense(256, activation='relu', name='fc4',kernel_initializer='he_normal')(x4) 40 | x = GaussianDropout(dr)(x) 41 | x = Dense(classes, activation='softmax', name='softmax')(x) 42 | model = Model(inputs = input, outputs=x) 43 | 44 | # Load weights. 45 | if weights is not None: 46 | model.load_weights(weights) 47 | 48 | return model 49 | 50 | 51 | import keras 52 | from keras.utils.vis_utils import plot_model 53 | 54 | if __name__ == '__main__': 55 | model = CGDNN(None, classes=10) 56 | 57 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 58 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 59 | plot_model(model, to_file='model.png', show_shapes=True) # print model 60 | print('models layers:', model.layers) 61 | print('models config:', model.get_config()) 62 | -------------------------------------------------------------------------------- /RML201610b/CGDNet/rmlmodels/__pycache__/CGDNN.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML201610b/CGDNet/rmlmodels/__pycache__/CGDNN.cpython-36.pyc -------------------------------------------------------------------------------- /RML201610b/CLDNN/rmldataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | 5 | 6 | # def load_data(filename=r'/home/xujialang/ZhangFuXin/AMR/tranining/RML2016.10b.dat'): 7 | def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code1080ti-experiment\data\RML2016.10b.dat'): 8 | 9 | # Xd1 = pickle.load(open(filename1,'rb'),encoding='iso-8859-1')#Xd1.keys() mod中没有AM-SSB Xd1(120W,2,128) 10 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 11 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 12 | X = [] 13 | # X2=[] 14 | lbl = [] 15 | # lbl2=[] 16 | train_idx=[] 17 | val_idx=[] 18 | np.random.seed(2016) 19 | a=0 20 | 21 | for mod in mods: 22 | for snr in snrs: 23 | X.append(Xd[(mod,snr)]) #ndarray(1000,2,128) 24 | for i in range(Xd[(mod,snr)].shape[0]): 25 | lbl.append((mod,snr)) 26 | train_idx+=list(np.random.choice(range(a*6000,(a+1)*6000), size=3600, replace=False)) 27 | val_idx+=list(np.random.choice(list(set(range(a*6000,(a+1)*6000))-set(train_idx)), size=1200, replace=False)) 28 | a+=1 29 | X = np.vstack(X) #(220000,2,128) mods * snr * 1000,total 220000 samples 30 | print(len(lbl)) 31 | n_examples=X.shape[0] 32 | # n_test=X2.shape[0] 33 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 34 | np.random.shuffle(train_idx) 35 | np.random.shuffle(val_idx) 36 | np.random.shuffle(test_idx) 37 | X_train = X[train_idx] 38 | X_val=X[val_idx] 39 | X_test = X[test_idx] 40 | print(len(train_idx)) 41 | print(len(val_idx)) 42 | print(len(test_idx)) 43 | 44 | print(X_train.shape) 45 | print(X_val.shape) 46 | print(X_test.shape) 47 | def to_onehot(yy): 48 | yy1 = np.zeros([len(yy), len(mods)]) 49 | yy1[np.arange(len(yy)), yy] = 1 50 | return yy1 51 | 52 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 53 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 54 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 55 | 56 | print(Y_train.shape) 57 | print(Y_val.shape) 58 | print(Y_test.shape) 59 | 60 | 61 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 62 | 63 | if __name__ == '__main__': 64 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 65 | -------------------------------------------------------------------------------- /RML201610b/CLDNN/rmlmodels/CLDNNLikeModel.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | import numpy as np 11 | 12 | from keras.models import Model 13 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,concatenate,Conv2D,CuDNNLSTM 14 | from keras.layers import LSTM,Permute,Reshape,ZeroPadding2D,Activation 15 | 16 | 17 | 18 | 19 | def CLDNNLikeModel(weights=None, 20 | input_shape1=[2,128], 21 | classes=10, 22 | **kwargs): 23 | if weights is not None and not (os.path.exists(weights)): 24 | raise ValueError('The `weights` argument should be either ' 25 | '`None` (random initialization), ' 26 | 'or the path to the weights file to be loaded.') 27 | 28 | dr = 0.5 # dropout rate 29 | 30 | input_x = Input(shape=(1, 2, 128)) 31 | 32 | 33 | input_x_padding = ZeroPadding2D((0, 2), data_format="channels_first")(input_x) 34 | 35 | layer11 = Conv2D(50, (1, 8), padding='valid', activation="relu", name="conv11", init='glorot_uniform', 36 | data_format="channels_first")(input_x_padding) 37 | layer11 = Dropout(dr)(layer11) 38 | 39 | layer11_padding = ZeroPadding2D((0, 2), data_format="channels_first")(layer11) 40 | layer12 = Conv2D(50, (1, 8), padding="valid", activation="relu", name="conv12", init='glorot_uniform', 41 | data_format="channels_first")(layer11_padding) 42 | layer12 = Dropout(dr)(layer12) 43 | 44 | layer12 = ZeroPadding2D((0, 2), data_format="channels_first")(layer12) 45 | layer13 = Conv2D(50, (1, 8), padding='valid', activation="relu", name="conv13", init='glorot_uniform', 46 | data_format="channels_first")(layer12) 47 | layer13 = Dropout(dr)(layer13) 48 | 49 | # : (None, 50, 2, 242), 50 | concat = keras.layers.concatenate([layer11, layer13]) 51 | concat_size = list(np.shape(concat)) 52 | input_dim = int(concat_size[-1] * concat_size[-2]) 53 | timesteps = int(concat_size[-3]) 54 | # concat = np.reshape(concat, (-1,timesteps,input_dim)) 55 | concat = Reshape((timesteps, input_dim))(concat) 56 | # (samples,timesteps,input_dim 57 | lstm_out = CuDNNLSTM(units=50)(concat) 58 | 59 | # layer_Flatten = Flatten()(lstm_out) 60 | layer_dense1 = Dense(256, activation='relu', init='he_normal', name="dense1")(lstm_out) 61 | layer_dropout = Dropout(dr)(layer_dense1) 62 | layer_dense2 = Dense(classes, init='he_normal', name="dense2")(layer_dropout) 63 | layer_softmax = Activation('softmax')(layer_dense2) 64 | output = Reshape([classes])(layer_softmax) 65 | 66 | model = Model(inputs=input_x, outputs=output) 67 | 68 | # Load weights. 69 | if weights is not None: 70 | model.load_weights(weights) 71 | 72 | return model 73 | 74 | import keras 75 | if __name__ == '__main__': 76 | model = CLDNNLikeModel(None,input_shape=(2,128),classes=10) 77 | 78 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 79 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 80 | 81 | print('models layers:', model.layers) 82 | print('models config:', model.get_config()) 83 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610b/CLDNN2/dataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code1080ti-experiment\data\RML2016.10b.dat'): 5 | # def load_data(filename=r'/home/xujialang/ZhangFuXin/AMR/tranining/RML2016.10b.dat'): 6 | # Xd1 = pickle.load(open(filename1,'rb'),encoding='iso-8859-1')#Xd1.keys() mod中没有AM-SSB Xd1(120W,2,128) 7 | Xd = pickle.load(open(filename, 'rb'), encoding='iso-8859-1') # Xd2(22W,2,128) 8 | mods, snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0, 1]] 9 | X = [] 10 | # X2=[] 11 | lbl = [] 12 | # lbl2=[] 13 | train_idx = [] 14 | val_idx = [] 15 | np.random.seed(2016) 16 | a = 0 17 | 18 | for mod in mods: 19 | for snr in snrs: 20 | X.append(Xd[(mod, snr)]) # ndarray(6000,2,128) 21 | for i in range(Xd[(mod, snr)].shape[0]): 22 | lbl.append((mod, snr)) 23 | train_idx += list(np.random.choice(range(a * 6000, (a + 1) * 6000), size=3600, replace=False)) 24 | val_idx += list( 25 | np.random.choice(list(set(range(a * 6000, (a + 1) * 6000)) - set(train_idx)), size=1200, replace=False)) 26 | a += 1 27 | X = np.vstack(X) # (220000,2,128) mods * snr * 6000,total 220000 samples 28 | # X2=np.vstack(X2) #(162060,2,128) 29 | print(len(lbl)) 30 | n_examples = X.shape[0] 31 | # n_test=X2.shape[0] 32 | test_idx = list(set(range(0, n_examples)) - set(train_idx) - set(val_idx)) 33 | np.random.shuffle(train_idx) 34 | np.random.shuffle(val_idx) 35 | np.random.shuffle(test_idx) 36 | X_train = X[train_idx] 37 | X_val = X[val_idx] 38 | X_test = X[test_idx] 39 | print(len(train_idx)) 40 | print(len(val_idx)) 41 | print(len(test_idx)) 42 | 43 | print(X_train.shape) 44 | print(X_val.shape) 45 | print(X_test.shape) 46 | 47 | def to_onehot(yy): 48 | yy1 = np.zeros([len(yy), len(mods)]) 49 | yy1[np.arange(len(yy)), yy] = 1 50 | return yy1 51 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 52 | Y_val = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 53 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), test_idx))) 54 | 55 | print(Y_train.shape) 56 | print(Y_val.shape) 57 | print(Y_test.shape) 58 | 59 | return (mods, snrs, lbl), (X_train, Y_train), (X_val, Y_val), (X_test, Y_test), (train_idx, val_idx, test_idx) 60 | 61 | 62 | if __name__ == '__main__': 63 | (mods, snrs, lbl), (X_train, Y_train), (X_val, Y_val), (X_test, Y_test), ( 64 | train_idx, val_idx, test_idx) = load_data() -------------------------------------------------------------------------------- /RML201610b/CLDNN2/rmlmodels/CLDNN.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | 12 | from keras.models import Model 13 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,concatenate,Flatten,Reshape,MaxPool2D,LSTM,Activation, CuDNNLSTM 14 | from keras.layers.convolutional import Conv2D 15 | from keras.layers import CuDNNLSTM 16 | 17 | 18 | def CLDNN(weights=None, 19 | input_shape1=[2,128], 20 | classes=10, 21 | **kwargs): 22 | if weights is not None and not (os.path.exists(weights)): 23 | raise ValueError('The `weights` argument should be either ' 24 | '`None` (random initialization), ' 25 | 'or the path to the weights file to be loaded.') 26 | 27 | dr = 0.6 # dropout rate (%) 卷积层部分 https://keras-cn.readthedocs.io/en/latest/layers/convolutional_layer/#conv2d 28 | 29 | # 这里使用keras的函数式编程 http://keras-cn.readthedocs.io/en/latest/getting_started/functional_API/ 30 | # Reshape [N,2,128] to [N,1,2,128] on input 31 | input_x = Input(input_shape1 + [1], name='input') 32 | 33 | # 卷积核维度(输出尺度),卷积核的宽度和长度,“valid”代表只进行有效的卷积,即对边界数据不处理, 34 | # 层权重weights的初始化函数 35 | # channels_first corresponds to inputs with shape (batch, channels, height, width). 36 | 37 | x = Conv2D(256, (1, 3), activation="relu", name="conv1", init='glorot_uniform')(input_x) # (b,c,h,w) (b,h,w,c) 38 | x = Dropout(dr)(x) 39 | x = Conv2D(256, (2, 3), activation="relu", name="conv2", init='glorot_uniform')(x) # (b,c,h,w) (b,h,w,c) 40 | x = Dropout(dr)(x) 41 | x = Conv2D(80, (1, 3), activation="relu", name="conv3", init='glorot_uniform')(x) # (b,c,h,w) (b,h,w,c) 42 | x = Dropout(dr)(x) 43 | x = Conv2D(80, (1, 3), activation="relu", name="conv4", init='glorot_uniform')(x) # (b,c,h,w) (b,h,w,c) 44 | x = Dropout(dr)(x) 45 | # 形如(samples,timesteps,input_dim)的3D张量 46 | x1 = Reshape((80, 120))(x) 47 | lstm_out = CuDNNLSTM(units=50)(x1) 48 | # 当 输出为250的时候正确里更高 49 | # lstm_out = LSTM(250, input_dim=input_dim, input_length=timesteps)(concat) 50 | 51 | # layer_Flatten = Flatten()(lstm_out) 52 | x = Dense(128, activation='relu', name="dense1")(lstm_out) 53 | x = Dropout(dr)(x) 54 | x = Dense(10, name="dense2")(x) 55 | output = Activation('softmax')(x) 56 | 57 | model = Model(inputs=input_x, outputs=output) 58 | 59 | # Load weights. 60 | if weights is not None: 61 | model.load_weights(weights) 62 | 63 | return model 64 | 65 | 66 | import keras 67 | from keras.utils.vis_utils import plot_model 68 | if __name__ == '__main__': 69 | model = MCLDNN(None,classes=10) 70 | 71 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 72 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 73 | print('models layers:', model.layers) 74 | print('models config:', model.get_config()) 75 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610b/CNN1/rmldataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | 5 | 6 | def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code1080ti-experiment\data\RML2016.10b.dat'): 7 | 8 | # Xd1 = pickle.load(open(filename1,'rb'),encoding='iso-8859-1')#Xd1.keys() mod中没有AM-SSB Xd1(120W,2,128) 9 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128)) 10 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 11 | X = [] 12 | # X2=[] 13 | lbl = [] 14 | # lbl2=[] 15 | train_idx=[] 16 | val_idx=[] 17 | np.random.seed(2016) 18 | a=0 19 | 20 | for mod in mods: 21 | for snr in snrs: 22 | X.append(Xd[(mod,snr)]) #ndarray(1000,2,128) 23 | for i in range(Xd[(mod,snr)].shape[0]): 24 | lbl.append((mod,snr)) 25 | train_idx+=list(np.random.choice(range(a*6000,(a+1)*6000), size=3600, replace=False)) 26 | val_idx+=list(np.random.choice(list(set(range(a*6000,(a+1)*6000))-set(train_idx)), size=1200, replace=False)) 27 | a+=1 28 | X = np.vstack(X) #(220000,2,128) mods * snr * 1000,total 220000 samples 29 | # X2=np.vstack(X2) #(162060,2,128) 30 | print(len(lbl)) 31 | n_examples=X.shape[0] 32 | # n_test=X2.shape[0] 33 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 34 | np.random.shuffle(train_idx) 35 | np.random.shuffle(val_idx) 36 | np.random.shuffle(test_idx) 37 | X_train = X[train_idx] 38 | X_val=X[val_idx] 39 | X_test = X[test_idx] 40 | print(len(train_idx)) 41 | print(len(val_idx)) 42 | print(len(test_idx)) 43 | 44 | print(X_train.shape) 45 | print(X_val.shape) 46 | print(X_test.shape) 47 | def to_onehot(yy): 48 | yy1 = np.zeros([len(yy), len(mods)]) 49 | yy1[np.arange(len(yy)), yy] = 1 50 | return yy1 51 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 52 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 53 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 54 | 55 | print(Y_train.shape) 56 | print(Y_val.shape) 57 | print(Y_test.shape) 58 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 59 | 60 | if __name__ == '__main__': 61 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 62 | -------------------------------------------------------------------------------- /RML201610b/CNN1/rmlmodels/CNN2Model.py: -------------------------------------------------------------------------------- 1 | import os 2 | os.environ["KERAS_BACKEND"] = "tensorflow" 3 | # os.environ["THEANO_FLAGS"] = "device=gpu%d"%(0) 4 | import numpy as np 5 | import keras.models as models 6 | from keras.layers.core import Reshape,Dense,Dropout,Activation,Flatten 7 | from keras.layers.convolutional import Convolution2D,Conv2D, MaxPooling2D, ZeroPadding2D 8 | from keras.layers.core import Activation 9 | 10 | 11 | def CNN2Model(weights=None, 12 | input_shape=[2,128], 13 | classes=10, 14 | **kwargs): 15 | if weights is not None and not (os.path.exists(weights)): 16 | raise ValueError('The `weights` argument should be either ' 17 | '`None` (random initialization), ' 18 | 'or the path to the weights file to be loaded.') 19 | dr = 0.5 # dropout rate (%) 20 | model = models.Sequential() 21 | model.add(Reshape(input_shape + [1], input_shape=input_shape)) 22 | model.add(Convolution2D(50, (1, 8), padding='same', activation="relu", name="conv1", kernel_initializer='glorot_uniform')) 23 | model.add(Dropout(dr)) 24 | model.add(Convolution2D(50, (2, 8), padding="valid", activation="relu", name="conv2", kernel_initializer='glorot_uniform')) 25 | model.add(Dropout(dr)) 26 | model.add(Flatten()) 27 | model.add(Dense(256, activation='relu', kernel_initializer='he_normal', name="dense1")) 28 | model.add(Dropout(dr)) 29 | model.add(Dense(classes, kernel_initializer='he_normal', name="dense2" )) 30 | model.add(Activation('softmax')) 31 | 32 | 33 | # Load weights. 34 | if weights is not None: 35 | model.load_weights(weights) 36 | 37 | return model 38 | 39 | if __name__ == '__main__': 40 | print(CNN2Model().summary()) 41 | -------------------------------------------------------------------------------- /RML201610b/CNN2/dataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | 5 | 6 | # def load_data(filename=r'D:/research_review/RML201610a/LSTM2/data/RML2016.10b.dat'): 7 | def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code1080ti-experiment\data\RML2016.10b.dat'): 8 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 9 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 10 | X = [] 11 | # X2=[] 12 | lbl = [] 13 | # lbl2=[] 14 | train_idx=[] 15 | val_idx=[] 16 | np.random.seed(2016) 17 | a=0 18 | 19 | for mod in mods: 20 | for snr in snrs: 21 | X.append(Xd[(mod,snr)]) #ndarray(6000,2,128) 22 | for i in range(Xd[(mod,snr)].shape[0]): 23 | lbl.append((mod,snr)) 24 | train_idx+=list(np.random.choice(range(a*6000,(a+1)*6000), size=3600, replace=False)) 25 | val_idx+=list(np.random.choice(list(set(range(a*6000,(a+1)*6000))-set(train_idx)), size=1200, replace=False)) 26 | a+=1 27 | X = np.vstack(X) #(220000,2,128) mods * snr * 6000,total 220000 samples 28 | print(len(lbl)) 29 | n_examples=X.shape[0] 30 | # n_test=X2.shape[0] 31 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 32 | np.random.shuffle(train_idx) 33 | np.random.shuffle(val_idx) 34 | np.random.shuffle(test_idx) 35 | X_train = X[train_idx] 36 | X_val=X[val_idx] 37 | X_test = X[test_idx] 38 | print(len(train_idx)) 39 | print(len(val_idx)) 40 | print(len(test_idx)) 41 | 42 | print(X_train.shape) 43 | print(X_val.shape) 44 | print(X_test.shape) 45 | def to_onehot(yy): 46 | # yy1 = np.zeros([len(yy), max(yy)+1]) 47 | yy1 = np.zeros([len(yy), len(mods)]) 48 | yy1[np.arange(len(yy)), yy] = 1 49 | return yy1 50 | 51 | # yy = list(map(lambda x: mods.index(lbl[x][0]), train_idx)) 52 | 53 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 54 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 55 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 56 | 57 | print(Y_train.shape) 58 | print(Y_val.shape) 59 | print(Y_test.shape) 60 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 61 | 62 | if __name__ == '__main__': 63 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 64 | -------------------------------------------------------------------------------- /RML201610b/CNN2/rmlmodels/CNN.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | from keras.models import Model 12 | from keras.layers import Input,Dense,ReLU,Dropout,Softmax,Conv2D,MaxPool2D 13 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 14 | from keras.utils.vis_utils import plot_model 15 | 16 | def CNN(weights=None, 17 | input_shape=[2,128], 18 | classes=10, 19 | **kwargs): 20 | if weights is not None and not (os.path.exists(weights)): 21 | raise ValueError('The `weights` argument should be either ' 22 | '`None` (random initialization), ' 23 | 'or the path to the weights file to be loaded.') 24 | 25 | input = Input(input_shape+[1],name='input') 26 | x = input 27 | 28 | x=Conv2D(256,(2,8),padding='same', activation="relu", name="conv1", kernel_initializer='glorot_uniform')(input) 29 | x=MaxPool2D(pool_size=(1,2))(x) 30 | x=Dropout(0.5)(x) 31 | x=Conv2D(128,(2,8),padding='same', activation="relu", name="conv2", kernel_initializer='glorot_uniform')(x) 32 | x=MaxPool2D(pool_size=(1,2))(x) 33 | x=Dropout(0.5)(x) 34 | x=Conv2D(64,(2,8),padding='same', activation="relu", name="conv3", kernel_initializer='glorot_uniform')(x) 35 | x=MaxPool2D(pool_size=(1,2))(x) 36 | x=Dropout(0.5)(x) 37 | x=Conv2D(64,(2,8),padding='same', activation="relu", name="conv4", kernel_initializer='glorot_uniform')(x) 38 | x=MaxPool2D(pool_size=(1,2))(x) 39 | x=Dropout(0.5)(x) 40 | x=Flatten()(x) 41 | x = Dense(128,activation='relu',name='dense1')(x) 42 | x = Dense(10,activation='softmax',name='dense2')(x) 43 | 44 | model = Model(inputs = input,outputs = x) 45 | 46 | # Load weights. 47 | if weights is not None: 48 | model.load_weights(weights) 49 | 50 | return model 51 | 52 | import keras 53 | if __name__ == '__main__': 54 | model = LSTMModel(None,input_shape=[2,128],classes=11) 55 | 56 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 57 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 58 | 59 | print('models layers:', model.layers) 60 | print('models config:', model.get_config()) 61 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610b/DAE/mltools.py: -------------------------------------------------------------------------------- 1 | import matplotlib 2 | #matplotlib.use('Tkagg') 3 | import matplotlib.pyplot as plt 4 | import numpy as np 5 | import pickle 6 | 7 | # Show loss curves 8 | def show_history(history): 9 | plt.figure() 10 | plt.title('Training loss performance') 11 | plt.plot(history.epoch, history.history['loss'], label='train loss+error') 12 | plt.plot(history.epoch, history.history['val_loss'], label='val_error') 13 | plt.legend() 14 | plt.savefig('figure/total_loss.png') 15 | plt.close() 16 | 17 | 18 | plt.figure() 19 | plt.title('Training accuracy performance') 20 | plt.plot(history.epoch, history.history['acc'], label='train_acc') 21 | plt.plot(history.epoch, history.history['val_acc'], label='val_acc') 22 | plt.legend() 23 | plt.savefig('figure/total_acc.png') 24 | plt.close() 25 | 26 | train_acc=history.history['acc'] 27 | val_acc=history.history['val_acc'] 28 | train_loss=history.history['loss'] 29 | val_loss=history.history['val_loss'] 30 | epoch=history.epoch 31 | np_train_acc=np.array(train_acc) 32 | np_val_acc=np.array(val_acc) 33 | np_train_loss=np.array(train_loss) 34 | np_val_loss=np.array(val_loss) 35 | np_epoch=np.array(epoch) 36 | np.savetxt('train_acc.txt',np_train_acc,delimiter=',') 37 | np.savetxt('train_loss.txt',np_train_loss,delimiter=',') 38 | np.savetxt('val_acc.txt',np_val_acc,delimiter=',') 39 | np.savetxt('val_loss.txt',np_val_loss,delimiter=',') 40 | 41 | 42 | def plot_confusion_matrix(cm, title='Confusion matrix', cmap=plt.get_cmap("Blues"), labels=[],save_filename=None): 43 | plt.figure(figsize=(4, 3), dpi=600) 44 | plt.imshow(cm * 100, interpolation='nearest', cmap=cmap) 45 | # plt.title(title,fontsize=10) 46 | plt.colorbar() 47 | tick_marks = np.arange(len(labels)) 48 | plt.xticks(tick_marks, labels, rotation=90, size=12) 49 | plt.yticks(tick_marks, labels, size=12) 50 | # np.set_printoptions(precision=2, suppress=True) 51 | for i in range(len(tick_marks)): 52 | for j in range(len(tick_marks)): 53 | if i != j: 54 | text = plt.text(j, i, int(np.around(cm[i, j] * 100)), ha="center", va="center", fontsize=10) 55 | elif i == j: 56 | if int(np.around(cm[i, j] * 100)) == 100: 57 | text = plt.text(j, i, int(np.around(cm[i, j] * 100)), ha="center", va="center", fontsize=7, 58 | color='darkorange') 59 | else: 60 | text = plt.text(j, i, int(np.around(cm[i, j] * 100)), ha="center", va="center", fontsize=10, 61 | color='darkorange') 62 | 63 | plt.tight_layout() 64 | # plt.ylabel('True label',fontdict={'size':8,}) 65 | # plt.xlabel('Predicted label',fontdict={'size':8,}) 66 | if save_filename is not None: 67 | plt.savefig(save_filename, dpi=600, bbox_inches='tight') 68 | plt.close() 69 | 70 | def calculate_confusion_matrix(Y,Y_hat,classes): 71 | n_classes = len(classes) 72 | conf = np.zeros([n_classes,n_classes]) 73 | confnorm = np.zeros([n_classes,n_classes]) 74 | 75 | for k in range(0,Y.shape[0]): 76 | i = list(Y[k,:]).index(1) 77 | j = int(np.argmax(Y_hat[k,:])) 78 | conf[i,j] = conf[i,j] + 1 79 | 80 | for i in range(0,n_classes): 81 | confnorm[i,:] = conf[i,:] / np.sum(conf[i,:]) 82 | # print(confnorm) 83 | 84 | right = np.sum(np.diag(conf)) 85 | wrong = np.sum(conf) - right 86 | return confnorm,right,wrong 87 | 88 | def main(): 89 | import dataset2016 90 | import numpy as np 91 | (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) = \ 92 | dataset2016.load_data() 93 | 94 | one_sample = X_test[0] 95 | print(np.shape(one_sample)) 96 | print(one_sample[0:2]) 97 | print(np.max(one_sample,axis=1)) 98 | one_sample = np.power(one_sample,2) 99 | one_sample = np.sqrt(one_sample[0,:]+one_sample[1,:]) 100 | 101 | plt.figure() 102 | plt.title('Training Samples') 103 | one_sample_t = np.arange(128) 104 | plt.plot(one_sample_t,one_sample) 105 | # plt.scatter() 106 | plt.grid() 107 | plt.show() 108 | 109 | sum_sample = np.sum(one_sample) 110 | print(sum_sample) -------------------------------------------------------------------------------- /RML201610b/DAE/rmlmodels/DAE.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from keras.models import Model 4 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,BatchNormalization,TimeDistributed 5 | from keras.layers import LSTM,CuDNNLSTM,Bidirectional,Flatten,LSTM,Reshape,Lambda 6 | from keras.utils.vis_utils import plot_model 7 | 8 | def DAE(weights=None, 9 | input_shape=[128,2], 10 | classes=10, 11 | **kwargs): 12 | if weights is not None and not (os.path.exists(weights)): 13 | raise ValueError('The `weights` argument should be either ' 14 | '`None` (random initialization), ' 15 | 'or the path to the weights file to be loaded.') 16 | 17 | input = Input(input_shape,name='input') 18 | x = input 19 | dr=0 20 | #LSTM Unit 21 | x,s,c = CuDNNLSTM(units=32,return_state = True,return_sequences = True)(x) 22 | x = Dropout(dr)(x) 23 | x,s1,c1 = CuDNNLSTM(units=32,return_state = True,return_sequences = True)(x) 24 | #Classifier 25 | xc = Dense(32,activation='relu')(s1) 26 | xc = BatchNormalization()(xc) 27 | xc = Dropout(dr)(xc) 28 | xc = Dense(16,activation='relu')(xc) 29 | xc = BatchNormalization()(xc) 30 | xc = Dropout(dr)(xc) 31 | xc = Dense(classes,activation='softmax',name='xc')(xc) 32 | 33 | #Decoder 34 | xd = TimeDistributed(Dense(2),name='xd')(x) 35 | 36 | model = Model(inputs = input,outputs = [xc,xd]) 37 | 38 | # Load weights. 39 | if weights is not None: 40 | model.load_weights(weights) 41 | 42 | return model -------------------------------------------------------------------------------- /RML201610b/DenseNet/dataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | 5 | 6 | # def load_data(filename=r'D:/research_review/RML201610a/LSTM2/data/RML2016.10b.dat'): 7 | def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code1080ti-experiment\data\RML2016.10b.dat'): 8 | # Xd1 = pickle.load(open(filename1,'rb'),encoding='iso-8859-1')#Xd1.keys() mod中没有AM-SSB Xd1(120W,2,128) 9 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 10 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 11 | X = [] 12 | # X2=[] 13 | lbl = [] 14 | # lbl2=[] 15 | train_idx=[] 16 | val_idx=[] 17 | np.random.seed(2016) 18 | a=0 19 | 20 | for mod in mods: 21 | for snr in snrs: 22 | X.append(Xd[(mod,snr)]) #ndarray(6000,2,128) 23 | for i in range(Xd[(mod,snr)].shape[0]): 24 | lbl.append((mod,snr)) 25 | train_idx+=list(np.random.choice(range(a*6000,(a+1)*6000), size=3600, replace=False)) 26 | val_idx+=list(np.random.choice(list(set(range(a*6000,(a+1)*6000))-set(train_idx)), size=1200, replace=False)) 27 | a+=1 28 | X = np.vstack(X) #(220000,2,128) mods * snr * 6000,total 220000 samples 29 | # X2=np.vstack(X2) #(162060,2,128) 30 | print(len(lbl)) 31 | n_examples=X.shape[0] 32 | # n_test=X2.shape[0] 33 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 34 | np.random.shuffle(train_idx) 35 | np.random.shuffle(val_idx) 36 | np.random.shuffle(test_idx) 37 | # test_idx=np.random.choice(range(0,n_test),size=n_test,replace=False) 38 | X_train = X[train_idx] 39 | X_val=X[val_idx] 40 | X_test = X[test_idx] 41 | print(len(train_idx)) 42 | print(len(val_idx)) 43 | print(len(test_idx)) 44 | 45 | print(X_train.shape) 46 | print(X_val.shape) 47 | print(X_test.shape) 48 | def to_onehot(yy): 49 | # yy1 = np.zeros([len(yy), max(yy)+1]) 50 | yy1 = np.zeros([len(yy), len(mods)]) 51 | yy1[np.arange(len(yy)), yy] = 1 52 | return yy1 53 | 54 | # yy = list(map(lambda x: mods.index(lbl[x][0]), train_idx)) 55 | 56 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 57 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 58 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 59 | 60 | print(Y_train.shape) 61 | print(Y_val.shape) 62 | print(Y_test.shape) 63 | 64 | # Y_one_hot = np.zeros([len(lbl),len(mods)]) 65 | # for i in range(len(lbl)): 66 | # Y_one_hot[i,mods.index(lbl[i][0])] = 1. 67 | # 68 | # Y_train2 = Y_one_hot[train_idx] 69 | # Y_test2 = Y_one_hot[test_idx] 70 | # 71 | # print( np.all(Y_test2 == Y_test) ) 72 | #X_train=X_train.swapaxes(2,1) 73 | #X_val=X_val.swapaxes(2,1) 74 | #X_test=X_test.swapaxes(2,1) 75 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 76 | 77 | if __name__ == '__main__': 78 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 79 | -------------------------------------------------------------------------------- /RML201610b/DenseNet/rmlmodels/DenseNet.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from keras.models import Model 4 | from keras.layers import Input,Dense,ReLU,Dropout,Softmax,Conv2D,MaxPool2D,Add,concatenate,Activation 5 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 6 | from keras.utils.vis_utils import plot_model 7 | 8 | def DenseNet(weights=None, 9 | input_shape=[2,128], 10 | classes=10, 11 | **kwargs): 12 | if weights is not None and not (os.path.exists(weights)): 13 | raise ValueError('The `weights` argument should be either ' 14 | '`None` (random initialization), ' 15 | 'or the path to the weights file to be loaded.') 16 | dr=0.6 17 | input = Input(input_shape+[1],name='input') 18 | x=Conv2D(256,(1,3), activation="relu", name="conv1", padding='same')(input) 19 | x1=Conv2D(256,(2,3), name="conv2", padding='same')(x) 20 | x2 = concatenate([x, x1]) 21 | x2 = Activation('relu')(x2) 22 | x3=Conv2D(80,(1,3), name="conv3", padding='same')(x2) 23 | x4 = concatenate([x, x1, x3]) 24 | x4 = Activation('relu')(x4) 25 | x=Conv2D(80,(1,3), activation="relu", name="conv4", padding='same')(x4) 26 | x = Dropout(dr)(x) 27 | x=Flatten()(x) 28 | 29 | x = Dense(128, activation='relu', name='fc1')(x) 30 | x = Dropout(dr)(x) 31 | x = Dense(classes, activation='softmax', name='softmax')(x) 32 | 33 | model = Model(inputs = input,outputs = x) 34 | 35 | # Load weights. 36 | if weights is not None: 37 | model.load_weights(weights) 38 | 39 | return model 40 | 41 | import keras 42 | if __name__ == '__main__': 43 | model = DenseNet(None,input_shape=[2,128],classes=10) 44 | 45 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 46 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 47 | 48 | print('models layers:', model.layers) 49 | print('models config:', model.get_config()) 50 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610b/GRU2/rmldataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | 5 | 6 | # def load_data(filename=r'D:/research_review/RML201610a/LSTM2/data/RML2016.10b.dat'): 7 | def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code1080ti-experiment\data\RML2016.10b.dat'): 8 | # Xd1 = pickle.load(open(filename1,'rb'),encoding='iso-8859-1')#Xd1.keys() mod中没有AM-SSB Xd1(120W,2,128) 9 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 10 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 11 | X = [] 12 | # X2=[] 13 | lbl = [] 14 | # lbl2=[] 15 | train_idx=[] 16 | val_idx=[] 17 | np.random.seed(2016) 18 | a=0 19 | 20 | for mod in mods: 21 | for snr in snrs: 22 | X.append(Xd[(mod,snr)]) #ndarray(6000,2,128) 23 | for i in range(Xd[(mod,snr)].shape[0]): 24 | lbl.append((mod,snr)) 25 | train_idx+=list(np.random.choice(range(a*6000,(a+1)*6000), size=3600, replace=False)) 26 | val_idx+=list(np.random.choice(list(set(range(a*6000,(a+1)*6000))-set(train_idx)), size=1200, replace=False)) 27 | a+=1 28 | X = np.vstack(X) #(220000,2,128) mods * snr * 6000,total 220000 samples 29 | n_examples=X.shape[0] 30 | # n_test=X2.shape[0] 31 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 32 | np.random.shuffle(train_idx) 33 | np.random.shuffle(val_idx) 34 | np.random.shuffle(test_idx) 35 | # test_idx=np.random.choice(range(0,n_test),size=n_test,replace=False) 36 | X_train = X[train_idx] 37 | X_val=X[val_idx] 38 | X_test = X[test_idx] 39 | print(len(train_idx)) 40 | print(len(val_idx)) 41 | print(len(test_idx)) 42 | 43 | 44 | def to_onehot(yy): 45 | # yy1 = np.zeros([len(yy), max(yy)+1]) 46 | yy1 = np.zeros([len(yy), len(mods)]) 47 | yy1[np.arange(len(yy)), yy] = 1 48 | return yy1 49 | 50 | # yy = list(map(lambda x: mods.index(lbl[x][0]), train_idx)) 51 | 52 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 53 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 54 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 55 | 56 | X_train=X_train.swapaxes(2,1) 57 | X_val=X_val.swapaxes(2,1) 58 | X_test=X_test.swapaxes(2,1) 59 | 60 | print(X_train.shape) 61 | print(X_val.shape) 62 | print(X_test.shape) 63 | print(Y_train.shape) 64 | print(Y_val.shape) 65 | print(Y_test.shape) 66 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 67 | 68 | if __name__ == '__main__': 69 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 70 | -------------------------------------------------------------------------------- /RML201610b/GRU2/rmlmodels/GRUModel.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | from keras.models import Model 12 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax 13 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 14 | from keras.utils.vis_utils import plot_model 15 | 16 | def GRUModel(weights=None, 17 | input_shape=[128,2], 18 | classes=10, 19 | **kwargs): 20 | if weights is not None and not (os.path.exists(weights)): 21 | raise ValueError('The `weights` argument should be either ' 22 | '`None` (random initialization), ' 23 | 'or the path to the weights file to be loaded.') 24 | 25 | input = Input(input_shape,name='input') 26 | x = input 27 | 28 | #LSTM Unit 29 | x = CuDNNGRU(units=128,return_sequences = True)(x) 30 | x = CuDNNGRU(units=128)(x) 31 | 32 | #DNN 33 | x = Dense(classes,activation='softmax',name='softmax')(x) 34 | 35 | model = Model(inputs = input,outputs = x) 36 | 37 | # Load weights. 38 | if weights is not None: 39 | model.load_weights(weights) 40 | 41 | return model 42 | 43 | import keras 44 | if __name__ == '__main__': 45 | model = LSTMModel(None,input_shape=(128,2),classes=11) 46 | 47 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 48 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 49 | plot_model(model, to_file='model.png',show_shapes=True) # print model 50 | 51 | print('models layers:', model.layers) 52 | print('models config:', model.get_config()) 53 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610b/IC-AMCNET/dataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code1080ti-experiment\data\RML2016.10b.dat'): 5 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 6 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 7 | X = [] 8 | # X2=[] 9 | lbl = [] 10 | # lbl2=[] 11 | train_idx=[] 12 | val_idx=[] 13 | np.random.seed(2016) 14 | a=0 15 | 16 | for mod in mods: 17 | for snr in snrs: 18 | X.append(Xd[(mod,snr)]) #ndarray(6000,2,128) 19 | for i in range(Xd[(mod,snr)].shape[0]): 20 | lbl.append((mod,snr)) 21 | train_idx+=list(np.random.choice(range(a*6000,(a+1)*6000), size=3600, replace=False)) 22 | val_idx+=list(np.random.choice(list(set(range(a*6000,(a+1)*6000))-set(train_idx)), size=1200, replace=False)) 23 | a+=1 24 | X = np.vstack(X) #(220000,2,128) mods * snr * 6000,total 220000 samples 25 | # X2=np.vstack(X2) #(162060,2,128) 26 | print(len(lbl)) 27 | n_examples=X.shape[0] 28 | # n_test=X2.shape[0] 29 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 30 | np.random.shuffle(train_idx) 31 | np.random.shuffle(val_idx) 32 | np.random.shuffle(test_idx) 33 | X_train = X[train_idx] 34 | X_val=X[val_idx] 35 | X_test = X[test_idx] 36 | print(len(train_idx)) 37 | print(len(val_idx)) 38 | print(len(test_idx)) 39 | 40 | print(X_train.shape) 41 | print(X_val.shape) 42 | print(X_test.shape) 43 | def to_onehot(yy): 44 | # yy1 = np.zeros([len(yy), max(yy)+1]) 45 | yy1 = np.zeros([len(yy), len(mods)]) 46 | yy1[np.arange(len(yy)), yy] = 1 47 | return yy1 48 | 49 | # yy = list(map(lambda x: mods.index(lbl[x][0]), train_idx)) 50 | 51 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 52 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 53 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 54 | 55 | print(Y_train.shape) 56 | print(Y_val.shape) 57 | print(Y_test.shape) 58 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 59 | 60 | if __name__ == '__main__': 61 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 62 | -------------------------------------------------------------------------------- /RML201610b/IC-AMCNET/rmlmodels/ICAMC.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from keras.models import Model 4 | from keras.layers import Input,Dense,ReLU,Dropout,Softmax,Conv2D,MaxPool2D,Lambda,GaussianNoise 5 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 6 | from keras.utils.vis_utils import plot_model 7 | 8 | def ICAMC(weights=None, 9 | input_shape=[2,128], 10 | classes=11, 11 | **kwargs): 12 | if weights is not None and not (os.path.exists(weights)): 13 | raise ValueError('The `weights` argument should be either ' 14 | '`None` (random initialization), ' 15 | 'or the path to the weights file to be loaded.') 16 | dr = 0.4 17 | input = Input(input_shape+[1],name='input') 18 | x=Conv2D(64,(1,8), activation="relu", name="conv1", padding='same', kernel_initializer='glorot_uniform')(input) 19 | x= MaxPool2D(pool_size=(2, 2))(x) 20 | x=Conv2D(64,(1,4), activation="relu", name="conv2", padding='same', kernel_initializer='glorot_uniform')(x) 21 | x=Conv2D(128,(1,8),activation="relu", name="conv3", padding='same', kernel_initializer='glorot_uniform')(x) 22 | x = MaxPool2D(pool_size=(1, 1))(x) 23 | x = Dropout(dr)(x) 24 | x=Conv2D(128,(1,8), activation="relu", name="conv4", padding='same', kernel_initializer='glorot_uniform')(x) 25 | x = Dropout(dr)(x) 26 | x=Flatten()(x) 27 | x = Dense(128,activation='relu',name='dense1')(x) 28 | x=Dropout(dr)(x) 29 | x = GaussianNoise(1)(x) 30 | x = Dense(10,activation='softmax',name='dense2')(x) 31 | 32 | model = Model(inputs = input,outputs = x) 33 | 34 | # Load weights. 35 | if weights is not None: 36 | model.load_weights(weights) 37 | 38 | return model 39 | 40 | import keras 41 | if __name__ == '__main__': 42 | model = ICAMC(None,input_shape=[2,128],classes=10) 43 | 44 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 45 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 46 | 47 | print('models layers:', model.layers) 48 | print('models config:', model.get_config()) 49 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610b/LSTM2/rmlmodels/CuDNNLSTMModel.py: -------------------------------------------------------------------------------- 1 | 2 | import os 3 | 4 | WEIGHTS_PATH = ('resnet_like_weights_tf_dim_ordering_tf_kernels.h5') 5 | 6 | from keras.models import Model 7 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax 8 | from keras.layers import LSTM,CuDNNLSTM,Bidirectional,Flatten,LSTM 9 | from keras.utils.vis_utils import plot_model 10 | 11 | def CuDNNLSTMModel(weights=None, 12 | input_shape=[1024,2], 13 | classes=10, 14 | **kwargs): 15 | if weights is not None and not (os.path.exists(weights)): 16 | raise ValueError('The `weights` argument should be either ' 17 | '`None` (random initialization), ' 18 | 'or the path to the weights file to be loaded.') 19 | input = Input(input_shape,name='input') 20 | x = input 21 | #LSTM Unit 22 | # batch_size,64,2 23 | x = CuDNNLSTM(units=128,return_sequences = True)(x) 24 | x = CuDNNLSTM(units=128)(x) 25 | 26 | #DNN 27 | x = Dense(classes,activation='softmax',name='softmax')(x) 28 | 29 | model = Model(inputs = input,outputs = x) 30 | 31 | # Load weights. 32 | if weights is not None: 33 | model.load_weights(weights) 34 | 35 | return model 36 | 37 | import keras 38 | if __name__ == '__main__': 39 | model = CuDNNLSTMModel(None,input_shape=(128,2),classes=11) 40 | 41 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 42 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 43 | plot_model(model, to_file='model.png',show_shapes=True) # print model 44 | 45 | print('models layers:', model.layers) 46 | print('models config:', model.get_config()) 47 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610b/MCLDNN/dataset2016.py: -------------------------------------------------------------------------------- 1 | "Adapted from the code (https://github.com/leena201818/radiom) contributed by leena201818" 2 | import pickle 3 | import numpy as np 4 | def l2_normalize(x, axis=-1): 5 | y = np.max(np.sum(x ** 2, axis, keepdims=True), axis, keepdims=True) 6 | return x / np.sqrt(y) 7 | 8 | # def load_data(filename=r'/home/xujialang/ZhangFuXin/AMR/tranining/RML2016.10b.dat'): 9 | def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code1080ti-experiment\data\RML2016.10b.dat'): 10 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd(120W,2,128) 10calss*20SNR*6000samples 11 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] #mods['8PSK', 'AM-DSB', 'BPSK', 'CPFSK', 'GFSK', 'PAM4', 'QAM16', 'QAM64', 'QPSK', 'WBFM'] 12 | X = [] 13 | lbl = [] 14 | train_idx=[] 15 | val_idx=[] 16 | np.random.seed(2016) 17 | a=0 18 | 19 | for mod in mods: 20 | for snr in snrs: 21 | X.append(Xd[(mod,snr)]) #ndarray(6000,2,128) 22 | for i in range(Xd[(mod,snr)].shape[0]): 23 | lbl.append((mod,snr)) 24 | train_idx+=list(np.random.choice(range(a*6000,(a+1)*6000), size=3600, replace=False)) 25 | val_idx+=list(np.random.choice(list(set(range(a*6000,(a+1)*6000))-set(train_idx)), size=1200, replace=False)) 26 | a+=1 27 | X = np.vstack(X) 28 | n_examples=X.shape[0] 29 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 30 | np.random.shuffle(train_idx) 31 | np.random.shuffle(val_idx) 32 | np.random.shuffle(test_idx) 33 | X_train = X[train_idx] 34 | X_val=X[val_idx] 35 | X_test = X[test_idx] 36 | # print(len(train_idx)) 37 | # print(len(val_idx)) 38 | # print(len(test_idx)) 39 | print(X_train.shape) 40 | print(X_val.shape) 41 | print(X_test.shape) 42 | # transfor the label form to one-hot 43 | def to_onehot(yy): 44 | # yy1 = np.zeros([len(yy), max(yy)+1]) 45 | yy1 = np.zeros([len(yy), len(mods)]) 46 | yy1[np.arange(len(yy)), yy] = 1 47 | return yy1 48 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 49 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 50 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 51 | 52 | print(Y_train.shape) 53 | print(Y_val.shape) 54 | print(Y_test.shape) 55 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 56 | #return (mods,snrs,lbl),(X_train,Y_train),(X_test,Y_test),(train_idx,val_idx,test_idx) 57 | 58 | if __name__ == '__main__': 59 | (mods, snrs, lbl), (X_train, Y_train), (X_val, Y_val), (X_test, Y_test), ( 60 | train_idx, val_idx, test_idx) = load_data() 61 | -------------------------------------------------------------------------------- /RML201610b/MCLDNN/rmlmodels/MCLDNN.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | WEIGHTS_PATH = ('resnet_like_weights_tf_dim_ordering_tf_kernels.h5') 12 | 13 | from keras.models import Model 14 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,concatenate,Flatten,Reshape 15 | from keras.layers.convolutional import Conv2D 16 | from keras.layers import CuDNNLSTM 17 | 18 | 19 | def MCLDNN(weights=None, 20 | input_shape1=[2,128], 21 | input_shape2=[128,1], 22 | classes=10, 23 | **kwargs): 24 | if weights is not None and not (os.path.exists(weights)): 25 | raise ValueError('The `weights` argument should be either ' 26 | '`None` (random initialization), ' 27 | 'or the path to the weights file to be loaded.') 28 | 29 | dr = 0.5 # dropout rate (%) 30 | tap = 8 31 | input1 =Input(input_shape1+[1],name='input1') 32 | input2 =Input(input_shape2,name='input2') 33 | input3=Input(input_shape2,name='input3') 34 | #Cnvolutional Block 35 | # L = 4 36 | # for i in range(L): 37 | # x = ConvBNReluUnit(x,kernel_size = tap,index=i) 38 | 39 | # SeparateChannel Combined Convolutional Neural Networks 40 | x1=Conv2D(50,(2,8),padding='same', activation="relu", name="conv1_1", kernel_initializer='glorot_uniform')(input1) 41 | x2=Conv1D(50,8,padding='causal', activation="relu", name="conv1_2", kernel_initializer='glorot_uniform')(input2) 42 | x2_reshape=Reshape([-1,128,50])(x2) 43 | x3=Conv1D(50,8,padding='causal', activation="relu", name="conv1_3", kernel_initializer='glorot_uniform')(input3) 44 | x3_reshape=Reshape([-1,128,50],name='reshap2')(x3) 45 | x=concatenate([x2_reshape,x3_reshape],axis=1) 46 | x=Conv2D(50,(1,8),padding='same', activation="relu", name="conv2", kernel_initializer='glorot_uniform')(x) 47 | x=concatenate([x1,x]) 48 | x=Conv2D(100,(2,5),padding='valid', activation="relu", name="conv4", kernel_initializer='glorot_uniform')(x) 49 | #LSTM Unit 50 | # batch_size,64,2 51 | x= Reshape(target_shape=((124,100)),name='reshape')(x) 52 | x = CuDNNLSTM(units=128,return_sequences = True)(x) 53 | x = CuDNNLSTM(units=128)(x) 54 | 55 | #DNN 56 | x = Dense(128,activation='selu',name='fc1')(x) 57 | x=Dropout(dr)(x) 58 | x = Dense(128,activation='selu',name='fc2')(x) 59 | x=Dropout(dr)(x) 60 | x = Dense(classes,activation='softmax',name='softmax')(x) 61 | 62 | model = Model(inputs = [input1,input2,input3],outputs = x) 63 | 64 | # Load weights. 65 | if weights is not None: 66 | model.load_weights(weights) 67 | 68 | return model 69 | 70 | import keras 71 | from keras.utils.vis_utils import plot_model 72 | if __name__ == '__main__': 73 | model = MCLDNN(None,classes=10) 74 | 75 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 76 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 77 | plot_model(model, to_file='model.png',show_shapes=True) # print model 78 | print('models layers:', model.layers) 79 | print('models config:', model.get_config()) 80 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610b/MCNET/rmldataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | from numpy import linalg as la 4 | 5 | maxlen=128 6 | def l2_normalize(x, axis=-1): 7 | y = np.max(np.sum(x ** 2, axis, keepdims=True), axis, keepdims=True) 8 | return x / np.sqrt(y) 9 | 10 | def norm_pad_zeros(X_train,nsamples): 11 | print ("Pad:", X_train.shape) 12 | for i in range(X_train.shape[0]): 13 | X_train[i,:,0] = X_train[i,:,0]/la.norm(X_train[i,:,0],2) 14 | return X_train 15 | 16 | 17 | # def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code\data\RML2016.10b.dat'): 18 | def load_data(filename=r'/home/neural/ZhangFuXin/AMR/tranining/RML2016.10b.dat'): 19 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd(120W,2,128) 10calss*20SNR*6000samples 20 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] #mods['8PSK', 'AM-DSB', 'BPSK', 'CPFSK', 'GFSK', 'PAM4', 'QAM16', 'QAM64', 'QPSK', 'WBFM'] 21 | X = [] 22 | lbl = [] 23 | train_idx=[] 24 | val_idx=[] 25 | np.random.seed(2016) 26 | a=0 27 | 28 | for mod in mods: 29 | for snr in snrs: 30 | X.append(Xd[(mod,snr)]) #ndarray(6000,2,128) 31 | for i in range(Xd[(mod,snr)].shape[0]): 32 | lbl.append((mod,snr)) 33 | train_idx+=list(np.random.choice(range(a*6000,(a+1)*6000), size=3600, replace=False)) 34 | val_idx+=list(np.random.choice(list(set(range(a*6000,(a+1)*6000))-set(train_idx)), size=1200, replace=False)) 35 | a+=1 36 | X = np.vstack(X) 37 | n_examples=X.shape[0] 38 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 39 | np.random.shuffle(train_idx) 40 | np.random.shuffle(val_idx) 41 | np.random.shuffle(test_idx) 42 | X_train = X[train_idx] 43 | X_val=X[val_idx] 44 | X_test = X[test_idx] 45 | # transfor the label form to one-hot 46 | def to_onehot(yy): 47 | # yy1 = np.zeros([len(yy), max(yy)+1]) 48 | yy1 = np.zeros([len(yy), len(mods)]) 49 | yy1[np.arange(len(yy)), yy] = 1 50 | return yy1 51 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 52 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 53 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 54 | 55 | X_train = X_train.swapaxes(2, 1) 56 | X_val = X_val.swapaxes(2, 1) 57 | X_test = X_test.swapaxes(2, 1) 58 | 59 | print(X_train.shape) 60 | print(X_val.shape) 61 | print(X_test.shape) 62 | print(Y_train.shape) 63 | print(Y_val.shape) 64 | print(Y_test.shape) 65 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 66 | 67 | if __name__ == '__main__': 68 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 69 | -------------------------------------------------------------------------------- /RML201610b/PET-CGDNN/rmldataset2016.py: -------------------------------------------------------------------------------- 1 | "Adapted from the code (https://github.com/leena201818/radiom) contributed by leena201818" 2 | import pickle 3 | import numpy as np 4 | from numpy import linalg as la 5 | 6 | maxlen=128 7 | def load_data(filename=r'./RML2016.10b.dat'): 8 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd(120W,2,128) 10calss*20SNR*6000samples 9 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] #mods['8PSK', 'AM-DSB', 'BPSK', 'CPFSK', 'GFSK', 'PAM4', 'QAM16', 'QAM64', 'QPSK', 'WBFM'] 10 | X = [] 11 | lbl = [] 12 | train_idx=[] 13 | val_idx=[] 14 | np.random.seed(2016) 15 | a=0 16 | 17 | for mod in mods: 18 | for snr in snrs: 19 | X.append(Xd[(mod,snr)]) #ndarray(6000,2,128) 20 | for i in range(Xd[(mod,snr)].shape[0]): 21 | lbl.append((mod,snr)) 22 | train_idx+=list(np.random.choice(range(a*6000,(a+1)*6000), size=3600, replace=False)) 23 | val_idx+=list(np.random.choice(list(set(range(a*6000,(a+1)*6000))-set(train_idx)), size=1200, replace=False)) 24 | a+=1 25 | X = np.vstack(X) 26 | n_examples=X.shape[0] 27 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 28 | np.random.shuffle(train_idx) 29 | np.random.shuffle(val_idx) 30 | np.random.shuffle(test_idx) 31 | X_train = X[train_idx] 32 | X_val=X[val_idx] 33 | X_test = X[test_idx] 34 | # transfor the label form to one-hot 35 | def to_onehot(yy): 36 | # yy1 = np.zeros([len(yy), max(yy)+1]) 37 | yy1 = np.zeros([len(yy), len(mods)]) 38 | yy1[np.arange(len(yy)), yy] = 1 39 | return yy1 40 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 41 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 42 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 43 | 44 | X_train = X_train.swapaxes(2, 1) 45 | X_val = X_val.swapaxes(2, 1) 46 | X_test = X_test.swapaxes(2, 1) 47 | print(X_train.shape) 48 | print(X_val.shape) 49 | print(X_test.shape) 50 | print(Y_train.shape) 51 | print(Y_val.shape) 52 | print(Y_test.shape) 53 | 54 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 55 | 56 | if __name__ == '__main__': 57 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 58 | -------------------------------------------------------------------------------- /RML201610b/PET-CGDNN/rmlmodels/PETCGDNN.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | import tensorflow as tf 11 | WEIGHTS_PATH = ('resnet_like_weights_tf_dim_ordering_tf_kernels.h5') 12 | import math 13 | from keras.models import Model 14 | from keras.layers import Input, Dense, Conv1D, MaxPool1D, ReLU, Dropout, Softmax, concatenate, Flatten, Reshape, \ 15 | GaussianNoise,Activation 16 | from keras.layers.convolutional import Conv2D 17 | from keras.layers import CuDNNLSTM,Lambda,Multiply,Add,Subtract,MaxPool2D,CuDNNGRU,LeakyReLU,BatchNormalization 18 | import tensorflow as tf 19 | 20 | def cal1(x): 21 | y = tf.keras.backend.cos(x) 22 | return y 23 | 24 | def cal2(x): 25 | y = tf.keras.backend.sin(x) 26 | return y 27 | 28 | def PETCGDNN(weights=None, 29 | input_shape=[128, 2], 30 | input_shape2=[128], 31 | classes=10, 32 | **kwargs): 33 | if weights is not None and not (os.path.exists(weights)): 34 | raise ValueError('The `weights` argument should be either ' 35 | '`None` (random initialization), ' 36 | 'or the path to the weights file to be loaded.') 37 | 38 | dr = 0.5 # dropout rate (%) 39 | input = Input(input_shape+[1], name='input1') 40 | input1 = Input(input_shape2, name='input2') 41 | input2 = Input(input_shape2, name='input3') 42 | 43 | x1 = Flatten()(input) 44 | x1 = Dense(1, name='fc2',activation="linear")(x1) 45 | x1 = Activation('linear')(x1) 46 | 47 | cos1= Lambda(cal1)(x1) 48 | sin1 = Lambda(cal2)(x1) 49 | x11 = Multiply()([input1, cos1]) 50 | x12 = Multiply()([input2, sin1]) 51 | x21 = Multiply()([input2, cos1]) 52 | x22 = Multiply()([input1, sin1]) 53 | y1 = Add()([x11,x12]) 54 | y2 = Subtract()([x21,x22]) 55 | y1 = Reshape(target_shape=(128, 1), name='reshape1')(y1) 56 | y2 = Reshape(target_shape=(128, 1), name='reshape2')(y2) 57 | x11 = concatenate([y1, y2]) 58 | x3 = Reshape(target_shape=((128, 2, 1)), name='reshape3')(x11) 59 | 60 | # spatial feature 61 | x3 = Conv2D(75, (8,2), padding='valid', activation="relu", name="conv1_1", kernel_initializer='glorot_uniform')( 62 | x3) 63 | x3 = Conv2D(25, (5,1), padding='valid', activation="relu", name="conv1_2", kernel_initializer='glorot_uniform')( 64 | x3) 65 | 66 | # temporal feature 67 | x4 = Reshape(target_shape=((117,25)), name='reshape4')(x3) 68 | x4= CuDNNGRU(units=128)(x4) 69 | 70 | x = Dense(classes, activation='softmax', name='softmax')(x4) 71 | 72 | model = Model(inputs = [input,input1,input2], outputs=x) 73 | 74 | # Load weights. 75 | if weights is not None: 76 | model.load_weights(weights) 77 | 78 | return model 79 | 80 | 81 | import keras 82 | from keras.utils.vis_utils import plot_model 83 | 84 | if __name__ == '__main__': 85 | model = PETCGDNN(None, classes=10) 86 | 87 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 88 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 89 | plot_model(model, to_file='model.png', show_shapes=True) # print model 90 | print('models layers:', model.layers) 91 | print('models config:', model.get_config()) 92 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML201610b/ResNet/dataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | 5 | 6 | def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code1080ti-experiment\data\RML2016.10b.dat'): 7 | # def load_data(filename=r'/home/xujialang/ZhangFuXin/AMR/tranining/RML2016.10b.dat'): 8 | # Xd1 = pickle.load(open(filename1,'rb'),encoding='iso-8859-1')#Xd1.keys() mod中没有AM-SSB Xd1(120W,2,128) 9 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 10 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 11 | X = [] 12 | # X2=[] 13 | lbl = [] 14 | # lbl2=[] 15 | train_idx=[] 16 | val_idx=[] 17 | np.random.seed(2016) 18 | a=0 19 | 20 | for mod in mods: 21 | for snr in snrs: 22 | X.append(Xd[(mod,snr)]) #ndarray(6000,2,128) 23 | for i in range(Xd[(mod,snr)].shape[0]): 24 | lbl.append((mod,snr)) 25 | train_idx+=list(np.random.choice(range(a*6000,(a+1)*6000), size=3600, replace=False)) 26 | val_idx+=list(np.random.choice(list(set(range(a*6000,(a+1)*6000))-set(train_idx)), size=1200, replace=False)) 27 | a+=1 28 | X = np.vstack(X) #(220000,2,128) mods * snr * 6000,total 220000 samples 29 | # X2=np.vstack(X2) #(162060,2,128) 30 | print(len(lbl)) 31 | n_examples=X.shape[0] 32 | # n_test=X2.shape[0] 33 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 34 | np.random.shuffle(train_idx) 35 | np.random.shuffle(val_idx) 36 | np.random.shuffle(test_idx) 37 | # test_idx=np.random.choice(range(0,n_test),size=n_test,replace=False) 38 | X_train = X[train_idx] 39 | X_val=X[val_idx] 40 | X_test = X[test_idx] 41 | print(len(train_idx)) 42 | print(len(val_idx)) 43 | print(len(test_idx)) 44 | 45 | print(X_train.shape) 46 | print(X_val.shape) 47 | print(X_test.shape) 48 | def to_onehot(yy): 49 | # yy1 = np.zeros([len(yy), max(yy)+1]) 50 | yy1 = np.zeros([len(yy), len(mods)]) 51 | yy1[np.arange(len(yy)), yy] = 1 52 | return yy1 53 | 54 | # yy = list(map(lambda x: mods.index(lbl[x][0]), train_idx)) 55 | 56 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 57 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 58 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 59 | 60 | print(Y_train.shape) 61 | print(Y_val.shape) 62 | print(Y_test.shape) 63 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 64 | 65 | if __name__ == '__main__': 66 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 67 | -------------------------------------------------------------------------------- /RML201610b/ResNet/rmlmodels/ResNet.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | from keras.models import Model 12 | from keras.layers import Input,Dense,ReLU,Dropout,Activation,concatenate,Softmax,Conv2D,MaxPool2D,Add,BatchNormalization 13 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 14 | from keras.utils.vis_utils import plot_model 15 | 16 | def ResNet(weights=None, 17 | input_shape=[2,128], 18 | classes=10, 19 | **kwargs): 20 | if weights is not None and not (os.path.exists(weights)): 21 | raise ValueError('The `weights` argument should be either ' 22 | '`None` (random initialization), ' 23 | 'or the path to the weights file to be loaded.') 24 | dr=0.6 25 | input = Input(input_shape+[1],name='input') 26 | 27 | x=Conv2D(256,(1,3), name="conv1",kernel_initializer='glorot_uniform', padding='same')(input) 28 | x = Activation('relu')(x) 29 | # x = Dropout(dr)(x) 30 | x=Conv2D(256,(2,3), name="conv2", kernel_initializer='glorot_uniform',padding='same')(x) 31 | # x = Dropout(dr)(x) 32 | x1 = Add()([input, x]) 33 | x1 = Activation('relu')(x1) 34 | x=Conv2D(80,(1,3), activation="relu", name="conv3", kernel_initializer='glorot_uniform',padding='same')(x1) 35 | x=Conv2D(80,(1,3), activation="relu", name="conv4", kernel_initializer='glorot_uniform',padding='same')(x) 36 | x = Dropout(dr)(x) 37 | x=Flatten()(x) 38 | x = Dense(128, activation='relu', name='fc1')(x) 39 | x = Dropout(dr)(x) 40 | output = Dense(classes, activation='softmax', name='softmax')(x) 41 | 42 | model = Model(inputs = input,outputs = output) 43 | 44 | # Load weights. 45 | if weights is not None: 46 | model.load_weights(weights) 47 | 48 | return model 49 | 50 | import keras 51 | if __name__ == '__main__': 52 | model = ResNet(None,input_shape=[2,128],classes=10) 53 | 54 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 55 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 56 | 57 | print('models layers:', model.layers) 58 | print('models config:', model.get_config()) 59 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML2018/1DCNN-PF/rmlmodels/DCNNPF.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | WEIGHTS_PATH = ('resnet_like_weights_tf_dim_ordering_tf_kernels.h5') 4 | 5 | from keras.models import Model 6 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,concatenate,Flatten,Reshape 7 | from keras.layers.convolutional import Conv2D 8 | from keras.layers import CuDNNLSTM 9 | 10 | 11 | def DCNNPF(weights=None, 12 | input_shape=[1024], 13 | classes=24, 14 | **kwargs): 15 | if weights is not None and not (os.path.exists(weights)): 16 | raise ValueError('The `weights` argument should be either ' 17 | '`None` (random initialization), ' 18 | 'or the path to the weights file to be loaded.') 19 | 20 | dr = 0.5 # dropout rate (%) 21 | tap = 8 22 | 23 | input1 =Input(input_shape,name='input1') 24 | Reshape1=Reshape(input_shape+[1])(input1) 25 | input2=Input(input_shape,name='input2') 26 | Reshape2=Reshape(input_shape+[1])(input2) 27 | #Cnvolutional Block 28 | # L = 4 29 | # for i in range(L): 30 | # x = ConvBNReluUnit(x,kernel_size = tap,index=i) 31 | 32 | # SeparateChannel Combined Convolutional Neural Networks 33 | 34 | x2=Conv1D(64,3, activation="relu" )(Reshape1) 35 | x2=Dropout(0.2)(x2) 36 | x2=Conv1D(64,3, activation="relu" )(x2) 37 | x2=Dropout(0.2)(x2) 38 | x2=Conv1D(64,3, activation="relu" )(x2) 39 | x2=Dropout(0.2)(x2) 40 | x2=Conv1D(64,3, activation="relu" )(x2) 41 | x2=Dropout(0.2)(x2) 42 | 43 | x3=Conv1D(64,3, activation="relu" )(Reshape2) 44 | x3=Dropout(0.2)(x3) 45 | x3=Conv1D(64,3, activation="relu" )(x3) 46 | x3=Dropout(0.2)(x3) 47 | x3=Conv1D(64,3, activation="relu" )(x3) 48 | x3=Dropout(0.2)(x3) 49 | x3=Conv1D(64,3, activation="relu" )(x3) 50 | x3=Dropout(0.2)(x3) 51 | 52 | x=concatenate([x2,x3]) 53 | x=Conv1D(64,3, activation="relu" )(x) 54 | x=Dropout(0.2)(x) 55 | x=MaxPool1D(pool_size=2)(x) 56 | x=Conv1D(64,3, activation="relu")(x) 57 | x=Dropout(0.2)(x) 58 | x=MaxPool1D(pool_size=2)(x) 59 | x=Conv1D(64,3, activation="relu")(x) 60 | x=Dropout(0.2)(x) 61 | x=MaxPool1D(pool_size=2)(x) 62 | x=Conv1D(64,3, activation="relu")(x) 63 | x=Dropout(0.2)(x) 64 | x=MaxPool1D(pool_size=2)(x) 65 | x=Conv1D(64,3, activation="relu")(x) 66 | x=Dropout(0.2)(x) 67 | x=MaxPool1D(pool_size=2)(x) 68 | x=Flatten()(x) 69 | x = Dense(128,activation='selu',name='fc1')(x) 70 | x=Dropout(dr)(x) 71 | x = Dense(128,activation='selu',name='fc2')(x) 72 | x=Dropout(dr)(x) 73 | x = Dense(classes,activation='softmax',name='softmax')(x) 74 | 75 | model = Model(inputs = [input1,input2],outputs = x) 76 | 77 | # Load weights. 78 | if weights is not None: 79 | model.load_weights(weights) 80 | 81 | return model 82 | 83 | import keras 84 | from keras.utils.vis_utils import plot_model 85 | if __name__ == '__main__': 86 | model = DCNNPF(None,classes=11) 87 | 88 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 89 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 90 | #plot_model(model, to_file='model.png',show_shapes=True) # print model 91 | print('models layers:', model.layers) 92 | print('models config:', model.get_config()) 93 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML2018/CGDNet/rmlmodels/CGDNN.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | import tensorflow as tf 11 | WEIGHTS_PATH = ('resnet_like_weights_tf_dim_ordering_tf_kernels.h5') 12 | import math 13 | from keras.models import Model 14 | from keras.layers import Input, Dense, Conv1D, MaxPool1D, ReLU, Dropout, Softmax, concatenate, Flatten, Reshape, \ 15 | GaussianNoise,GaussianDropout 16 | from keras.layers.convolutional import Conv2D 17 | from keras.layers import CuDNNLSTM,Lambda,Multiply,Add,Subtract,MaxPool2D,CuDNNGRU,LeakyReLU,BatchNormalization 18 | import tensorflow as tf 19 | 20 | 21 | def CGDNN(weights=None, 22 | input_shape=[1, 2, 1024], 23 | classes=24, 24 | **kwargs): 25 | if weights is not None and not (os.path.exists(weights)): 26 | raise ValueError('The `weights` argument should be either ' 27 | '`None` (random initialization), ' 28 | 'or the path to the weights file to be loaded.') 29 | 30 | dr = 0.2 # dropout rate (%) 31 | input = Input(input_shape, name='input1') 32 | x1 = Conv2D(50, (1, 6), activation='relu', kernel_initializer='lecun_uniform', data_format="channels_first")(input) 33 | x1 = MaxPool2D(pool_size=(2, 2), strides=1, padding='same', data_format="channels_first")(x1) 34 | x1 = GaussianDropout(dr)(x1) 35 | x2 = Conv2D(50, (1, 6), activation='relu', kernel_initializer='glorot_uniform', data_format="channels_first")(x1) 36 | x2 = MaxPool2D(pool_size=(2, 2), strides=1, padding='same', data_format="channels_first")(x2) 37 | x2 = GaussianDropout(dr)(x2) 38 | x3 = Conv2D(50, (1, 6), activation='relu', kernel_initializer='glorot_uniform', data_format="channels_first")(x2) 39 | x3 = MaxPool2D(pool_size=(2, 2), strides=1, padding='same', data_format="channels_first")(x3) 40 | x3 = GaussianDropout(dr)(x3) 41 | x11 = concatenate([x1, x3], 3) 42 | x4 = Reshape(target_shape=((50, 4056)), name='reshape4')(x11) 43 | x4 = CuDNNGRU(units=50)(x4) 44 | x4 = GaussianDropout(dr)(x4) 45 | x = Dense(256, activation='relu', name='fc4',kernel_initializer='he_normal')(x4) 46 | x = GaussianDropout(dr)(x) 47 | x = Dense(classes, activation='softmax', name='softmax')(x) 48 | model = Model(inputs=input, outputs=x) 49 | 50 | # Load weights. 51 | if weights is not None: 52 | model.load_weights(weights) 53 | 54 | return model 55 | 56 | 57 | import keras 58 | from keras.utils.vis_utils import plot_model 59 | 60 | if __name__ == '__main__': 61 | model = CGDNN(None, classes=10) 62 | 63 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 64 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 65 | plot_model(model, to_file='model.png', show_shapes=True) # print model 66 | print('models layers:', model.layers) 67 | print('models config:', model.get_config()) 68 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML2018/CLDNN/rmlmodels/CLDNNLikeModel.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | import numpy as np 11 | 12 | from keras.models import Model 13 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,concatenate,Conv2D 14 | from keras.layers import LSTM,Permute,Reshape,ZeroPadding2D,Activation 15 | 16 | 17 | 18 | 19 | def CLDNNLikeModel(weights=None, 20 | input_shape1=[2,1024], 21 | classes=24, 22 | **kwargs): 23 | if weights is not None and not (os.path.exists(weights)): 24 | raise ValueError('The `weights` argument should be either ' 25 | '`None` (random initialization), ' 26 | 'or the path to the weights file to be loaded.') 27 | 28 | # %% 29 | dr = 0.5 # dropout rate (%) 卷积层部分 https://keras-cn.readthedocs.io/en/latest/layers/convolutional_layer/#conv2d 30 | 31 | # 这里使用keras的函数式编程 http://keras-cn.readthedocs.io/en/latest/getting_started/functional_API/ 32 | # Reshape [N,2,128] to [N,1,2,128] on input 33 | input_x = Input(shape=(1, 2, 1024)) 34 | 35 | # 卷积核维度(输出尺度),卷积核的宽度和长度,“valid”代表只进行有效的卷积,即对边界数据不处理, 36 | # 层权重weights的初始化函数 37 | # channels_first corresponds to inputs with shape (batch, channels, height, width). 38 | 39 | input_x_padding = ZeroPadding2D((0, 2), data_format="channels_first")(input_x) 40 | 41 | layer11 = Conv2D(50, (1, 8), padding='valid', activation="relu", name="conv11", init='glorot_uniform', 42 | data_format="channels_first")(input_x_padding) 43 | layer11 = Dropout(dr)(layer11) 44 | 45 | layer11_padding = ZeroPadding2D((0, 2), data_format="channels_first")(layer11) 46 | layer12 = Conv2D(50, (1, 8), padding="valid", activation="relu", name="conv12", init='glorot_uniform', 47 | data_format="channels_first")(layer11_padding) 48 | layer12 = Dropout(dr)(layer12) 49 | 50 | layer12 = ZeroPadding2D((0, 2), data_format="channels_first")(layer12) 51 | layer13 = Conv2D(50, (1, 8), padding='valid', activation="relu", name="conv13", init='glorot_uniform', 52 | data_format="channels_first")(layer12) 53 | layer13 = Dropout(dr)(layer13) 54 | 55 | # : (None, 50, 2, 242), 56 | concat = keras.layers.concatenate([layer11, layer13]) 57 | concat_size = list(np.shape(concat)) 58 | input_dim = int(concat_size[-1] * concat_size[-2]) 59 | timesteps = int(concat_size[-3]) 60 | # concat = np.reshape(concat, (-1,timesteps,input_dim)) 61 | concat = Reshape((timesteps, input_dim))(concat) 62 | # 形如(samples,timesteps,input_dim)的3D张量 63 | lstm_out = LSTM(50, input_dim=input_dim, input_length=timesteps)(concat) 64 | # 当 输出为250的时候正确里更高 65 | # lstm_out = LSTM(250, input_dim=input_dim, input_length=timesteps)(concat) 66 | 67 | # layer_Flatten = Flatten()(lstm_out) 68 | layer_dense1 = Dense(256, activation='relu', init='he_normal', name="dense1")(lstm_out) 69 | layer_dropout = Dropout(dr)(layer_dense1) 70 | layer_dense2 = Dense(24, init='he_normal', name="dense2")(layer_dropout) 71 | layer_softmax = Activation('softmax')(layer_dense2) 72 | output = Reshape([24])(layer_softmax) 73 | 74 | model = Model(inputs=input_x, outputs=output) 75 | 76 | # Load weights. 77 | if weights is not None: 78 | model.load_weights(weights) 79 | 80 | return model 81 | 82 | import keras 83 | if __name__ == '__main__': 84 | model = CLDNNLikeModel(None,input_shape=(2,1024),classes=24) 85 | 86 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 87 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 88 | 89 | print('models layers:', model.layers) 90 | print('models config:', model.get_config()) 91 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML2018/CLDNN2/rmlmodels/CLDNNLikeModel.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | import numpy as np 11 | 12 | from keras.models import Model 13 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,concatenate,Conv2D 14 | from keras.layers import LSTM,Permute,Reshape,ZeroPadding2D,Activation 15 | 16 | 17 | 18 | 19 | def CLDNNLikeModel(weights=None, 20 | input_shape1=[2,1024], 21 | classes=11, 22 | **kwargs): 23 | if weights is not None and not (os.path.exists(weights)): 24 | raise ValueError('The `weights` argument should be either ' 25 | '`None` (random initialization), ' 26 | 'or the path to the weights file to be loaded.') 27 | 28 | dr = 0.5 29 | input_x = Input(input_shape1+[1],name='input') 30 | x = Conv2D(256, (1, 3), activation="relu", name="conv1", init='glorot_uniform')(input_x) # (b,c,h,w) (b,h,w,c) 31 | x = Dropout(dr)(x) 32 | x = Conv2D(256, (2, 3), activation="relu", name="conv2", init='glorot_uniform')(x) # (b,c,h,w) (b,h,w,c) 33 | x = Dropout(dr)(x) 34 | x = Conv2D(80, (1, 3), activation="relu", name="conv3", init='glorot_uniform')(x) # (b,c,h,w) (b,h,w,c) 35 | x = Dropout(dr)(x) 36 | x = Conv2D(80, (1, 3), activation="relu", name="conv4", init='glorot_uniform')(x) # (b,c,h,w) (b,h,w,c) 37 | x = Dropout(dr)(x) 38 | # 形如(samples,timesteps,input_dim)的3D张量 39 | x1 = Reshape((80, 1016))(x) 40 | lstm_out = LSTM(units=50)(x1) 41 | 42 | # layer_Flatten = Flatten()(lstm_out) 43 | x = Dense(128, activation='relu', name="dense1")(lstm_out) 44 | x = Dropout(dr)(x) 45 | output = Dense(24, activation='softmax',name="dense2")(x) 46 | 47 | model = Model(inputs=input_x, outputs=output) 48 | 49 | # Load weights. 50 | if weights is not None: 51 | model.load_weights(weights) 52 | 53 | return model 54 | 55 | import keras 56 | if __name__ == '__main__': 57 | model = CLDNNLikeModel(None,input_shape=(2,1024),classes=24) 58 | 59 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 60 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 61 | 62 | print('models layers:', model.layers) 63 | print('models config:', model.get_config()) 64 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML2018/CNN1/rmlmodels/CNN2Model.py: -------------------------------------------------------------------------------- 1 | import os 2 | os.environ["KERAS_BACKEND"] = "tensorflow" 3 | # os.environ["THEANO_FLAGS"] = "device=gpu%d"%(0) 4 | import numpy as np 5 | import keras.models as models 6 | from keras.layers.core import Reshape,Dense,Dropout,Activation,Flatten 7 | from keras.layers.convolutional import Convolution2D,Conv2D, MaxPooling2D, ZeroPadding2D 8 | from keras.layers.core import Activation 9 | 10 | 11 | def CNN2Model(weights=None, 12 | input_shape=[2,1024], 13 | classes=24, 14 | **kwargs): 15 | if weights is not None and not (os.path.exists(weights)): 16 | raise ValueError('The `weights` argument should be either ' 17 | '`None` (random initialization), ' 18 | 'or the path to the weights file to be loaded.') 19 | dr = 0.5 # dropout rate (%) 20 | model = models.Sequential() 21 | model.add(Reshape(input_shape + [1], input_shape=input_shape)) 22 | model.add(Convolution2D(50, (1, 8), padding='same', activation="relu", name="conv1", kernel_initializer='glorot_uniform')) 23 | model.add(Dropout(dr)) 24 | model.add(Convolution2D(50, (2, 8), padding="valid", activation="relu", name="conv2", kernel_initializer='glorot_uniform')) 25 | model.add(Dropout(dr)) 26 | model.add(Flatten()) 27 | model.add(Dense(256, activation='relu', kernel_initializer='he_normal', name="dense1")) 28 | model.add(Dropout(dr)) 29 | model.add(Dense( classes, kernel_initializer='he_normal', name="dense2" )) 30 | model.add(Activation('softmax')) 31 | 32 | 33 | # Load weights. 34 | if weights is not None: 35 | model.load_weights(weights) 36 | 37 | return model 38 | 39 | if __name__ == '__main__': 40 | print(CNN2Model().summary()) 41 | -------------------------------------------------------------------------------- /RML2018/CNN2/dataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | 4 | 5 | 6 | def load_data(filename=r'D:\OneDrive - std.uestc.edu.cn\研究生\First_thesisl_A Spatiotemporal Multi-Channel Learning\Thesis_code_20200415\RML201610a\LSTM2\data\RML2016.10a_dict.pkl'): 7 | 8 | # Xd1 = pickle.load(open(filename1,'rb'),encoding='iso-8859-1')#Xd1.keys() mod中没有AM-SSB Xd1(120W,2,128) 9 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 10 | # Xd3=pickle.load(open(filename3,'rb'),encoding='iso-8859-1')#04c(162060,2,128) 11 | # snrs,mods = map(lambda j: sorted(list(set(map(lambda x: x[j], Xd.keys())))), [1,0]) 12 | # same with the following without using map function,but 'for' method 13 | # mods = set([ k[0] for k in Xd.keys()]) 14 | # mods = list(mods) 15 | # mods = sorted(mods) 16 | # 17 | # snrs = sorted(list(set([k[1] for print(len(Xd[:].shape[0])) 18 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 19 | X = [] 20 | # X2=[] 21 | lbl = [] 22 | # lbl2=[] 23 | train_idx=[] 24 | val_idx=[] 25 | np.random.seed(2016) 26 | a=0 27 | 28 | for mod in mods: 29 | for snr in snrs: 30 | X.append(Xd[(mod,snr)]) #ndarray(1000,2,128) 31 | for i in range(Xd[(mod,snr)].shape[0]): 32 | lbl.append((mod,snr)) 33 | train_idx+=list(np.random.choice(range(a*1000,(a+1)*1000), size=600, replace=False)) 34 | val_idx+=list(np.random.choice(list(set(range(a*1000,(a+1)*1000))-set(train_idx)), size=200, replace=False)) 35 | a+=1 36 | X = np.vstack(X) #(220000,2,128) mods * snr * 1000,total 220000 samples 37 | # X2=np.vstack(X2) #(162060,2,128) 38 | print(len(lbl)) 39 | # Partition the data 40 | # into training and test sets of the form we can train/test on 41 | # while keeping SNR and Mod labels handy for each 42 | n_examples=X.shape[0] 43 | # n_test=X2.shape[0] 44 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 45 | np.random.shuffle(train_idx) 46 | np.random.shuffle(val_idx) 47 | np.random.shuffle(test_idx) 48 | # test_idx=np.random.choice(range(0,n_test),size=n_test,replace=False) 49 | X_train = X[train_idx] 50 | X_val=X[val_idx] 51 | X_test = X[test_idx] 52 | print(len(train_idx)) 53 | print(len(val_idx)) 54 | print(len(test_idx)) 55 | 56 | print(X_train.shape) 57 | print(X_val.shape) 58 | print(X_test.shape) 59 | def to_onehot(yy): 60 | # yy1 = np.zeros([len(yy), max(yy)+1]) 61 | yy1 = np.zeros([len(yy), len(mods)]) 62 | yy1[np.arange(len(yy)), yy] = 1 63 | return yy1 64 | 65 | # yy = list(map(lambda x: mods.index(lbl[x][0]), train_idx)) 66 | 67 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 68 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 69 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 70 | 71 | print(Y_train.shape) 72 | print(Y_val.shape) 73 | print(Y_test.shape) 74 | 75 | # Y_one_hot = np.zeros([len(lbl),len(mods)]) 76 | # for i in range(len(lbl)): 77 | # Y_one_hot[i,mods.index(lbl[i][0])] = 1. 78 | # 79 | # Y_train2 = Y_one_hot[train_idx] 80 | # Y_test2 = Y_one_hot[test_idx] 81 | # 82 | # print( np.all(Y_test2 == Y_test) ) 83 | #X_train=X_train.swapaxes(2,1) 84 | #X_val=X_val.swapaxes(2,1) 85 | #X_test=X_test.swapaxes(2,1) 86 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 87 | 88 | if __name__ == '__main__': 89 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 90 | -------------------------------------------------------------------------------- /RML2018/CNN2/rmlmodels/CNN.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from keras.models import Model 4 | from keras.layers import Input,Dense,ReLU,Dropout,Softmax,Conv2D,MaxPool2D 5 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 6 | from keras.utils.vis_utils import plot_model 7 | 8 | def CNN(weights=None, 9 | input_shape=[2,1024], 10 | classes=11, 11 | **kwargs): 12 | if weights is not None and not (os.path.exists(weights)): 13 | raise ValueError('The `weights` argument should be either ' 14 | '`None` (random initialization), ' 15 | 'or the path to the weights file to be loaded.') 16 | 17 | input = Input(input_shape+[1],name='input') 18 | x = input 19 | 20 | x=Conv2D(256,(2,8),padding='same', activation="relu", name="conv1", kernel_initializer='glorot_uniform')(input) 21 | x=MaxPool2D(pool_size=(1,2))(x) 22 | x=Dropout(0.5)(x) 23 | x=Conv2D(128,(2,8),padding='same', activation="relu", name="conv2", kernel_initializer='glorot_uniform')(x) 24 | x=MaxPool2D(pool_size=(1,2))(x) 25 | x=Dropout(0.5)(x) 26 | x=Conv2D(64,(2,8),padding='same', activation="relu", name="conv3", kernel_initializer='glorot_uniform')(x) 27 | x=MaxPool2D(pool_size=(1,2))(x) 28 | x=Dropout(0.5)(x) 29 | x=Conv2D(64,(2,8),padding='same', activation="relu", name="conv4", kernel_initializer='glorot_uniform')(x) 30 | x=MaxPool2D(pool_size=(1,2))(x) 31 | x=Dropout(0.5)(x) 32 | x=Flatten()(x) 33 | x = Dense(128,activation='relu',name='dense1')(x) 34 | x = Dense(24,activation='softmax',name='dense2')(x) 35 | 36 | model = Model(inputs = input,outputs = x) 37 | 38 | # Load weights. 39 | if weights is not None: 40 | model.load_weights(weights) 41 | 42 | return model 43 | 44 | import keras 45 | if __name__ == '__main__': 46 | model = CNN(None,input_shape=[2,1024],classes=24) 47 | 48 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 49 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 50 | 51 | print('models layers:', model.layers) 52 | print('models config:', model.get_config()) 53 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML2018/DAE/rmlmodels/DAE.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from keras.models import Model 4 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,BatchNormalization,TimeDistributed 5 | from keras.layers import LSTM,CuDNNLSTM,Bidirectional,Flatten,LSTM,Reshape,Lambda 6 | from keras.utils.vis_utils import plot_model 7 | 8 | def DAE(weights=None, 9 | input_shape=[1024,2], 10 | classes=24, 11 | **kwargs): 12 | if weights is not None and not (os.path.exists(weights)): 13 | raise ValueError('The `weights` argument should be either ' 14 | '`None` (random initialization), ' 15 | 'or the path to the weights file to be loaded.') 16 | 17 | input = Input(input_shape,name='input') 18 | x = input 19 | dr=0 20 | #LSTM Unit 21 | x,s,c = CuDNNLSTM(units=32,return_state = True,return_sequences = True)(x) 22 | x = Dropout(dr)(x) 23 | x,s1,c1 = CuDNNLSTM(units=32,return_state = True,return_sequences = True)(x) 24 | #Classifier 25 | xc = Dense(32,activation='relu')(s1) 26 | xc = BatchNormalization()(xc) 27 | xc = Dropout(dr)(xc) 28 | xc = Dense(16,activation='relu')(xc) 29 | xc = BatchNormalization()(xc) 30 | xc = Dropout(dr)(xc) 31 | xc = Dense(classes,activation='softmax',name='xc')(xc) 32 | 33 | #Decoder 34 | xd = TimeDistributed(Dense(2),name='xd')(x) 35 | 36 | model = Model(inputs = input,outputs = [xc,xd]) 37 | 38 | # Load weights. 39 | if weights is not None: 40 | model.load_weights(weights) 41 | 42 | return model -------------------------------------------------------------------------------- /RML2018/DAE/rmlmodels/__pycache__/CuDNNLSTMModel.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML2018/DAE/rmlmodels/__pycache__/CuDNNLSTMModel.cpython-36.pyc -------------------------------------------------------------------------------- /RML2018/DenseNet/rmlmodels/DenseNet.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from keras.models import Model 4 | from keras.layers import Input,Dense,ReLU,Dropout,Softmax,Conv2D,MaxPool2D,Add,concatenate,Activation 5 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 6 | from keras.utils.vis_utils import plot_model 7 | 8 | def DenseNet(weights=None, 9 | input_shape=[2,1024], 10 | classes=24, 11 | **kwargs): 12 | if weights is not None and not (os.path.exists(weights)): 13 | raise ValueError('The `weights` argument should be either ' 14 | '`None` (random initialization), ' 15 | 'or the path to the weights file to be loaded.') 16 | dr=0.6 17 | input = Input(input_shape+[1],name='input') 18 | x=Conv2D(256,(1,3), activation="relu", name="conv1", padding='same')(input) 19 | x1=Conv2D(256,(2,3), name="conv2", padding='same')(x) 20 | x2 = concatenate([x, x1]) 21 | x2 = Activation('relu')(x2) 22 | x3=Conv2D(80,(1,3), name="conv3", padding='same')(x2) 23 | x4 = concatenate([x, x1, x3]) 24 | x4 = Activation('relu')(x4) 25 | x=Conv2D(80,(1,3), activation="relu", name="conv4", padding='same')(x4) 26 | x = Dropout(dr)(x) 27 | x=Flatten()(x) 28 | 29 | x = Dense(128, activation='relu', name='fc1')(x) 30 | x = Dropout(dr)(x) 31 | x = Dense(classes, activation='softmax', name='softmax')(x) 32 | 33 | model = Model(inputs = input,outputs = x) 34 | 35 | # Load weights. 36 | if weights is not None: 37 | model.load_weights(weights) 38 | 39 | return model 40 | 41 | import keras 42 | if __name__ == '__main__': 43 | model = DenseNet(None,input_shape=[2,128],classes=11) 44 | 45 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 46 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 47 | 48 | print('models layers:', model.layers) 49 | print('models config:', model.get_config()) 50 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML2018/GRU2/rmlmodels/GRUModel.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from keras.models import Model 4 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax 5 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 6 | from keras.utils.vis_utils import plot_model 7 | 8 | def GRUModel(weights=None, 9 | input_shape=[1024,2], 10 | classes=24, 11 | **kwargs): 12 | if weights is not None and not (os.path.exists(weights)): 13 | raise ValueError('The `weights` argument should be either ' 14 | '`None` (random initialization), ' 15 | 'or the path to the weights file to be loaded.') 16 | 17 | input = Input(input_shape,name='input') 18 | x = input 19 | 20 | #LSTM Unit 21 | x = CuDNNGRU(units=128,return_sequences = True)(x) 22 | x = CuDNNGRU(units=128)(x) 23 | 24 | #DNN 25 | x = Dense(classes,activation='softmax',name='softmax')(x) 26 | 27 | model = Model(inputs = input,outputs = x) 28 | 29 | # Load weights. 30 | if weights is not None: 31 | model.load_weights(weights) 32 | 33 | return model 34 | 35 | import keras 36 | if __name__ == '__main__': 37 | model = GRUModel(None,input_shape=(128,2),classes=11) 38 | 39 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 40 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 41 | plot_model(model, to_file='model.png',show_shapes=True) # print model 42 | 43 | print('models layers:', model.layers) 44 | print('models config:', model.get_config()) 45 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML2018/IC-AMCNet/rmlmodels/ICAMC.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from keras.models import Model 4 | from keras.layers import Input,Dense,ReLU,Dropout,Softmax,Conv2D,MaxPool2D,Lambda,GaussianNoise 5 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 6 | from keras.utils.vis_utils import plot_model 7 | 8 | def ICAMC(weights=None, 9 | input_shape=[2,1024], 10 | classes=24, 11 | **kwargs): 12 | if weights is not None and not (os.path.exists(weights)): 13 | raise ValueError('The `weights` argument should be either ' 14 | '`None` (random initialization), ' 15 | 'or the path to the weights file to be loaded.') 16 | dr = 0.4 17 | input = Input(input_shape+[1],name='input') 18 | x=Conv2D(64,(1,8), activation="relu", name="conv1", padding='same', kernel_initializer='glorot_uniform')(input) 19 | x= MaxPool2D(pool_size=(2, 2))(x) 20 | x=Conv2D(64,(1,4), activation="relu", name="conv2", padding='same', kernel_initializer='glorot_uniform')(x) 21 | x=Conv2D(128,(1,8),activation="relu", name="conv3", padding='same', kernel_initializer='glorot_uniform')(x) 22 | x = MaxPool2D(pool_size=(1, 1))(x) 23 | x = Dropout(dr)(x) 24 | x=Conv2D(128,(1,8), activation="relu", name="conv4", padding='same', kernel_initializer='glorot_uniform')(x) 25 | x = Dropout(dr)(x) 26 | x=Flatten()(x) 27 | x = Dense(128,activation='relu',name='dense1')(x) 28 | x=Dropout(dr)(x) 29 | x = GaussianNoise(1)(x) 30 | x = Dense(24,activation='softmax',name='dense2')(x) 31 | 32 | model = Model(inputs = input,outputs = x) 33 | 34 | # Load weights. 35 | if weights is not None: 36 | model.load_weights(weights) 37 | 38 | return model 39 | 40 | import keras 41 | if __name__ == '__main__': 42 | model = ICAMC(None,input_shape=[2,128],classes=11) 43 | 44 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 45 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 46 | 47 | print('models layers:', model.layers) 48 | print('models config:', model.get_config()) 49 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML2018/LSTM2/rmlmodels/CuDNNLSTMModel.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from keras.models import Model 4 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax 5 | from keras.layers import LSTM,CuDNNLSTM,Bidirectional,Flatten,LSTM 6 | from keras.utils.vis_utils import plot_model 7 | 8 | def LSTMModel(weights=None, 9 | input_shape=[1024,2], 10 | classes=24, 11 | **kwargs): 12 | if weights is not None and not (os.path.exists(weights)): 13 | raise ValueError('The `weights` argument should be either ' 14 | '`None` (random initialization), ' 15 | 'or the path to the weights file to be loaded.') 16 | 17 | input = Input(input_shape,name='input') 18 | x = input 19 | 20 | #LSTM Unit 21 | x = CuDNNLSTM(units=128,return_sequences = True)(x) 22 | x = CuDNNLSTM(units=128)(x) 23 | 24 | #DNN 25 | x = Dense(classes,activation='softmax',name='softmax')(x) 26 | 27 | model = Model(inputs = input,outputs = x) 28 | 29 | # Load weights. 30 | if weights is not None: 31 | model.load_weights(weights) 32 | 33 | return model 34 | 35 | import keras 36 | if __name__ == '__main__': 37 | model = LSTMModel(None,input_shape=(128,2),classes=11) 38 | 39 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 40 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 41 | plot_model(model, to_file='model.png',show_shapes=True) # print model 42 | 43 | print('models layers:', model.layers) 44 | print('models config:', model.get_config()) 45 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML2018/MCLDNN/dataset2016.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import numpy as np 3 | def l2_normalize(x, axis=-1): 4 | y = np.max(np.sum(x ** 2, axis, keepdims=True), axis, keepdims=True) 5 | return x / np.sqrt(y) 6 | 7 | def load_data(filename=r'E:\Richard_zhangxx\My_Research\AMR\Thesis_code\Thesis_code\data\RML2016.10a_dict.pkl'): 8 | 9 | Xd =pickle.load(open(filename,'rb'),encoding='iso-8859-1')#Xd2(22W,2,128) 10 | mods,snrs = [sorted(list(set([k[j] for k in Xd.keys()]))) for j in [0,1] ] 11 | X = [] 12 | lbl = [] 13 | train_idx=[] 14 | val_idx=[] 15 | np.random.seed(2016) 16 | a=0 17 | 18 | for mod in mods: 19 | for snr in snrs: 20 | X.append(Xd[(mod,snr)]) #ndarray(1000,2,128) 21 | for i in range(Xd[(mod,snr)].shape[0]): 22 | lbl.append((mod,snr)) 23 | train_idx+=list(np.random.choice(range(a*1000,(a+1)*1000), size=600, replace=False)) 24 | val_idx+=list(np.random.choice(list(set(range(a*1000,(a+1)*1000))-set(train_idx)), size=200, replace=False)) 25 | a+=1 26 | X = np.vstack(X) #(220000,2,128) mods * snr * 1000,total 220000 samples chui zhi fang xiang dui die 27 | n_examples=X.shape[0] 28 | test_idx = list(set(range(0,n_examples))-set(train_idx)-set(val_idx)) 29 | np.random.shuffle(train_idx) 30 | np.random.shuffle(val_idx) 31 | np.random.shuffle(test_idx) 32 | X_train = X[train_idx] 33 | X_val=X[val_idx] 34 | X_test = X[test_idx] 35 | def to_onehot(yy): 36 | # yy1 = np.zeros([len(yy), max(yy)+1]) 37 | yy1 = np.zeros([len(yy), len(mods)]) 38 | yy1[np.arange(len(yy)), yy] = 1 39 | yy2=yy1 40 | return yy1 41 | Y_train = to_onehot(list(map(lambda x: mods.index(lbl[x][0]), train_idx))) 42 | Y_val=to_onehot(list(map(lambda x: mods.index(lbl[x][0]), val_idx))) 43 | Y_test = to_onehot(list(map(lambda x: mods.index(lbl[x][0]),test_idx))) 44 | 45 | # print(Y_train.shape) 46 | # print(Y_val.shape) 47 | # print(Y_test.shape) 48 | #X_train=X_train.swapaxes(2,1) 49 | #X_val=X_val.swapaxes(2,1) 50 | #X_test=X_test.swapaxes(2,1) 51 | return (mods,snrs,lbl),(X_train,Y_train),(X_val,Y_val),(X_test,Y_test),(train_idx,val_idx,test_idx) 52 | # 下的代码只有在第一种情况下(即文件作为脚本直接执行)才会被执行,而 import 到其他脚本中是不会被执行的 53 | if __name__ == '__main__': 54 | (mods, snrs, lbl), (X_train, Y_train),(X_val,Y_val), (X_test, Y_test), (train_idx,val_idx,test_idx) = load_data() 55 | -------------------------------------------------------------------------------- /RML2018/MCLDNN/rmlmodels/MCLDNN.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | 11 | WEIGHTS_PATH = ('resnet_like_weights_tf_dim_ordering_tf_kernels.h5') 12 | 13 | from keras.models import Model 14 | from keras.layers import Input,Dense,Conv1D,MaxPool1D,ReLU,Dropout,Softmax,concatenate,Flatten,Reshape 15 | from keras.layers.convolutional import Conv2D 16 | from keras.layers import CuDNNLSTM 17 | 18 | 19 | def MCLDNN(weights=None, 20 | input_shape1=[2,1024], 21 | input_shape2=[1024,1], 22 | classes=24, 23 | **kwargs): 24 | if weights is not None and not (os.path.exists(weights)): 25 | raise ValueError('The `weights` argument should be either ' 26 | '`None` (random initialization), ' 27 | 'or the path to the weights file to be loaded.') 28 | 29 | dr = 0.5 # dropout rate (%) 30 | tap = 8 31 | input1 =Input(input_shape1+[1],name='input1') 32 | input2 =Input(input_shape2,name='input2') 33 | input3=Input(input_shape2,name='input3') 34 | #Cnvolutional Block 35 | # L = 4 36 | # for i in range(L): 37 | # x = ConvBNReluUnit(x,kernel_size = tap,index=i) 38 | 39 | # SeparateChannel Combined Convolutional Neural Networks 40 | x1=Conv2D(50,(2,8),padding='same', activation="relu", name="conv1_1", kernel_initializer='glorot_uniform')(input1) 41 | x2=Conv1D(50,8,padding='causal', activation="relu", name="conv1_2", kernel_initializer='glorot_uniform')(input2) 42 | x2_reshape=Reshape([-1,1024,50])(x2) 43 | x3=Conv1D(50,8,padding='causal', activation="relu", name="conv1_3", kernel_initializer='glorot_uniform')(input3) 44 | x3_reshape=Reshape([-1,1024,50],name='reshap2')(x3) 45 | x=concatenate([x2_reshape,x3_reshape],axis=1) 46 | x=Conv2D(50,(1,8),padding='same', activation="relu", name="conv2", kernel_initializer='glorot_uniform')(x) 47 | x=concatenate([x1,x]) 48 | x=Conv2D(100,(2,5),padding='valid', activation="relu", name="conv4", kernel_initializer='glorot_uniform')(x) 49 | #LSTM Unit 50 | # batch_size,64,2 51 | x= Reshape(target_shape=((1020,100)),name='reshape')(x) 52 | x = CuDNNLSTM(units=128,return_sequences = True)(x) 53 | x = CuDNNLSTM(units=128)(x) 54 | 55 | #DNN 56 | x = Dense(128,activation='selu',name='fc1')(x) 57 | x=Dropout(dr)(x) 58 | x = Dense(128,activation='selu',name='fc2')(x) 59 | x=Dropout(dr)(x) 60 | x = Dense(classes,activation='softmax',name='softmax')(x) 61 | 62 | model = Model(inputs = [input1,input2,input3],outputs = x) 63 | 64 | # Load weights. 65 | if weights is not None: 66 | model.load_weights(weights) 67 | 68 | return model 69 | 70 | 71 | import keras 72 | from keras.utils.vis_utils import plot_model 73 | if __name__ == '__main__': 74 | model = MCLDNN(None,classes=10) 75 | 76 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 77 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 78 | plot_model(model, to_file='model.png',show_shapes=True) # print model 79 | print('models layers:', model.layers) 80 | print('models config:', model.get_config()) 81 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML2018/PET-CGDNN/rmlmodels/PETCGDNN.py: -------------------------------------------------------------------------------- 1 | """CLDNNLike model for RadioML. 2 | 3 | # Reference: 4 | 5 | - [CONVOLUTIONAL,LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS ] 6 | 7 | Adapted from code contributed by Mika. 8 | """ 9 | import os 10 | import tensorflow as tf 11 | WEIGHTS_PATH = ('resnet_like_weights_tf_dim_ordering_tf_kernels.h5') 12 | import math 13 | from keras.models import Model 14 | from keras.layers import Input, Dense, Conv1D, MaxPool1D, ReLU, Dropout, Softmax, concatenate, Flatten, Reshape, \ 15 | GaussianNoise 16 | from keras.layers.convolutional import Conv2D 17 | from keras.layers import CuDNNLSTM,Lambda,Multiply,Add,Subtract,MaxPool2D,CuDNNGRU,LeakyReLU,BatchNormalization 18 | import tensorflow as tf 19 | def l2_normalize(x): 20 | y = tf.keras.backend.max(tf.keras.backend.sum(x ** 2, -1, keepdims=True), -1, keepdims=True) 21 | return x / tf.keras.backend.sqrt(y) 22 | 23 | def cal1(x): 24 | y = tf.keras.backend.cos(x) 25 | return y 26 | 27 | def cal2(x): 28 | y = tf.keras.backend.sin(x) 29 | return y 30 | 31 | def PETCGDNN(weights=None, 32 | input_shape=[1024, 2], 33 | input_shape2=[1024], 34 | classes=24, 35 | **kwargs): 36 | if weights is not None and not (os.path.exists(weights)): 37 | raise ValueError('The `weights` argument should be either ' 38 | '`None` (random initialization), ' 39 | 'or the path to the weights file to be loaded.') 40 | 41 | dr = 0.5 # dropout rate (%) 42 | input = Input(input_shape+[1], name='input1') 43 | input1 = Input(input_shape2, name='input2') 44 | input2 = Input(input_shape2, name='input3') 45 | 46 | x1 = Flatten()(input) 47 | x1 = Dense(1, name='fc2',activation="linear")(x1) 48 | cos1= Lambda(cal1)(x1) 49 | sin1 = Lambda(cal2)(x1) 50 | x11 = Multiply()([input1, cos1]) 51 | x12 = Multiply()([input2, sin1]) 52 | x21 = Multiply()([input2, cos1]) 53 | x22 = Multiply()([input1, sin1]) 54 | y1 = Add()([x11,x12]) 55 | y2 = Subtract()([x21,x22]) 56 | y1 = Reshape(target_shape=(1024, 1), name='reshape1')(y1) 57 | y2 = Reshape(target_shape=(1024, 1), name='reshape2')(y2) 58 | x11 = concatenate([y1, y2]) 59 | x3 = Reshape(target_shape=((1024, 2, 1)), name='reshape3')(x11) 60 | 61 | # spatial feature 62 | x3 = Conv2D(75, (8,2), padding='valid', activation="relu", name="conv1_1", kernel_initializer='glorot_uniform')( 63 | x3) 64 | x3 = Conv2D(25, (5,1), padding='valid', activation="relu", name="conv1_2", kernel_initializer='glorot_uniform')( 65 | x3) 66 | # temporal feature 67 | x4 = Reshape(target_shape=((1013,25)), name='reshape4')(x3) 68 | x4= CuDNNGRU(units=128)(x4) 69 | 70 | x = Dense(classes, activation='softmax', name='softmax')(x4) 71 | 72 | model = Model(inputs = [input,input1,input2], outputs=x) 73 | 74 | # Load weights. 75 | if weights is not None: 76 | model.load_weights(weights) 77 | 78 | return model 79 | 80 | 81 | import keras 82 | from keras.utils.vis_utils import plot_model 83 | 84 | if __name__ == '__main__': 85 | model = CLDNN(None, classes=10) 86 | 87 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 88 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 89 | plot_model(model, to_file='model.png', show_shapes=True) # print model 90 | print('models layers:', model.layers) 91 | print('models config:', model.get_config()) 92 | print('models summary:', model.summary()) -------------------------------------------------------------------------------- /RML2018/PET-CGDNN/rmlmodels/__pycache__/SCCLSTM.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Richardzhangxx/AMR-Benchmark/6a129c411b73e521fc3f04ccb8e1e58f8af71eb1/RML2018/PET-CGDNN/rmlmodels/__pycache__/SCCLSTM.cpython-36.pyc -------------------------------------------------------------------------------- /RML2018/ResNet/rmlmodels/ResNet.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from keras.models import Model 4 | from keras.layers import Input,Dense,ReLU,Dropout,Activation,concatenate,Softmax,Conv2D,MaxPool2D,Add,BatchNormalization 5 | from keras.layers import Bidirectional,Flatten,CuDNNGRU 6 | from keras.utils.vis_utils import plot_model 7 | 8 | def ResNet(weights=None, 9 | input_shape=[2,1024], 10 | classes=24, 11 | **kwargs): 12 | if weights is not None and not (os.path.exists(weights)): 13 | raise ValueError('The `weights` argument should be either ' 14 | '`None` (random initialization), ' 15 | 'or the path to the weights file to be loaded.') 16 | dr=0.6 17 | input = Input(input_shape+[1],name='input') 18 | 19 | x=Conv2D(256,(1,3), name="conv1",kernel_initializer='glorot_uniform', padding='same')(input) 20 | x = Activation('relu')(x) 21 | # x = Dropout(dr)(x) 22 | x=Conv2D(256,(2,3), name="conv2", kernel_initializer='glorot_uniform',padding='same')(x) 23 | # x = Dropout(dr)(x) 24 | x1 = Add()([input, x]) 25 | x1 = Activation('relu')(x1) 26 | x=Conv2D(80,(1,3), activation="relu", name="conv3", kernel_initializer='glorot_uniform',padding='same')(x1) 27 | x=Conv2D(80,(1,3), activation="relu", name="conv4", kernel_initializer='glorot_uniform',padding='same')(x) 28 | x = Dropout(dr)(x) 29 | x=Flatten()(x) 30 | x = Dense(128, activation='relu', name='fc1')(x) 31 | x = Dropout(dr)(x) 32 | output = Dense(classes, activation='softmax', name='softmax')(x) 33 | 34 | model = Model(inputs = input,outputs = output) 35 | 36 | # Load weights. 37 | if weights is not None: 38 | model.load_weights(weights) 39 | 40 | return model 41 | 42 | import keras 43 | if __name__ == '__main__': 44 | model = ResNet(None,input_shape=[2,128],classes=11) 45 | 46 | adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) 47 | model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer=adam) 48 | 49 | print('models layers:', model.layers) 50 | print('models config:', model.get_config()) 51 | print('models summary:', model.summary()) --------------------------------------------------------------------------------