├── 说明.txt ├── README.md ├── Fiber-Autoencoder.py ├── Untitled1.ipynb ├── Channel.ipynb ├── Decoder_only.ipynb └── bad_channel.ipynb /说明.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rui-ops/Intelligent-model-of-Communication-system-simulation-based-on-auto-encoding-deep-learning-/HEAD/说明.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Intelligent-model-of-Communication-system-simulation-based-on-auto-encoding-deep-learning 2 | 3 | Used a Generative Adversarial Network(GAN) to simulate a optical communication system; 4 | 5 | Applying auto-encoding deep-learning method to build an Intelligent model of Communication system in order to improve its information rate and symbol coding method; 6 | 7 | laying a good foundation for the development of intelligent fiber communication systems; 8 | 9 | This is my bachelor thesis project, and that's why I'll only put some part of the code here since I don't wanna get fined by my university or something 10 | -------------------------------------------------------------------------------- /Fiber-Autoencoder.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[24]: 5 | 6 | 7 | import numpy as np 8 | import matplotlib.pyplot as plt 9 | import scipy.io as sio 10 | import math 11 | import time 12 | import sys 13 | import matplotlib.cm as cm 14 | import tensorflow as tf 15 | import random 16 | 17 | 18 | # In[25]: 19 | 20 | 21 | def tf_print(tmp_var): 22 | init = tf.global_variables_initializer() 23 | sess = tf.Session() 24 | sess.run(init) 25 | print(sess.run(tmp_var)) 26 | 27 | 28 | # In[453]: 29 | 30 | 31 | ## START: these are the main parameters to set 32 | P_in_dBm=-2 # input power in dBm 33 | gamma = 1.27 # fiber nonlinearity (set to 0 zero for AWGN or 1.27 for a nonlinear channel) 34 | M = 4 # constellation size 35 | 36 | # main network parameters and optimization parameters (to be modified for performance improvements) 37 | neurons_per_layer = 50 38 | tx_layers = 3 39 | rx_layers = 3 40 | learning_rate = 0.001 41 | iterations = 50000 42 | stacks = 20 43 | minibatch_size = stacks*M 44 | ## END: these are the main parameters to set 45 | 46 | 47 | # derived channel parameters 48 | channel_uses = 2 # this should be 2: the fiber code will break otherwise 49 | assert(channel_uses==2), "channel uses should be 2" 50 | L=50 # fiber total length 51 | K=20 # number of amplification stages (more layers requires more time) 52 | 53 | P_in=10**(P_in_dBm/10)*0.001 54 | Ess=np.sqrt(P_in) 55 | SNR_dB=16 56 | SNR=10**(SNR_dB/10) 57 | sigma2tot=Ess**2/SNR 58 | sigma=np.sqrt(sigma2tot/K) 59 | 60 | 61 | #sigma = 3.8505e-4*np.sqrt(2) # N0= h*v*nsp*(G-1) sigma**2 = BW*N0 62 | #sigma2tot=K*sigma**2 63 | #P_in=10**(P_in_dBm/10)*0.001 64 | #Ess=np.sqrt(P_in) 65 | #SNR=Ess**2/(sigma2tot) 66 | #SNR_dB=10*np.log(SNR) 67 | print(SNR_dB,L) 68 | 69 | 70 | # In[454]: 71 | 72 | 73 | #=====================================================# 74 | # Define the components of the computation graph 75 | #=====================================================# 76 | initializer = tf.contrib.layers.xavier_initializer() 77 | # transmitter 78 | W_tx = {} 79 | b_tx = {} 80 | for NN in range(tx_layers): 81 | if NN == 0: 82 | in_neurons = M 83 | else: 84 | in_neurons = neurons_per_layer 85 | if NN == tx_layers - 1: 86 | out_neurons = channel_uses 87 | else: 88 | out_neurons = neurons_per_layer 89 | W_tx[NN] = tf.Variable(initializer([in_neurons, out_neurons])) 90 | b_tx[NN] = tf.Variable(initializer([1, out_neurons])) 91 | 92 | # receiver 93 | W_rx = {} 94 | b_rx = {} 95 | for NN in range(rx_layers): 96 | if NN == 0: 97 | in_neurons = channel_uses+1 98 | else: 99 | in_neurons = neurons_per_layer 100 | if NN == rx_layers - 1: 101 | out_neurons = M 102 | else: 103 | out_neurons = neurons_per_layer 104 | W_rx[NN] = tf.Variable(initializer([in_neurons, out_neurons])) 105 | b_rx[NN] = tf.Variable(initializer([1, out_neurons])) 106 | 107 | # the encoder 108 | def encoder(x): 109 | for NN in range(tx_layers-1): 110 | x = tf.nn.tanh(tf.matmul(x, W_tx[NN]) + b_tx[NN]) 111 | x = tf.matmul(x, W_tx[tx_layers-1]) + b_tx[tx_layers-1] 112 | return x 113 | 114 | # the decoder 115 | def decoder(x): 116 | for NN in range(rx_layers-1): 117 | x = tf.nn.tanh(tf.matmul(x, W_rx[NN]) + b_rx[NN]) 118 | x = tf.nn.softmax(tf.matmul(x, W_rx[rx_layers-1]) + b_rx[rx_layers-1]) 119 | return x 120 | 121 | # the non-dispersive fiber channel 122 | def fiber_channel(x): 123 | xr=x[:,0] 124 | xi=x[:,1] 125 | for segments in range(1,K+1): 126 | s=gamma*(xr**2+xi**2)*L/K 127 | xr=xr*tf.cos(s)-xi*tf.sin(s) 128 | xi=xi*tf.cos(s)+xr*tf.sin(s) 129 | xr=tf.add(xr,tf.random_normal(tf.shape(xr), mean=0.0, stddev=sigma)) 130 | xi=tf.add(xi,tf.random_normal(tf.shape(xi), mean=0.0, stddev=sigma)) 131 | z=tf.stack([xr,xi,xr**2+xi**2]) 132 | z=tf.transpose(z) 133 | return z 134 | 135 | # average transmit power constraint 136 | def normalization(x): # E[|x|^2] = Es 137 | return Ess*x / tf.sqrt(2*tf.reduce_mean(tf.square(x))) 138 | 139 | 140 | # In[455]: 141 | 142 | 143 | _map64_ = dict([('0',(-4,-4)),('1',(-4,-3)),('2',(-4,-1)),('3',(-4,-2)), 144 | ('4',(-4,4)),('5',(-4,3)),('6',(-4,1)),('7',(-4,2)), 145 | ('8',(-3,-4)),('9',(-3,-3)),('10',(-3,-1)),('11',(-3,-2)), 146 | ('12',(-3,4)),('13',(-3,3)),('14',(-3,1)),('15',(-3,2)), 147 | ('16',(-1,-4)),('17',(-1,-3)),('18',(-1,-1)),('19',(-1,-2)), 148 | ('20',(-1,4)),('21',(-1,3)),('22',(-1,1)),('23',(-1,2)), 149 | ('24',(-2,-4)),('25',(-2,-3)),('26',(-2,-1)),('27',(-2,-2)), 150 | ('28',(-2,4)),('29',(-2,3)),('30',(-2,1)),('31',(-2,2)), 151 | ('32',(4,-4)),('33',(4,-3)),('34',(4,-1)),('35',(4,-2)), 152 | ('36',(4,4)),('37',(4,3)),('38',(4,1)),('39',(4,2)), 153 | ('40',(3,-4)),('41',(3,-3)),('42',(3,-1)),('43',(3,-2)), 154 | ('44',(3,4)),('45',(3,3)),('46',(3,1)),('47',(3,2)), 155 | ('48',(1,-4)),('49',(1,-3)),('50',(1,-1)),('51',(1,-2)), 156 | ('52',(1,4)),('53',(1,3)),('54',(1,1)),('55',(1,2)), 157 | ('56',(2,-4)),('57',(2,-3)),('58',(2,-1)),('59',(2,-2)), 158 | ('60',(2,4)),('61',(2,3)),('62',(2,1)),('63',(2,2))]) 159 | _map4_ = dict([('0',(1,1)),('1',(1,-1)),('2',(-1,1)),('3',(-1,-1))]) 160 | _map16_ = dict([('0',(3,3)),('1',(1,3)),('2',(-3,3)),('3',(-1,3)), 161 | ('7',(-1,1)),('6',(-3,1)),('5',(1,1)),('4',(3,1)), 162 | ('8',(3,-3)),('9',(1,-3)),('10',(-3,-3)),('11',(-1,-3)), 163 | ('15',(-1,-1)),('14',(-3,-1)),('13',(1,-1)),('12',(3,-1))]) 164 | #用了Grey Mapping 165 | 166 | 167 | # In[456]: 168 | 169 | 170 | #=====================================================# 171 | # build the computation graph 172 | 173 | X_tilde = tf.placeholder('float', [minibatch_size, M]) # one-hot vectors 174 | enco=tf.placeholder('float', [minibatch_size, 2]) 175 | 176 | #grid coordinates for visulazing decision regions 177 | resolution=1000 178 | G = tf.placeholder('float', [resolution**2, channel_uses+1]) 179 | 180 | X = normalization(enco) # minibatch_size x channel_uses 181 | Y = fiber_channel(X) 182 | Z = decoder(Y) 183 | D = decoder(G) 184 | epsilon = 0.000001 185 | loss = -tf.reduce_mean(X_tilde*tf.log(Z+epsilon)) 186 | MI=(np.log(M)-loss*M)/np.log(2) 187 | optimizer = tf.train.AdamOptimizer(learning_rate) 188 | train = optimizer.minimize(loss) 189 | 190 | 191 | # In[ ]: 192 | 193 | 194 | 195 | 196 | 197 | # In[457]: 198 | 199 | 200 | def random_int_list(start, stop, length): 201 | start, stop = (int(start), int(stop)) if start <= stop else (int(stop), int(start)) 202 | length = int(abs(length)) if length else 0 203 | random_list = [] 204 | for i in range(length): 205 | random_list.append(random.randint(start, stop)) 206 | return random_list 207 | 208 | 209 | # In[ ]: 210 | 211 | 212 | 213 | 214 | 215 | # In[458]: 216 | 217 | 218 | #=====================================================# 219 | # parameter training 220 | #=====================================================# 221 | start_time = time.time() 222 | unitmatrix = np.eye(M) 223 | training_set = np.tile(unitmatrix, [stacks, 1]) 224 | init_op = tf.global_variables_initializer() 225 | sess = tf.Session() 226 | sess.run(init_op) 227 | MI_tmp=0 228 | totalloss=[] 229 | enco_set=[] 230 | for i in range(0,stacks): 231 | for j in range(0,M): 232 | enco_set.append(_map4_.get(str(j))) 233 | enco_set=np.array(enco_set) 234 | for i in range(1, iterations+1): 235 | _, loss_tmp, MI_tmp = sess.run([train, loss, MI], feed_dict={X_tilde: training_set, enco: enco_set}) 236 | totalloss=np.append(totalloss, loss_tmp) 237 | if i%1000==0 or i==1: 238 | print('iteration ', i, ': loss = ', loss_tmp, '; Mutual information [bits] = ', MI_tmp) 239 | elapsed = time.time() - start_time 240 | print("{0:.2f} seconds".format(elapsed)) 241 | 242 | 243 | # In[459]: 244 | 245 | 246 | # BER Calculation 247 | test_length=100000 248 | X_t = tf.placeholder('float', [test_length, 2]) # one-hot vectors 249 | 250 | 251 | Xt = normalization(X_t) # minibatch_size x channel_uses 252 | Yt = fiber_channel(Xt) 253 | Zt = decoder(Yt) 254 | 255 | 256 | # In[460]: 257 | 258 | 259 | N=test_length 260 | test_data=random_int_list(0, M-1, N) 261 | test_enco=[] 262 | for i in range(0,N): 263 | test_enco.append(_map4_[str(test_data[i])]) 264 | 265 | [constellation,receive_points,decoded] = sess.run([Xt,Yt,Zt],feed_dict={X_t:test_enco}) 266 | 267 | 268 | # In[461]: 269 | 270 | 271 | pred_output = np.argmax(decoded,axis=1) 272 | no_errors = (pred_output != test_data) 273 | no_errors = no_errors.astype(int).sum() 274 | ber = no_errors 275 | print ('BER:',ber/N) 276 | #print(pred_output) 277 | 278 | 279 | # In[ ]: 280 | 281 | 282 | 283 | 284 | 285 | # In[ ]: 286 | 287 | 288 | 289 | 290 | -------------------------------------------------------------------------------- /Untitled1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 24, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import numpy as np\n", 10 | "import matplotlib.pyplot as plt\n", 11 | "import scipy.io as sio\n", 12 | "import math\n", 13 | "import time\n", 14 | "import sys\n", 15 | "import matplotlib.cm as cm\n", 16 | "import tensorflow as tf\n", 17 | "import random" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 25, 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "def tf_print(tmp_var):\n", 27 | " init = tf.global_variables_initializer()\n", 28 | " sess = tf.Session()\n", 29 | " sess.run(init)\n", 30 | " print(sess.run(tmp_var))" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 453, 36 | "metadata": {}, 37 | "outputs": [ 38 | { 39 | "name": "stdout", 40 | "output_type": "stream", 41 | "text": [ 42 | "16 50\n" 43 | ] 44 | } 45 | ], 46 | "source": [ 47 | "## START: these are the main parameters to set\n", 48 | "P_in_dBm=-2 # input power in dBm\n", 49 | "gamma = 1.27 # fiber nonlinearity (set to 0 zero for AWGN or 1.27 for a nonlinear channel)\n", 50 | "M = 4 # constellation size\n", 51 | "\n", 52 | "# main network parameters and optimization parameters (to be modified for performance improvements)\n", 53 | "neurons_per_layer = 50 \n", 54 | "tx_layers = 3\n", 55 | "rx_layers = 3\n", 56 | "learning_rate = 0.001\n", 57 | "iterations = 50000\n", 58 | "stacks = 20\n", 59 | "minibatch_size = stacks*M\n", 60 | "## END: these are the main parameters to set\n", 61 | "\n", 62 | "\n", 63 | "# derived channel parameters\n", 64 | "channel_uses = 2 # this should be 2: the fiber code will break otherwise\n", 65 | "assert(channel_uses==2), \"channel uses should be 2\"\n", 66 | "L=50 # fiber total length\n", 67 | "K=20 # number of amplification stages (more layers requires more time)\n", 68 | "\n", 69 | "P_in=10**(P_in_dBm/10)*0.001\n", 70 | "Ess=np.sqrt(P_in)\n", 71 | "SNR_dB=16\n", 72 | "SNR=10**(SNR_dB/10)\n", 73 | "sigma2tot=Ess**2/SNR\n", 74 | "sigma=np.sqrt(sigma2tot/K)\n", 75 | "\n", 76 | "\n", 77 | "#sigma = 3.8505e-4*np.sqrt(2) # N0= h*v*nsp*(G-1) sigma**2 = BW*N0 \n", 78 | "#sigma2tot=K*sigma**2\n", 79 | "#P_in=10**(P_in_dBm/10)*0.001\n", 80 | "#Ess=np.sqrt(P_in)\n", 81 | "#SNR=Ess**2/(sigma2tot)\n", 82 | "#SNR_dB=10*np.log(SNR)\n", 83 | "print(SNR_dB,L)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 454, 89 | "metadata": {}, 90 | "outputs": [], 91 | "source": [ 92 | "#=====================================================#\n", 93 | "# Define the components of the computation graph\n", 94 | "#=====================================================#\n", 95 | "initializer = tf.contrib.layers.xavier_initializer()\n", 96 | "# transmitter\n", 97 | "W_tx = {}\n", 98 | "b_tx = {}\n", 99 | "for NN in range(tx_layers):\n", 100 | " if NN == 0:\n", 101 | " in_neurons = M\n", 102 | " else:\n", 103 | " in_neurons = neurons_per_layer\n", 104 | " if NN == tx_layers - 1:\n", 105 | " out_neurons = channel_uses\n", 106 | " else:\n", 107 | " out_neurons = neurons_per_layer\n", 108 | " W_tx[NN] = tf.Variable(initializer([in_neurons, out_neurons]))\n", 109 | " b_tx[NN] = tf.Variable(initializer([1, out_neurons]))\n", 110 | " \n", 111 | "# receiver\n", 112 | "W_rx = {}\n", 113 | "b_rx = {}\n", 114 | "for NN in range(rx_layers):\n", 115 | " if NN == 0:\n", 116 | " in_neurons = channel_uses+1\n", 117 | " else:\n", 118 | " in_neurons = neurons_per_layer\n", 119 | " if NN == rx_layers - 1:\n", 120 | " out_neurons = M\n", 121 | " else:\n", 122 | " out_neurons = neurons_per_layer\n", 123 | " W_rx[NN] = tf.Variable(initializer([in_neurons, out_neurons]))\n", 124 | " b_rx[NN] = tf.Variable(initializer([1, out_neurons])) \n", 125 | "\n", 126 | "# the encoder\n", 127 | "def encoder(x):\n", 128 | " for NN in range(tx_layers-1):\n", 129 | " x = tf.nn.tanh(tf.matmul(x, W_tx[NN]) + b_tx[NN])\n", 130 | " x = tf.matmul(x, W_tx[tx_layers-1]) + b_tx[tx_layers-1]\n", 131 | " return x\n", 132 | "\n", 133 | "# the decoder\n", 134 | "def decoder(x):\n", 135 | " for NN in range(rx_layers-1):\n", 136 | " x = tf.nn.tanh(tf.matmul(x, W_rx[NN]) + b_rx[NN])\n", 137 | " x = tf.nn.softmax(tf.matmul(x, W_rx[rx_layers-1]) + b_rx[rx_layers-1])\n", 138 | " return x\n", 139 | "\n", 140 | "# the non-dispersive fiber channel \n", 141 | "def fiber_channel(x):\n", 142 | " xr=x[:,0]\n", 143 | " xi=x[:,1]\n", 144 | " for segments in range(1,K+1): \n", 145 | " s=gamma*(xr**2+xi**2)*L/K \n", 146 | " xr=xr*tf.cos(s)-xi*tf.sin(s)\n", 147 | " xi=xi*tf.cos(s)+xr*tf.sin(s)\n", 148 | " xr=tf.add(xr,tf.random_normal(tf.shape(xr), mean=0.0, stddev=sigma))\n", 149 | " xi=tf.add(xi,tf.random_normal(tf.shape(xi), mean=0.0, stddev=sigma)) \n", 150 | " z=tf.stack([xr,xi,xr**2+xi**2]) \n", 151 | " z=tf.transpose(z) \n", 152 | " return z\n", 153 | "\n", 154 | "# average transmit power constraint\n", 155 | "def normalization(x): # E[|x|^2] = Es\n", 156 | " return Ess*x / tf.sqrt(2*tf.reduce_mean(tf.square(x)))" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": 455, 162 | "metadata": {}, 163 | "outputs": [], 164 | "source": [ 165 | "_map64_ = dict([('0',(-4,-4)),('1',(-4,-3)),('2',(-4,-1)),('3',(-4,-2)), \n", 166 | " ('4',(-4,4)),('5',(-4,3)),('6',(-4,1)),('7',(-4,2)),\n", 167 | " ('8',(-3,-4)),('9',(-3,-3)),('10',(-3,-1)),('11',(-3,-2)),\n", 168 | " ('12',(-3,4)),('13',(-3,3)),('14',(-3,1)),('15',(-3,2)),\n", 169 | " ('16',(-1,-4)),('17',(-1,-3)),('18',(-1,-1)),('19',(-1,-2)),\n", 170 | " ('20',(-1,4)),('21',(-1,3)),('22',(-1,1)),('23',(-1,2)),\n", 171 | " ('24',(-2,-4)),('25',(-2,-3)),('26',(-2,-1)),('27',(-2,-2)),\n", 172 | " ('28',(-2,4)),('29',(-2,3)),('30',(-2,1)),('31',(-2,2)),\n", 173 | " ('32',(4,-4)),('33',(4,-3)),('34',(4,-1)),('35',(4,-2)),\n", 174 | " ('36',(4,4)),('37',(4,3)),('38',(4,1)),('39',(4,2)),\n", 175 | " ('40',(3,-4)),('41',(3,-3)),('42',(3,-1)),('43',(3,-2)),\n", 176 | " ('44',(3,4)),('45',(3,3)),('46',(3,1)),('47',(3,2)),\n", 177 | " ('48',(1,-4)),('49',(1,-3)),('50',(1,-1)),('51',(1,-2)),\n", 178 | " ('52',(1,4)),('53',(1,3)),('54',(1,1)),('55',(1,2)),\n", 179 | " ('56',(2,-4)),('57',(2,-3)),('58',(2,-1)),('59',(2,-2)),\n", 180 | " ('60',(2,4)),('61',(2,3)),('62',(2,1)),('63',(2,2))])\n", 181 | "_map4_ = dict([('0',(1,1)),('1',(1,-1)),('2',(-1,1)),('3',(-1,-1))])\n", 182 | "_map16_ = dict([('0',(3,3)),('1',(1,3)),('2',(-3,3)),('3',(-1,3)), \n", 183 | " ('7',(-1,1)),('6',(-3,1)),('5',(1,1)),('4',(3,1)),\n", 184 | " ('8',(3,-3)),('9',(1,-3)),('10',(-3,-3)),('11',(-1,-3)),\n", 185 | " ('15',(-1,-1)),('14',(-3,-1)),('13',(1,-1)),('12',(3,-1))])\n", 186 | "#用了Grey Mapping" 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": 456, 192 | "metadata": {}, 193 | "outputs": [], 194 | "source": [ 195 | "#=====================================================#\n", 196 | "# build the computation graph\n", 197 | "#=====================================================#\n", 198 | "X_tilde = tf.placeholder('float', [minibatch_size, M]) # one-hot vectors\n", 199 | "enco=tf.placeholder('float', [minibatch_size, 2])\n", 200 | "\n", 201 | "#grid coordinates for visulazing decision regions\n", 202 | "resolution=1000\n", 203 | "G = tf.placeholder('float', [resolution**2, channel_uses+1])\n", 204 | "\n", 205 | "X = normalization(enco) # minibatch_size x channel_uses\n", 206 | "Y = fiber_channel(X)\n", 207 | "Z = decoder(Y)\n", 208 | "D = decoder(G)\n", 209 | "epsilon = 0.000001\n", 210 | "loss = -tf.reduce_mean(X_tilde*tf.log(Z+epsilon))\n", 211 | "MI=(np.log(M)-loss*M)/np.log(2)\n", 212 | "optimizer = tf.train.AdamOptimizer(learning_rate)\n", 213 | "train = optimizer.minimize(loss)" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": null, 219 | "metadata": {}, 220 | "outputs": [], 221 | "source": [] 222 | }, 223 | { 224 | "cell_type": "code", 225 | "execution_count": 457, 226 | "metadata": {}, 227 | "outputs": [], 228 | "source": [ 229 | "def random_int_list(start, stop, length):\n", 230 | " start, stop = (int(start), int(stop)) if start <= stop else (int(stop), int(start))\n", 231 | " length = int(abs(length)) if length else 0\n", 232 | " random_list = []\n", 233 | " for i in range(length):\n", 234 | " random_list.append(random.randint(start, stop))\n", 235 | " return random_list" 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": null, 241 | "metadata": {}, 242 | "outputs": [], 243 | "source": [] 244 | }, 245 | { 246 | "cell_type": "code", 247 | "execution_count": 458, 248 | "metadata": {}, 249 | "outputs": [ 250 | { 251 | "name": "stdout", 252 | "output_type": "stream", 253 | "text": [ 254 | "iteration 1 : loss = 0.4124269 ; Mutual information [bits] = -0.3800249\n", 255 | "iteration 1000 : loss = 0.0018700387 ; Mutual information [bits] = 1.9892085\n", 256 | "iteration 2000 : loss = 0.0006371564 ; Mutual information [bits] = 1.9963231\n", 257 | "iteration 3000 : loss = 0.0007933079 ; Mutual information [bits] = 1.995422\n", 258 | "iteration 4000 : loss = 0.000118813325 ; Mutual information [bits] = 1.9993143\n", 259 | "iteration 5000 : loss = 5.960318e-05 ; Mutual information [bits] = 1.999656\n", 260 | "iteration 6000 : loss = 1.2501245e-05 ; Mutual information [bits] = 1.9999279\n", 261 | "iteration 7000 : loss = 1.9326424e-05 ; Mutual information [bits] = 1.9998885\n", 262 | "iteration 8000 : loss = 6.169536e-05 ; Mutual information [bits] = 1.9996439\n", 263 | "iteration 9000 : loss = 1.6802744e-06 ; Mutual information [bits] = 1.9999903\n", 264 | "iteration 10000 : loss = 1.0413141e-05 ; Mutual information [bits] = 1.9999399\n", 265 | "iteration 11000 : loss = 9.345453e-06 ; Mutual information [bits] = 1.999946\n", 266 | "iteration 12000 : loss = 2.7951037e-06 ; Mutual information [bits] = 1.9999838\n", 267 | "iteration 13000 : loss = -7.84164e-08 ; Mutual information [bits] = 2.0000005\n", 268 | "iteration 14000 : loss = -1.7192198e-07 ; Mutual information [bits] = 2.000001\n", 269 | "iteration 15000 : loss = 3.1575594e-06 ; Mutual information [bits] = 1.9999818\n", 270 | "iteration 16000 : loss = -1.7695109e-07 ; Mutual information [bits] = 2.000001\n", 271 | "iteration 17000 : loss = -5.829782e-08 ; Mutual information [bits] = 2.0000002\n", 272 | "iteration 18000 : loss = -1.5478489e-07 ; Mutual information [bits] = 2.000001\n", 273 | "iteration 19000 : loss = 0.0001228236 ; Mutual information [bits] = 1.9992912\n", 274 | "iteration 20000 : loss = 8.4392994e-08 ; Mutual information [bits] = 1.9999994\n", 275 | "iteration 21000 : loss = 1.3977479e-08 ; Mutual information [bits] = 2.0\n", 276 | "iteration 22000 : loss = 2.142005e-06 ; Mutual information [bits] = 1.9999876\n", 277 | "iteration 23000 : loss = -2.0395956e-07 ; Mutual information [bits] = 2.0000012\n", 278 | "iteration 24000 : loss = 5.943042e-08 ; Mutual information [bits] = 1.9999996\n", 279 | "iteration 25000 : loss = -2.2444867e-07 ; Mutual information [bits] = 2.0000014\n", 280 | "iteration 26000 : loss = -2.3730095e-07 ; Mutual information [bits] = 2.0000014\n", 281 | "iteration 27000 : loss = -1.9129352e-07 ; Mutual information [bits] = 2.000001\n", 282 | "iteration 28000 : loss = -2.1010631e-07 ; Mutual information [bits] = 2.0000012\n", 283 | "iteration 29000 : loss = 0.0010058379 ; Mutual information [bits] = 1.9941956\n", 284 | "iteration 30000 : loss = -2.1513543e-07 ; Mutual information [bits] = 2.0000012\n", 285 | "iteration 31000 : loss = -1.6707854e-07 ; Mutual information [bits] = 2.000001\n", 286 | "iteration 32000 : loss = -2.3506577e-07 ; Mutual information [bits] = 2.0000014\n", 287 | "iteration 33000 : loss = 2.9445455e-06 ; Mutual information [bits] = 1.999983\n", 288 | "iteration 34000 : loss = -1.7099045e-07 ; Mutual information [bits] = 2.000001\n", 289 | "iteration 35000 : loss = -2.3655589e-07 ; Mutual information [bits] = 2.0000014\n", 290 | "iteration 36000 : loss = -1.4845158e-07 ; Mutual information [bits] = 2.000001\n", 291 | "iteration 37000 : loss = -2.0544958e-07 ; Mutual information [bits] = 2.0000012\n", 292 | "iteration 38000 : loss = -2.3767348e-07 ; Mutual information [bits] = 2.0000014\n", 293 | "iteration 39000 : loss = -2.3767348e-07 ; Mutual information [bits] = 2.0000014\n", 294 | "iteration 40000 : loss = -1.4174589e-07 ; Mutual information [bits] = 2.000001\n", 295 | "iteration 41000 : loss = -2.1476285e-07 ; Mutual information [bits] = 2.0000012\n", 296 | "iteration 42000 : loss = 2.21367e-06 ; Mutual information [bits] = 1.9999872\n", 297 | "iteration 43000 : loss = -2.3730095e-07 ; Mutual information [bits] = 2.0000014\n", 298 | "iteration 44000 : loss = 9.754481e-06 ; Mutual information [bits] = 1.9999437\n", 299 | "iteration 45000 : loss = -2.1364527e-07 ; Mutual information [bits] = 2.0000012\n", 300 | "iteration 46000 : loss = -3.8737973e-08 ; Mutual information [bits] = 2.0000002\n", 301 | "iteration 47000 : loss = -2.3841854e-07 ; Mutual information [bits] = 2.0000014\n", 302 | "iteration 48000 : loss = -2.1643928e-07 ; Mutual information [bits] = 2.0000012\n", 303 | "iteration 49000 : loss = -2.3730095e-07 ; Mutual information [bits] = 2.0000014\n", 304 | "iteration 50000 : loss = -1.8104876e-07 ; Mutual information [bits] = 2.000001\n", 305 | "66.26 seconds\n" 306 | ] 307 | } 308 | ], 309 | "source": [ 310 | "#=====================================================#\n", 311 | "# parameter training\n", 312 | "#=====================================================#\n", 313 | "start_time = time.time()\n", 314 | "unitmatrix = np.eye(M) \n", 315 | "training_set = np.tile(unitmatrix, [stacks, 1])\n", 316 | "init_op = tf.global_variables_initializer()\n", 317 | "sess = tf.Session()\n", 318 | "sess.run(init_op)\n", 319 | "MI_tmp=0\n", 320 | "totalloss=[]\n", 321 | "enco_set=[]\n", 322 | "for i in range(0,stacks):\n", 323 | " for j in range(0,M):\n", 324 | " enco_set.append(_map4_.get(str(j)))\n", 325 | "enco_set=np.array(enco_set)\n", 326 | "for i in range(1, iterations+1):\n", 327 | " _, loss_tmp, MI_tmp = sess.run([train, loss, MI], feed_dict={X_tilde: training_set, enco: enco_set})\n", 328 | " totalloss=np.append(totalloss, loss_tmp)\n", 329 | " if i%1000==0 or i==1:\n", 330 | " print('iteration ', i, ': loss = ', loss_tmp, '; Mutual information [bits] = ', MI_tmp) \n", 331 | "elapsed = time.time() - start_time\n", 332 | "print(\"{0:.2f} seconds\".format(elapsed))\n" 333 | ] 334 | }, 335 | { 336 | "cell_type": "code", 337 | "execution_count": 459, 338 | "metadata": {}, 339 | "outputs": [], 340 | "source": [ 341 | "# BER Calculation\n", 342 | "test_length=100000\n", 343 | "X_t = tf.placeholder('float', [test_length, 2]) # one-hot vectors\n", 344 | "\n", 345 | "\n", 346 | "Xt = normalization(X_t) # minibatch_size x channel_uses\n", 347 | "Yt = fiber_channel(Xt)\n", 348 | "Zt = decoder(Yt)" 349 | ] 350 | }, 351 | { 352 | "cell_type": "code", 353 | "execution_count": 460, 354 | "metadata": {}, 355 | "outputs": [], 356 | "source": [ 357 | "N=test_length\n", 358 | "test_data=random_int_list(0, M-1, N)\n", 359 | "test_enco=[]\n", 360 | "for i in range(0,N):\n", 361 | " test_enco.append(_map4_[str(test_data[i])])\n", 362 | " \n", 363 | "[constellation,receive_points,decoded] = sess.run([Xt,Yt,Zt],feed_dict={X_t:test_enco})\n" 364 | ] 365 | }, 366 | { 367 | "cell_type": "code", 368 | "execution_count": 461, 369 | "metadata": {}, 370 | "outputs": [ 371 | { 372 | "name": "stdout", 373 | "output_type": "stream", 374 | "text": [ 375 | "BER: 0.00026\n" 376 | ] 377 | } 378 | ], 379 | "source": [ 380 | "pred_output = np.argmax(decoded,axis=1)\n", 381 | "no_errors = (pred_output != test_data)\n", 382 | "no_errors = no_errors.astype(int).sum()\n", 383 | "ber = no_errors \n", 384 | "print ('BER:',ber/N)\n", 385 | "#print(pred_output)" 386 | ] 387 | }, 388 | { 389 | "cell_type": "code", 390 | "execution_count": null, 391 | "metadata": {}, 392 | "outputs": [], 393 | "source": [] 394 | }, 395 | { 396 | "cell_type": "code", 397 | "execution_count": null, 398 | "metadata": {}, 399 | "outputs": [], 400 | "source": [] 401 | } 402 | ], 403 | "metadata": { 404 | "kernelspec": { 405 | "display_name": "Python 3", 406 | "language": "python", 407 | "name": "python3" 408 | }, 409 | "language_info": { 410 | "codemirror_mode": { 411 | "name": "ipython", 412 | "version": 3 413 | }, 414 | "file_extension": ".py", 415 | "mimetype": "text/x-python", 416 | "name": "python", 417 | "nbconvert_exporter": "python", 418 | "pygments_lexer": "ipython3", 419 | "version": "3.7.4" 420 | } 421 | }, 422 | "nbformat": 4, 423 | "nbformat_minor": 2 424 | } 425 | -------------------------------------------------------------------------------- /Channel.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 19, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "# importing libs\n", 10 | "import numpy as np\n", 11 | "import tensorflow as tf\n", 12 | "from tensorflow import keras\n", 13 | "from keras.layers import Input, Dense, GaussianNoise\n", 14 | "from keras.models import Model\n", 15 | "from keras import regularizers\n", 16 | "from keras.layers.normalization import BatchNormalization\n", 17 | "from keras.optimizers import SGD\n", 18 | "import random as rn\n", 19 | "import os\n", 20 | "from keras.models import load_model" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 20, 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "# Loading data\n", 30 | "real_input=np.loadtxt('real_input.txt')\n", 31 | "#print(real_input.shape)\n", 32 | "Rinput=[]\n", 33 | "for i in range(0,32768):\n", 34 | " Rinput.append(real_input[i][1])\n", 35 | "Rinput=np.array(Rinput)\n", 36 | "Rinput=np.reshape(Rinput,(4096,8))\n", 37 | "#print(Rinput.shape)\n", 38 | "#print(Rinput[2])\n", 39 | "\n", 40 | "valinput=np.loadtxt('valinput.txt')\n", 41 | "#print(valinput.shape)\n", 42 | "Vinput=[]\n", 43 | "for i in range(0,8192):\n", 44 | " Vinput.append(real_input[i][1])\n", 45 | "Vinput=np.array(Vinput)\n", 46 | "Vinput=np.reshape(Vinput,(1024,8))\n", 47 | "\n", 48 | "real_output=np.loadtxt('real_output.txt')\n", 49 | "#print(real_output.shape)\n", 50 | "Routput=[]\n", 51 | "for i in range(0,32768):\n", 52 | " Sum=real_output[4*i][1]+real_output[4*i+1][1]+real_output[4*i+2][1]+real_output[4*i+3][1]\n", 53 | " mm=Sum/4\n", 54 | " Routput.append(mm)\n", 55 | "Routput=np.array(Routput)\n", 56 | "Routput=np.reshape(Routput,(4096,8))\n", 57 | "#print(Rinput.shape)\n", 58 | "#print(Routput[2])\n", 59 | "\n", 60 | "valoutput=np.loadtxt('valoutput.txt')\n", 61 | "#print(valoutput.shape)\n", 62 | "Voutput=[]\n", 63 | "for i in range(0,8192):\n", 64 | " Sum=valoutput[4*i][1]+valoutput[4*i+1][1]+valoutput[4*i+2][1]+valoutput[4*i+3][1]\n", 65 | " mm=Sum/4\n", 66 | " Voutput.append(mm)\n", 67 | "Voutput=np.array(Voutput)\n", 68 | "Voutput=np.reshape(Voutput,(1024,8))\n" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 21, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "Ir=[0,1]\n", 78 | "If=[1,0]\n", 79 | "\n", 80 | "Ir1=[]\n", 81 | "If1=[]\n", 82 | "Ir2=[]\n", 83 | "If2=[]\n", 84 | "for i in range(0,4096):\n", 85 | " Ir1.append(Ir)\n", 86 | " If1.append(If)\n", 87 | " \n", 88 | "for i in range(0,1024):\n", 89 | " Ir2.append(Ir)\n", 90 | " If2.append(If)\n", 91 | " \n", 92 | "Ir1=np.array(Ir1)\n", 93 | "Ir2=np.array(Ir2)\n", 94 | "If1=np.array(If1)\n", 95 | "If2=np.array(If2)" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 22, 101 | "metadata": {}, 102 | "outputs": [ 103 | { 104 | "name": "stdout", 105 | "output_type": "stream", 106 | "text": [ 107 | "Model: \"model_5\"\n", 108 | "_________________________________________________________________\n", 109 | "Layer (type) Output Shape Param # \n", 110 | "=================================================================\n", 111 | "input_5 (InputLayer) (None, 8) 0 \n", 112 | "_________________________________________________________________\n", 113 | "dense_19 (Dense) (None, 16) 144 \n", 114 | "_________________________________________________________________\n", 115 | "dense_20 (Dense) (None, 10) 170 \n", 116 | "_________________________________________________________________\n", 117 | "dense_21 (Dense) (None, 6) 66 \n", 118 | "_________________________________________________________________\n", 119 | "dense_22 (Dense) (None, 2) 14 \n", 120 | "=================================================================\n", 121 | "Total params: 394\n", 122 | "Trainable params: 394\n", 123 | "Non-trainable params: 0\n", 124 | "_________________________________________________________________\n", 125 | "None\n" 126 | ] 127 | } 128 | ], 129 | "source": [ 130 | "#Discriminator\n", 131 | "inputsize = 8\n", 132 | "outputsize = 2\n", 133 | "input_sig = Input(shape=(inputsize,))\n", 134 | "layer1 = Dense(16, activation='relu')(input_sig)\n", 135 | "layer2 = Dense(10, activation='relu')(layer1)\n", 136 | "layer3 = Dense(6, activation='relu')(layer2)\n", 137 | "p = Dense(outputsize, activation='softmax')(layer3)\n", 138 | "\n", 139 | "discriminator = Model(input_sig, p)\n", 140 | "\n", 141 | "discriminator.compile(optimizer='adam', loss='categorical_crossentropy')\n", 142 | "print (discriminator.summary())" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 24, 148 | "metadata": {}, 149 | "outputs": [ 150 | { 151 | "name": "stdout", 152 | "output_type": "stream", 153 | "text": [ 154 | "Model: \"model_7\"\n", 155 | "_________________________________________________________________\n", 156 | "Layer (type) Output Shape Param # \n", 157 | "=================================================================\n", 158 | "input_7 (InputLayer) (None, 8) 0 \n", 159 | "_________________________________________________________________\n", 160 | "dense_29 (Dense) (None, 30) 270 \n", 161 | "_________________________________________________________________\n", 162 | "dense_30 (Dense) (None, 20) 620 \n", 163 | "_________________________________________________________________\n", 164 | "dense_31 (Dense) (None, 13) 273 \n", 165 | "_________________________________________________________________\n", 166 | "dense_32 (Dense) (None, 8) 112 \n", 167 | "_________________________________________________________________\n", 168 | "dense_33 (Dense) (None, 5) 45 \n", 169 | "_________________________________________________________________\n", 170 | "dense_34 (Dense) (None, 8) 48 \n", 171 | "=================================================================\n", 172 | "Total params: 1,368\n", 173 | "Trainable params: 1,368\n", 174 | "Non-trainable params: 0\n", 175 | "_________________________________________________________________\n", 176 | "None\n" 177 | ] 178 | } 179 | ], 180 | "source": [ 181 | "#Generator\n", 182 | "Inputsize = 8\n", 183 | "Outputsize = 8\n", 184 | "input_signal = Input(shape=(Inputsize,))\n", 185 | "lay1 = Dense(30, activation='relu')(input_signal)\n", 186 | "lay2 = Dense(20, activation='relu')(lay1)\n", 187 | "lay3 = Dense(13, activation='relu')(lay2)\n", 188 | "lay4 = Dense(8, activation='relu')(lay3)\n", 189 | "lay5 = Dense(5, activation='relu')(lay4)\n", 190 | "output_signal = Dense(Outputsize, activation='linear')(lay5)\n", 191 | "\n", 192 | "generator = Model(input_signal, output_signal)\n", 193 | "\n", 194 | "generator.compile(optimizer='adam', loss='categorical_crossentropy')\n", 195 | "print (generator.summary())" 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "execution_count": 25, 201 | "metadata": {}, 202 | "outputs": [ 203 | { 204 | "data": { 205 | "text/plain": [ 206 | "" 207 | ] 208 | }, 209 | "execution_count": 25, 210 | "metadata": {}, 211 | "output_type": "execute_result" 212 | } 213 | ], 214 | "source": [ 215 | "#初始化权重\n", 216 | "keras.initializers.RandomUniform(minval=-0.05, maxval=0.05, seed=None)" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": 26, 222 | "metadata": {}, 223 | "outputs": [ 224 | { 225 | "name": "stdout", 226 | "output_type": "stream", 227 | "text": [ 228 | "Train on 4096 samples, validate on 1024 samples\n", 229 | "Epoch 1/30\n", 230 | "4096/4096 [==============================] - 0s 22us/step - loss: 0.6632 - val_loss: 0.6239\n", 231 | "Epoch 2/30\n", 232 | "4096/4096 [==============================] - 0s 4us/step - loss: 0.5878 - val_loss: 0.5421\n", 233 | "Epoch 3/30\n", 234 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.5012 - val_loss: 0.4498\n", 235 | "Epoch 4/30\n", 236 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.4055 - val_loss: 0.3515\n", 237 | "Epoch 5/30\n", 238 | "4096/4096 [==============================] - 0s 6us/step - loss: 0.3077 - val_loss: 0.2564\n", 239 | "Epoch 6/30\n", 240 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.2181 - val_loss: 0.1754\n", 241 | "Epoch 7/30\n", 242 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.1463 - val_loss: 0.1153\n", 243 | "Epoch 8/30\n", 244 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0957 - val_loss: 0.0754\n", 245 | "Epoch 9/30\n", 246 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0631 - val_loss: 0.0505\n", 247 | "Epoch 10/30\n", 248 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0430 - val_loss: 0.0353\n", 249 | "Epoch 11/30\n", 250 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0306 - val_loss: 0.0257\n", 251 | "Epoch 12/30\n", 252 | "4096/4096 [==============================] - 0s 4us/step - loss: 0.0227 - val_loss: 0.0195\n", 253 | "Epoch 13/30\n", 254 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0174 - val_loss: 0.0153\n", 255 | "Epoch 14/30\n", 256 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0138 - val_loss: 0.0123\n", 257 | "Epoch 15/30\n", 258 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0112 - val_loss: 0.0101\n", 259 | "Epoch 16/30\n", 260 | "4096/4096 [==============================] - 0s 6us/step - loss: 0.0093 - val_loss: 0.0084\n", 261 | "Epoch 17/30\n", 262 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0078 - val_loss: 0.0072\n", 263 | "Epoch 18/30\n", 264 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0067 - val_loss: 0.0062\n", 265 | "Epoch 19/30\n", 266 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0058 - val_loss: 0.0054\n", 267 | "Epoch 20/30\n", 268 | "4096/4096 [==============================] - 0s 6us/step - loss: 0.0050 - val_loss: 0.0047\n", 269 | "Epoch 21/30\n", 270 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0044 - val_loss: 0.0042\n", 271 | "Epoch 22/30\n", 272 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0039 - val_loss: 0.0037\n", 273 | "Epoch 23/30\n", 274 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0035 - val_loss: 0.0033\n", 275 | "Epoch 24/30\n", 276 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0032 - val_loss: 0.0030\n", 277 | "Epoch 25/30\n", 278 | "4096/4096 [==============================] - 0s 6us/step - loss: 0.0029 - val_loss: 0.0027\n", 279 | "Epoch 26/30\n", 280 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0026 - val_loss: 0.0025\n", 281 | "Epoch 27/30\n", 282 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0024 - val_loss: 0.0023\n", 283 | "Epoch 28/30\n", 284 | "4096/4096 [==============================] - 0s 6us/step - loss: 0.0022 - val_loss: 0.0021\n", 285 | "Epoch 29/30\n", 286 | "4096/4096 [==============================] - 0s 7us/step - loss: 0.0020 - val_loss: 0.0019\n", 287 | "Epoch 30/30\n", 288 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0018 - val_loss: 0.0018\n" 289 | ] 290 | }, 291 | { 292 | "data": { 293 | "text/plain": [ 294 | "" 295 | ] 296 | }, 297 | "execution_count": 26, 298 | "metadata": {}, 299 | "output_type": "execute_result" 300 | } 301 | ], 302 | "source": [ 303 | "#Training od discriminator\n", 304 | "discriminator.fit(Routput, Ir1,\n", 305 | " epochs=30,\n", 306 | " batch_size=300,\n", 307 | " validation_data=(Voutput, Ir2))\n" 308 | ] 309 | }, 310 | { 311 | "cell_type": "code", 312 | "execution_count": 27, 313 | "metadata": {}, 314 | "outputs": [], 315 | "source": [ 316 | "Foutput = generator.predict(Rinput) \n", 317 | "FVoutput=generator.predict(Vinput)" 318 | ] 319 | }, 320 | { 321 | "cell_type": "code", 322 | "execution_count": 28, 323 | "metadata": {}, 324 | "outputs": [ 325 | { 326 | "name": "stdout", 327 | "output_type": "stream", 328 | "text": [ 329 | "Train on 4096 samples, validate on 1024 samples\n", 330 | "Epoch 1/30\n", 331 | "4096/4096 [==============================] - 0s 5us/step - loss: 5.2985 - val_loss: 2.2888\n", 332 | "Epoch 2/30\n", 333 | "4096/4096 [==============================] - 0s 6us/step - loss: 1.2653 - val_loss: 0.5677\n", 334 | "Epoch 3/30\n", 335 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.3913 - val_loss: 0.2798\n", 336 | "Epoch 4/30\n", 337 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.2315 - val_loss: 0.1769\n", 338 | "Epoch 5/30\n", 339 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.1480 - val_loss: 0.1147\n", 340 | "Epoch 6/30\n", 341 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0981 - val_loss: 0.0779\n", 342 | "Epoch 7/30\n", 343 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0683 - val_loss: 0.0557\n", 344 | "Epoch 8/30\n", 345 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0498 - val_loss: 0.0416\n", 346 | "Epoch 9/30\n", 347 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0379 - val_loss: 0.0324\n", 348 | "Epoch 10/30\n", 349 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0299 - val_loss: 0.0259\n", 350 | "Epoch 11/30\n", 351 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0243 - val_loss: 0.0213\n", 352 | "Epoch 12/30\n", 353 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0201 - val_loss: 0.0178\n", 354 | "Epoch 13/30\n", 355 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0169 - val_loss: 0.0151\n", 356 | "Epoch 14/30\n", 357 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0145 - val_loss: 0.0130\n", 358 | "Epoch 15/30\n", 359 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0125 - val_loss: 0.0114\n", 360 | "Epoch 16/30\n", 361 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0110 - val_loss: 0.0100\n", 362 | "Epoch 17/30\n", 363 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0097 - val_loss: 0.0089\n", 364 | "Epoch 18/30\n", 365 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0087 - val_loss: 0.0079\n", 366 | "Epoch 19/30\n", 367 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0078 - val_loss: 0.0071\n", 368 | "Epoch 20/30\n", 369 | "4096/4096 [==============================] - 0s 4us/step - loss: 0.0070 - val_loss: 0.0065\n", 370 | "Epoch 21/30\n", 371 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0064 - val_loss: 0.0059\n", 372 | "Epoch 22/30\n", 373 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0058 - val_loss: 0.0054\n", 374 | "Epoch 23/30\n", 375 | "4096/4096 [==============================] - 0s 4us/step - loss: 0.0053 - val_loss: 0.0049\n", 376 | "Epoch 24/30\n", 377 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0049 - val_loss: 0.0046\n", 378 | "Epoch 25/30\n", 379 | "4096/4096 [==============================] - 0s 4us/step - loss: 0.0045 - val_loss: 0.0042\n", 380 | "Epoch 26/30\n", 381 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0042 - val_loss: 0.0039\n", 382 | "Epoch 27/30\n", 383 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0039 - val_loss: 0.0036\n", 384 | "Epoch 28/30\n", 385 | "4096/4096 [==============================] - 0s 4us/step - loss: 0.0036 - val_loss: 0.0034\n", 386 | "Epoch 29/30\n", 387 | "4096/4096 [==============================] - 0s 4us/step - loss: 0.0034 - val_loss: 0.0032\n", 388 | "Epoch 30/30\n", 389 | "4096/4096 [==============================] - 0s 5us/step - loss: 0.0032 - val_loss: 0.0030\n" 390 | ] 391 | }, 392 | { 393 | "data": { 394 | "text/plain": [ 395 | "" 396 | ] 397 | }, 398 | "execution_count": 28, 399 | "metadata": {}, 400 | "output_type": "execute_result" 401 | } 402 | ], 403 | "source": [ 404 | "discriminator.fit(Foutput, If1,\n", 405 | " epochs=30,\n", 406 | " batch_size=300,\n", 407 | " validation_data=(FVoutput, If2))" 408 | ] 409 | }, 410 | { 411 | "cell_type": "code", 412 | "execution_count": 29, 413 | "metadata": {}, 414 | "outputs": [ 415 | { 416 | "name": "stdout", 417 | "output_type": "stream", 418 | "text": [ 419 | "Train on 4096 samples, validate on 1024 samples\n", 420 | "Epoch 1/30\n", 421 | "4096/4096 [==============================] - 0s 34us/step - loss: 1.7880e-06 - val_loss: 3.3096e-06\n", 422 | "Epoch 2/30\n", 423 | "4096/4096 [==============================] - 0s 6us/step - loss: 1.9945e-06 - val_loss: 4.3918e-06\n", 424 | "Epoch 3/30\n", 425 | "4096/4096 [==============================] - 0s 7us/step - loss: 3.5846e-06 - val_loss: 2.1528e-06\n", 426 | "Epoch 4/30\n", 427 | "4096/4096 [==============================] - 0s 6us/step - loss: 3.9072e-06 - val_loss: 2.0598e-06\n", 428 | "Epoch 5/30\n", 429 | "4096/4096 [==============================] - 0s 6us/step - loss: 3.4553e-06 - val_loss: 3.6485e-06\n", 430 | "Epoch 6/30\n", 431 | "4096/4096 [==============================] - 0s 5us/step - loss: 2.6962e-06 - val_loss: -1.4452e-06\n", 432 | "Epoch 7/30\n", 433 | "4096/4096 [==============================] - 0s 6us/step - loss: 1.8651e-06 - val_loss: -5.1137e-07\n", 434 | "Epoch 8/30\n", 435 | "4096/4096 [==============================] - 0s 6us/step - loss: 2.1935e-06 - val_loss: -6.6744e-07\n", 436 | "Epoch 9/30\n", 437 | "4096/4096 [==============================] - 0s 5us/step - loss: 2.0230e-06 - val_loss: 1.5063e-06\n", 438 | "Epoch 10/30\n", 439 | "4096/4096 [==============================] - 0s 5us/step - loss: 2.6173e-06 - val_loss: 1.5055e-06\n", 440 | "Epoch 11/30\n", 441 | "4096/4096 [==============================] - 0s 6us/step - loss: 2.6371e-06 - val_loss: 8.1315e-07\n", 442 | "Epoch 12/30\n", 443 | "4096/4096 [==============================] - 0s 7us/step - loss: 2.1047e-06 - val_loss: 8.0763e-07\n", 444 | "Epoch 13/30\n", 445 | "4096/4096 [==============================] - 0s 6us/step - loss: 1.7936e-06 - val_loss: 7.5946e-07\n", 446 | "Epoch 14/30\n", 447 | "4096/4096 [==============================] - 0s 5us/step - loss: 1.9806e-06 - val_loss: 1.0981e-06\n", 448 | "Epoch 15/30\n", 449 | "4096/4096 [==============================] - 0s 5us/step - loss: 2.1270e-06 - val_loss: 1.5857e-06\n", 450 | "Epoch 16/30\n", 451 | "4096/4096 [==============================] - 0s 6us/step - loss: 1.5201e-06 - val_loss: 5.3218e-07\n", 452 | "Epoch 17/30\n", 453 | "4096/4096 [==============================] - 0s 6us/step - loss: 3.1802e-06 - val_loss: 2.9004e-06\n", 454 | "Epoch 18/30\n", 455 | "4096/4096 [==============================] - 0s 6us/step - loss: 1.8326e-06 - val_loss: 2.6138e-06\n", 456 | "Epoch 19/30\n", 457 | "4096/4096 [==============================] - 0s 6us/step - loss: 1.8558e-06 - val_loss: 2.7076e-06\n", 458 | "Epoch 20/30\n", 459 | "4096/4096 [==============================] - 0s 6us/step - loss: 1.3304e-06 - val_loss: 3.3606e-06\n", 460 | "Epoch 21/30\n", 461 | "4096/4096 [==============================] - 0s 6us/step - loss: 3.3764e-06 - val_loss: 3.9187e-06\n", 462 | "Epoch 22/30\n", 463 | "4096/4096 [==============================] - 0s 6us/step - loss: 3.4778e-06 - val_loss: 3.9909e-06\n", 464 | "Epoch 23/30\n", 465 | "4096/4096 [==============================] - 0s 5us/step - loss: 3.4889e-06 - val_loss: 4.0204e-06\n", 466 | "Epoch 24/30\n", 467 | "4096/4096 [==============================] - 0s 5us/step - loss: 3.4779e-06 - val_loss: 4.0064e-06\n", 468 | "Epoch 25/30\n", 469 | "4096/4096 [==============================] - 0s 6us/step - loss: 3.4658e-06 - val_loss: 3.9989e-06\n", 470 | "Epoch 26/30\n", 471 | "4096/4096 [==============================] - 0s 6us/step - loss: 3.4576e-06 - val_loss: 3.9994e-06\n", 472 | "Epoch 27/30\n", 473 | "4096/4096 [==============================] - 0s 6us/step - loss: 3.4508e-06 - val_loss: 3.9939e-06\n", 474 | "Epoch 28/30\n", 475 | "4096/4096 [==============================] - 0s 6us/step - loss: 3.4445e-06 - val_loss: 3.9823e-06\n", 476 | "Epoch 29/30\n", 477 | "4096/4096 [==============================] - 0s 6us/step - loss: 3.4389e-06 - val_loss: 3.9729e-06\n", 478 | "Epoch 30/30\n", 479 | "4096/4096 [==============================] - 0s 6us/step - loss: 3.4265e-06 - val_loss: 3.9616e-06\n" 480 | ] 481 | }, 482 | { 483 | "data": { 484 | "text/plain": [ 485 | "" 486 | ] 487 | }, 488 | "execution_count": 29, 489 | "metadata": {}, 490 | "output_type": "execute_result" 491 | } 492 | ], 493 | "source": [ 494 | "generator.fit(Rinput, Routput,\n", 495 | " epochs=30,\n", 496 | " batch_size=300,\n", 497 | " validation_data=(Vinput, Voutput))" 498 | ] 499 | }, 500 | { 501 | "cell_type": "code", 502 | "execution_count": 75, 503 | "metadata": {}, 504 | "outputs": [], 505 | "source": [] 506 | }, 507 | { 508 | "cell_type": "code", 509 | "execution_count": null, 510 | "metadata": {}, 511 | "outputs": [], 512 | "source": [] 513 | }, 514 | { 515 | "cell_type": "code", 516 | "execution_count": null, 517 | "metadata": {}, 518 | "outputs": [], 519 | "source": [] 520 | } 521 | ], 522 | "metadata": { 523 | "kernelspec": { 524 | "display_name": "Python 3", 525 | "language": "python", 526 | "name": "python3" 527 | }, 528 | "language_info": { 529 | "codemirror_mode": { 530 | "name": "ipython", 531 | "version": 3 532 | }, 533 | "file_extension": ".py", 534 | "mimetype": "text/x-python", 535 | "name": "python", 536 | "nbconvert_exporter": "python", 537 | "pygments_lexer": "ipython3", 538 | "version": "3.7.4" 539 | } 540 | }, 541 | "nbformat": 4, 542 | "nbformat_minor": 2 543 | } 544 | -------------------------------------------------------------------------------- /Decoder_only.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stderr", 10 | "output_type": "stream", 11 | "text": [ 12 | "Using TensorFlow backend.\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "# importing libs\n", 18 | "import numpy as np\n", 19 | "import tensorflow as tf\n", 20 | "from tensorflow import keras\n", 21 | "from keras.layers import Input, Dense, GaussianNoise\n", 22 | "from keras.models import Model\n", 23 | "from keras import regularizers\n", 24 | "from keras.layers.normalization import BatchNormalization\n", 25 | "from keras.optimizers import SGD\n", 26 | "import random as rn\n", 27 | "import os\n", 28 | "from keras.models import load_model" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 2, 34 | "metadata": {}, 35 | "outputs": [], 36 | "source": [ 37 | "encoder = load_model('encoder.model')\n", 38 | "decoder = load_model('decoder.model')" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 4, 44 | "metadata": {}, 45 | "outputs": [ 46 | { 47 | "name": "stdout", 48 | "output_type": "stream", 49 | "text": [ 50 | "M: 4 k: 2\n" 51 | ] 52 | } 53 | ], 54 | "source": [ 55 | "# defining parameters\n", 56 | "M = 4 \n", 57 | "k = np.log2(M)\n", 58 | "k = int(k)\n", 59 | "print ('M:',M,'k:',k)" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 5, 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [ 68 | "#generating data of size N\n", 69 | "N = 8192\n", 70 | "label = np.random.randint(M,size=N)" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 6, 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "# creating one hot encoded vectors\n", 80 | "data = []\n", 81 | "for i in label:\n", 82 | " temp = np.zeros(M)\n", 83 | " temp[i] = 1\n", 84 | " data.append(temp)" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 7, 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "name": "stdout", 94 | "output_type": "stream", 95 | "text": [ 96 | "(8192, 4)\n" 97 | ] 98 | } 99 | ], 100 | "source": [ 101 | "data = np.array(data)\n", 102 | "print (data.shape)" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 8, 108 | "metadata": {}, 109 | "outputs": [], 110 | "source": [ 111 | "encoded = encoder.predict(data)" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": 10, 117 | "metadata": {}, 118 | "outputs": [ 119 | { 120 | "name": "stdout", 121 | "output_type": "stream", 122 | "text": [ 123 | "\n", 124 | "\n" 125 | ] 126 | } 127 | ], 128 | "source": [ 129 | "def myprint(s):\n", 130 | " with open('deco_input.txt','w+') as f:\n", 131 | " print('\\n')\n", 132 | " for i in range(0,s.size):\n", 133 | " print(s[i],file=f)\n", 134 | " \n", 135 | "np.set_printoptions(threshold=np.inf)\n", 136 | "myprint(encoded.flatten())" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 11, 142 | "metadata": {}, 143 | "outputs": [], 144 | "source": [ 145 | "# Loading data\n", 146 | "deco_output=np.loadtxt('deco_output.txt')\n", 147 | "#print(valoutput.shape)\n", 148 | "Doutput=[]\n", 149 | "for i in range(0,32768):\n", 150 | " Doutput.append(deco_output[i][1])\n", 151 | "Doutput=np.array(Doutput)\n", 152 | "Doutput=np.reshape(Doutput,(8192,4))" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 15, 158 | "metadata": {}, 159 | "outputs": [], 160 | "source": [ 161 | "N_val = 2048\n", 162 | "val_label = np.random.randint(M,size=N_val)\n", 163 | "val_data = []\n", 164 | "for i in val_label:\n", 165 | " temp = np.zeros(M)\n", 166 | " temp[i] = 1\n", 167 | " val_data.append(temp)\n", 168 | "val_data = np.array(val_data)" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": null, 174 | "metadata": {}, 175 | "outputs": [], 176 | "source": [] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 16, 181 | "metadata": {}, 182 | "outputs": [], 183 | "source": [ 184 | "Vinput=encoder.predict(val_data)" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": 18, 190 | "metadata": {}, 191 | "outputs": [ 192 | { 193 | "name": "stdout", 194 | "output_type": "stream", 195 | "text": [ 196 | "\n", 197 | "\n" 198 | ] 199 | } 200 | ], 201 | "source": [ 202 | "def myprint1(s):\n", 203 | " with open('deco_vinput.txt','w+') as f:\n", 204 | " print('\\n')\n", 205 | " for i in range(0,s.size):\n", 206 | " print(s[i],file=f)\n", 207 | " \n", 208 | "np.set_printoptions(threshold=np.inf)\n", 209 | "myprint1(Vinput.flatten())" 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": 19, 215 | "metadata": {}, 216 | "outputs": [], 217 | "source": [ 218 | "# Loading data\n", 219 | "deco_voutput=np.loadtxt('deco_voutput.txt')\n", 220 | "#print(valoutput.shape)\n", 221 | "Dvoutput=[]\n", 222 | "for i in range(0,8192):\n", 223 | " Dvoutput.append(deco_voutput[i][1])\n", 224 | "Dvoutput=np.array(Dvoutput)\n", 225 | "Dvoutput=np.reshape(Dvoutput,(2048,4))" 226 | ] 227 | }, 228 | { 229 | "cell_type": "code", 230 | "execution_count": 25, 231 | "metadata": {}, 232 | "outputs": [ 233 | { 234 | "name": "stdout", 235 | "output_type": "stream", 236 | "text": [ 237 | "Train on 8192 samples, validate on 2048 samples\n", 238 | "Epoch 1/50\n", 239 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3845 - val_loss: 1.3843\n", 240 | "Epoch 2/50\n", 241 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3848 - val_loss: 1.3836\n", 242 | "Epoch 3/50\n", 243 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3851 - val_loss: 1.3834\n", 244 | "Epoch 4/50\n", 245 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3854 - val_loss: 1.3854\n", 246 | "Epoch 5/50\n", 247 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3860 - val_loss: 1.3864\n", 248 | "Epoch 6/50\n", 249 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3884 - val_loss: 1.3840\n", 250 | "Epoch 7/50\n", 251 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3848 - val_loss: 1.3867\n", 252 | "Epoch 8/50\n", 253 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3847 - val_loss: 1.3839\n", 254 | "Epoch 9/50\n", 255 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3840 - val_loss: 1.3853\n", 256 | "Epoch 10/50\n", 257 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3858 - val_loss: 1.3852\n", 258 | "Epoch 11/50\n", 259 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3847 - val_loss: 1.3881\n", 260 | "Epoch 12/50\n", 261 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3847 - val_loss: 1.3851\n", 262 | "Epoch 13/50\n", 263 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3850 - val_loss: 1.3849\n", 264 | "Epoch 14/50\n", 265 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3871 - val_loss: 1.3833\n", 266 | "Epoch 15/50\n", 267 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3865 - val_loss: 1.3868\n", 268 | "Epoch 16/50\n", 269 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3861 - val_loss: 1.3833\n", 270 | "Epoch 17/50\n", 271 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3847 - val_loss: 1.3869\n", 272 | "Epoch 18/50\n", 273 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3853 - val_loss: 1.3825\n", 274 | "Epoch 19/50\n", 275 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3846 - val_loss: 1.3832\n", 276 | "Epoch 20/50\n", 277 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3843 - val_loss: 1.3833\n", 278 | "Epoch 21/50\n", 279 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3849 - val_loss: 1.3841\n", 280 | "Epoch 22/50\n", 281 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3849 - val_loss: 1.3827\n", 282 | "Epoch 23/50\n", 283 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3851 - val_loss: 1.3847\n", 284 | "Epoch 24/50\n", 285 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3842 - val_loss: 1.3839\n", 286 | "Epoch 25/50\n", 287 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3839 - val_loss: 1.3841\n", 288 | "Epoch 26/50\n", 289 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3840 - val_loss: 1.3853\n", 290 | "Epoch 27/50\n", 291 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3844 - val_loss: 1.3835\n", 292 | "Epoch 28/50\n", 293 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3842 - val_loss: 1.3846\n", 294 | "Epoch 29/50\n", 295 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3848 - val_loss: 1.3826\n", 296 | "Epoch 30/50\n", 297 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3848 - val_loss: 1.3820\n", 298 | "Epoch 31/50\n", 299 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3846 - val_loss: 1.3830\n", 300 | "Epoch 32/50\n", 301 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3860 - val_loss: 1.3827\n", 302 | "Epoch 33/50\n", 303 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3851 - val_loss: 1.3824\n", 304 | "Epoch 34/50\n", 305 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3846 - val_loss: 1.3829\n", 306 | "Epoch 35/50\n", 307 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3847 - val_loss: 1.3837\n", 308 | "Epoch 36/50\n", 309 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3871 - val_loss: 1.3888\n", 310 | "Epoch 37/50\n", 311 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3855 - val_loss: 1.3881\n", 312 | "Epoch 38/50\n", 313 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3871 - val_loss: 1.3851\n", 314 | "Epoch 39/50\n", 315 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3839 - val_loss: 1.3840\n", 316 | "Epoch 40/50\n", 317 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3838 - val_loss: 1.3828\n", 318 | "Epoch 41/50\n", 319 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3832 - val_loss: 1.3842\n", 320 | "Epoch 42/50\n", 321 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3862 - val_loss: 1.3821\n", 322 | "Epoch 43/50\n", 323 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3840 - val_loss: 1.3853\n", 324 | "Epoch 44/50\n", 325 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3869 - val_loss: 1.3894\n", 326 | "Epoch 45/50\n", 327 | "8192/8192 [==============================] - 0s 4us/step - loss: 1.3883 - val_loss: 1.3840\n", 328 | "Epoch 46/50\n", 329 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3857 - val_loss: 1.3829\n", 330 | "Epoch 47/50\n", 331 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3838 - val_loss: 1.3843\n", 332 | "Epoch 48/50\n", 333 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3837 - val_loss: 1.3849\n", 334 | "Epoch 49/50\n", 335 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3839 - val_loss: 1.3869\n", 336 | "Epoch 50/50\n", 337 | "8192/8192 [==============================] - 0s 3us/step - loss: 1.3846 - val_loss: 1.3827\n" 338 | ] 339 | }, 340 | { 341 | "data": { 342 | "text/plain": [ 343 | "" 344 | ] 345 | }, 346 | "execution_count": 25, 347 | "metadata": {}, 348 | "output_type": "execute_result" 349 | } 350 | ], 351 | "source": [ 352 | "decoder.fit(Doutput, data,\n", 353 | " epochs=50,\n", 354 | " batch_size=500,\n", 355 | " validation_data=(Dvoutput, val_data))" 356 | ] 357 | }, 358 | { 359 | "cell_type": "code", 360 | "execution_count": 26, 361 | "metadata": {}, 362 | "outputs": [ 363 | { 364 | "name": "stdout", 365 | "output_type": "stream", 366 | "text": [ 367 | "BER: 6122\n", 368 | "[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 369 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 370 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 371 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 372 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 373 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 374 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 375 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 376 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 377 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 378 | " 0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 0 0 0\n", 578 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 579 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 580 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 581 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 582 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 583 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 584 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 585 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 586 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 587 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 588 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", 589 | " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n" 590 | ] 591 | } 592 | ], 593 | "source": [ 594 | "decoded = decoder.predict(Doutput)\n", 595 | "pred_output = np.argmax(decoded,axis=1)\n", 596 | "no_errors = (pred_output != label)\n", 597 | "no_errors = no_errors.astype(int).sum()\n", 598 | "ber = no_errors \n", 599 | "print ('BER:',ber)\n", 600 | "print(pred_output)" 601 | ] 602 | }, 603 | { 604 | "cell_type": "code", 605 | "execution_count": null, 606 | "metadata": {}, 607 | "outputs": [], 608 | "source": [] 609 | } 610 | ], 611 | "metadata": { 612 | "kernelspec": { 613 | "display_name": "Python 3", 614 | "language": "python", 615 | "name": "python3" 616 | }, 617 | "language_info": { 618 | "codemirror_mode": { 619 | "name": "ipython", 620 | "version": 3 621 | }, 622 | "file_extension": ".py", 623 | "mimetype": "text/x-python", 624 | "name": "python", 625 | "nbconvert_exporter": "python", 626 | "pygments_lexer": "ipython3", 627 | "version": "3.7.4" 628 | } 629 | }, 630 | "nbformat": 4, 631 | "nbformat_minor": 2 632 | } 633 | -------------------------------------------------------------------------------- /bad_channel.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stderr", 10 | "output_type": "stream", 11 | "text": [ 12 | "Using TensorFlow backend.\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "# importing libs\n", 18 | "import numpy as np\n", 19 | "import tensorflow as tf\n", 20 | "from tensorflow import keras\n", 21 | "from keras.layers import Input, Dense, GaussianNoise, concatenate, Flatten, Conv1D,MaxPool1D\n", 22 | "from keras.models import Model\n", 23 | "from keras import regularizers\n", 24 | "from keras.layers.normalization import BatchNormalization\n", 25 | "from keras.optimizers import SGD\n", 26 | "import random as rn\n", 27 | "import os\n", 28 | "from keras.models import load_model" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 2, 34 | "metadata": {}, 35 | "outputs": [], 36 | "source": [ 37 | "# Loading data\n", 38 | "real_input=np.loadtxt('real_input.txt')\n", 39 | "#print(real_input.shape)\n", 40 | "Rinput=[]\n", 41 | "for i in range(0,131072):\n", 42 | " Rinput.append(real_input[i][1])\n", 43 | "Rinput=np.array(Rinput)\n", 44 | "Rinput=np.reshape(Rinput,(16384,8))\n", 45 | "#print(Rinput.shape)\n", 46 | "#print(Rinput[2])\n", 47 | "\n", 48 | "valinput=np.loadtxt('valinput.txt')\n", 49 | "#print(valinput.shape)\n", 50 | "Vinput=[]\n", 51 | "for i in range(0,8192):\n", 52 | " Vinput.append(real_input[i][1])\n", 53 | "Vinput=np.array(Vinput)\n", 54 | "Vinput=np.reshape(Vinput,(1024,8))\n", 55 | "\n", 56 | "real_output=np.loadtxt('real_output.txt')\n", 57 | "#print(real_output.shape)\n", 58 | "Routput=[]\n", 59 | "for i in range(0,131072):\n", 60 | " Sum=real_output[4*i][1]+real_output[4*i+1][1]+real_output[4*i+2][1]+real_output[4*i+3][1]\n", 61 | " mm=Sum/4\n", 62 | " Routput.append(mm)\n", 63 | "Routput=np.array(Routput)\n", 64 | "Routput=np.reshape(Routput,(16384,8))\n", 65 | "#print(Rinput.shape)\n", 66 | "#print(Routput[2])\n", 67 | "\n", 68 | "valoutput=np.loadtxt('valoutput.txt')\n", 69 | "#print(valoutput.shape)\n", 70 | "Voutput=[]\n", 71 | "for i in range(0,8192):\n", 72 | " Sum=valoutput[4*i][1]+valoutput[4*i+1][1]+valoutput[4*i+2][1]+valoutput[4*i+3][1]\n", 73 | " mm=Sum/4\n", 74 | " Voutput.append(mm)\n", 75 | "Voutput=np.array(Voutput)\n", 76 | "Voutput=np.reshape(Voutput,(1024,8))" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 3, 82 | "metadata": {}, 83 | "outputs": [], 84 | "source": [ 85 | "Ir=[0,1]\n", 86 | "If=[1,0]\n", 87 | "\n", 88 | "Ir1=[]\n", 89 | "If1=[]\n", 90 | "Ir2=[]\n", 91 | "If2=[]\n", 92 | "for i in range(0,16384):\n", 93 | " Ir1.append(Ir)\n", 94 | " If1.append(If)\n", 95 | " \n", 96 | "for i in range(0,1024):\n", 97 | " Ir2.append(Ir)\n", 98 | " If2.append(If)\n", 99 | " \n", 100 | "Ir1=np.array(Ir1)\n", 101 | "Ir2=np.array(Ir2)\n", 102 | "If1=np.array(If1)\n", 103 | "If2=np.array(If2)" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": 37, 109 | "metadata": {}, 110 | "outputs": [ 111 | { 112 | "name": "stdout", 113 | "output_type": "stream", 114 | "text": [ 115 | "Model: \"model_11\"\n", 116 | "_________________________________________________________________\n", 117 | "Layer (type) Output Shape Param # \n", 118 | "=================================================================\n", 119 | "input_16 (InputLayer) (None, 8) 0 \n", 120 | "_________________________________________________________________\n", 121 | "dense_89 (Dense) (None, 30) 270 \n", 122 | "_________________________________________________________________\n", 123 | "dense_90 (Dense) (None, 20) 620 \n", 124 | "_________________________________________________________________\n", 125 | "dense_91 (Dense) (None, 13) 273 \n", 126 | "_________________________________________________________________\n", 127 | "dense_92 (Dense) (None, 8) 112 \n", 128 | "_________________________________________________________________\n", 129 | "dense_93 (Dense) (None, 5) 45 \n", 130 | "_________________________________________________________________\n", 131 | "dense_94 (Dense) (None, 8) 48 \n", 132 | "_________________________________________________________________\n", 133 | "dense_95 (Dense) (None, 16) 144 \n", 134 | "_________________________________________________________________\n", 135 | "dense_96 (Dense) (None, 10) 170 \n", 136 | "_________________________________________________________________\n", 137 | "dense_97 (Dense) (None, 6) 66 \n", 138 | "_________________________________________________________________\n", 139 | "dense_98 (Dense) (None, 2) 14 \n", 140 | "=================================================================\n", 141 | "Total params: 1,762\n", 142 | "Trainable params: 1,762\n", 143 | "Non-trainable params: 0\n", 144 | "_________________________________________________________________\n", 145 | "None\n" 146 | ] 147 | } 148 | ], 149 | "source": [ 150 | "#Channel\n", 151 | "Inputsize = 8\n", 152 | "Outputsize = 8\n", 153 | "input_signal = Input(shape=(Inputsize,))\n", 154 | "lay1 = Dense(30, activation='relu')(input_signal)\n", 155 | "lay2 = Dense(20, activation='relu')(lay1)\n", 156 | "lay3 = Dense(13, activation='relu')(lay2)\n", 157 | "lay4 = Dense(8, activation='relu')(lay3)\n", 158 | "lay5 = Dense(5, activation='relu')(lay4)\n", 159 | "output_signal = Dense(Outputsize, activation='linear')(lay5)\n", 160 | "\n", 161 | "#generator = Model(input_signal, output_signal)\n", 162 | "\n", 163 | "#generator.compile(optimizer='adam', loss='categorical_crossentropy')\n", 164 | "#print (generator.summary())\n", 165 | "\n", 166 | "#Discriminator\n", 167 | "inputsize = 8\n", 168 | "outputsize = 2\n", 169 | "#input_sig = Input(shape=(inputsize,)\n", 170 | "\n", 171 | "layer1 = Dense(16, activation='relu')(output_signal)\n", 172 | "layer2 = Dense(10, activation='relu')(layer1)\n", 173 | "layer3 = Dense(6, activation='relu')(layer2)\n", 174 | "p = Dense(outputsize, activation='softmax')(layer3)\n", 175 | "\n", 176 | "#discriminator = Model(input_sig, p)\n", 177 | "\n", 178 | "#discriminator.compile(optimizer='adam', loss='categorical_crossentropy')\n", 179 | "#print (discriminator.summary())\n", 180 | "\n", 181 | "channel=Model(input_signal,p)\n", 182 | "channel.compile(optimizer='adam', loss='categorical_crossentropy')\n", 183 | "print (channel.summary())" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 11, 189 | "metadata": {}, 190 | "outputs": [ 191 | { 192 | "name": "stdout", 193 | "output_type": "stream", 194 | "text": [ 195 | "Model: \"model_5\"\n", 196 | "_________________________________________________________________\n", 197 | "Layer (type) Output Shape Param # \n", 198 | "=================================================================\n", 199 | "input_4 (InputLayer) (None, 8) 0 \n", 200 | "_________________________________________________________________\n", 201 | "dense_17 (Dense) (None, 16) 144 \n", 202 | "_________________________________________________________________\n", 203 | "dense_18 (Dense) (None, 10) 170 \n", 204 | "_________________________________________________________________\n", 205 | "dense_19 (Dense) (None, 6) 66 \n", 206 | "_________________________________________________________________\n", 207 | "dense_20 (Dense) (None, 2) 14 \n", 208 | "=================================================================\n", 209 | "Total params: 394\n", 210 | "Trainable params: 394\n", 211 | "Non-trainable params: 0\n", 212 | "_________________________________________________________________\n", 213 | "None\n" 214 | ] 215 | } 216 | ], 217 | "source": [ 218 | "#Discriminator\n", 219 | "input_sig = Input(shape=(inputsize,))\n", 220 | "disc=channel.layers[-4](input_sig)\n", 221 | "disc=channel.layers[-3](disc)\n", 222 | "disc=channel.layers[-2](disc)\n", 223 | "disc=channel.layers[-1](disc)\n", 224 | "discriminator = Model(input_sig, disc)\n", 225 | "\n", 226 | "discriminator.compile(optimizer='adam', loss='categorical_crossentropy')\n", 227 | "print (discriminator.summary())" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": 12, 233 | "metadata": {}, 234 | "outputs": [ 235 | { 236 | "name": "stdout", 237 | "output_type": "stream", 238 | "text": [ 239 | "Model: \"model_6\"\n", 240 | "_________________________________________________________________\n", 241 | "Layer (type) Output Shape Param # \n", 242 | "=================================================================\n", 243 | "input_3 (InputLayer) (None, 8) 0 \n", 244 | "_________________________________________________________________\n", 245 | "dense_11 (Dense) (None, 30) 270 \n", 246 | "_________________________________________________________________\n", 247 | "dense_12 (Dense) (None, 20) 620 \n", 248 | "_________________________________________________________________\n", 249 | "dense_13 (Dense) (None, 13) 273 \n", 250 | "_________________________________________________________________\n", 251 | "dense_14 (Dense) (None, 8) 112 \n", 252 | "_________________________________________________________________\n", 253 | "dense_15 (Dense) (None, 5) 45 \n", 254 | "_________________________________________________________________\n", 255 | "dense_16 (Dense) (None, 8) 48 \n", 256 | "=================================================================\n", 257 | "Total params: 1,368\n", 258 | "Trainable params: 1,368\n", 259 | "Non-trainable params: 0\n", 260 | "_________________________________________________________________\n", 261 | "None\n" 262 | ] 263 | } 264 | ], 265 | "source": [ 266 | "#Generator\n", 267 | "generator = Model(input_signal, output_signal)\n", 268 | "\n", 269 | "generator.compile(optimizer='adam', loss='categorical_crossentropy')\n", 270 | "print (generator.summary())" 271 | ] 272 | }, 273 | { 274 | "cell_type": "code", 275 | "execution_count": 13, 276 | "metadata": {}, 277 | "outputs": [ 278 | { 279 | "data": { 280 | "text/plain": [ 281 | "" 282 | ] 283 | }, 284 | "execution_count": 13, 285 | "metadata": {}, 286 | "output_type": "execute_result" 287 | } 288 | ], 289 | "source": [ 290 | "#初始化权重\n", 291 | "keras.initializers.RandomUniform(minval=-0.05, maxval=0.05, seed=None)" 292 | ] 293 | }, 294 | { 295 | "cell_type": "code", 296 | "execution_count": 44, 297 | "metadata": {}, 298 | "outputs": [ 299 | { 300 | "name": "stdout", 301 | "output_type": "stream", 302 | "text": [ 303 | "Train on 16384 samples, validate on 1024 samples\n", 304 | "Epoch 1/50\n", 305 | "16384/16384 [==============================] - 0s 3us/step - loss: 3.2257e-05 - val_loss: 3.1948e-05\n", 306 | "Epoch 2/50\n", 307 | "16384/16384 [==============================] - 0s 3us/step - loss: 3.1700e-05 - val_loss: 3.1471e-05\n", 308 | "Epoch 3/50\n", 309 | "16384/16384 [==============================] - 0s 2us/step - loss: 3.1149e-05 - val_loss: 3.0875e-05\n", 310 | "Epoch 4/50\n", 311 | "16384/16384 [==============================] - 0s 3us/step - loss: 3.0614e-05 - val_loss: 3.0397e-05\n" 312 | ] 313 | }, 314 | { 315 | "name": "stderr", 316 | "output_type": "stream", 317 | "text": [ 318 | "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\keras\\engine\\training.py:297: UserWarning: Discrepancy between trainable weights and collected trainable weights, did you set `model.trainable` without calling `model.compile` after ?\n", 319 | " 'Discrepancy between trainable weights and collected trainable'\n" 320 | ] 321 | }, 322 | { 323 | "name": "stdout", 324 | "output_type": "stream", 325 | "text": [ 326 | "Epoch 5/50\n", 327 | "16384/16384 [==============================] - 0s 3us/step - loss: 3.0077e-05 - val_loss: 2.9802e-05\n", 328 | "Epoch 6/50\n", 329 | "16384/16384 [==============================] - 0s 2us/step - loss: 2.9557e-05 - val_loss: 2.9325e-05\n", 330 | "Epoch 7/50\n", 331 | "16384/16384 [==============================] - 0s 2us/step - loss: 2.9045e-05 - val_loss: 2.8808e-05\n", 332 | "Epoch 8/50\n", 333 | "16384/16384 [==============================] - 0s 2us/step - loss: 2.8534e-05 - val_loss: 2.8252e-05\n", 334 | "Epoch 9/50\n", 335 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.8038e-05 - val_loss: 2.7775e-05\n", 336 | "Epoch 10/50\n", 337 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.7548e-05 - val_loss: 2.7299e-05\n", 338 | "Epoch 11/50\n", 339 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.7068e-05 - val_loss: 2.6822e-05\n", 340 | "Epoch 12/50\n", 341 | "16384/16384 [==============================] - 0s 2us/step - loss: 2.6595e-05 - val_loss: 2.6345e-05\n", 342 | "Epoch 13/50\n", 343 | "16384/16384 [==============================] - 0s 2us/step - loss: 2.6129e-05 - val_loss: 2.5868e-05\n", 344 | "Epoch 14/50\n", 345 | "16384/16384 [==============================] - 0s 2us/step - loss: 2.5672e-05 - val_loss: 2.5393e-05\n", 346 | "Epoch 15/50\n", 347 | "16384/16384 [==============================] - 0s 2us/step - loss: 2.5219e-05 - val_loss: 2.5034e-05\n", 348 | "Epoch 16/50\n", 349 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.4775e-05 - val_loss: 2.4557e-05\n", 350 | "Epoch 17/50\n", 351 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.4344e-05 - val_loss: 2.4080e-05\n", 352 | "Epoch 18/50\n", 353 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.3910e-05 - val_loss: 2.3722e-05\n", 354 | "Epoch 19/50\n", 355 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.3492e-05 - val_loss: 2.3246e-05\n", 356 | "Epoch 20/50\n", 357 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.3076e-05 - val_loss: 2.2888e-05\n", 358 | "Epoch 21/50\n", 359 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.2672e-05 - val_loss: 2.2433e-05\n", 360 | "Epoch 22/50\n", 361 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.2264e-05 - val_loss: 2.2053e-05\n", 362 | "Epoch 23/50\n", 363 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.1873e-05 - val_loss: 2.1696e-05\n", 364 | "Epoch 24/50\n", 365 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.1489e-05 - val_loss: 2.1338e-05\n", 366 | "Epoch 25/50\n", 367 | "16384/16384 [==============================] - 0s 2us/step - loss: 2.1107e-05 - val_loss: 2.0879e-05\n", 368 | "Epoch 26/50\n", 369 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.0730e-05 - val_loss: 2.0504e-05\n", 370 | "Epoch 27/50\n", 371 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.0363e-05 - val_loss: 2.0146e-05\n", 372 | "Epoch 28/50\n", 373 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.0002e-05 - val_loss: 1.9789e-05\n", 374 | "Epoch 29/50\n", 375 | "16384/16384 [==============================] - 0s 2us/step - loss: 1.9647e-05 - val_loss: 1.9431e-05\n", 376 | "Epoch 30/50\n", 377 | "16384/16384 [==============================] - 0s 2us/step - loss: 1.9297e-05 - val_loss: 1.9073e-05\n", 378 | "Epoch 31/50\n", 379 | "16384/16384 [==============================] - 0s 2us/step - loss: 1.8952e-05 - val_loss: 1.8835e-05\n", 380 | "Epoch 32/50\n", 381 | "16384/16384 [==============================] - 0s 2us/step - loss: 1.8611e-05 - val_loss: 1.8477e-05\n", 382 | "Epoch 33/50\n", 383 | "16384/16384 [==============================] - 0s 2us/step - loss: 1.8282e-05 - val_loss: 1.8120e-05\n", 384 | "Epoch 34/50\n", 385 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.7958e-05 - val_loss: 1.7762e-05\n", 386 | "Epoch 35/50\n", 387 | "16384/16384 [==============================] - 0s 4us/step - loss: 1.7637e-05 - val_loss: 1.7524e-05\n", 388 | "Epoch 36/50\n", 389 | "16384/16384 [==============================] - 0s 4us/step - loss: 1.7315e-05 - val_loss: 1.7166e-05\n", 390 | "Epoch 37/50\n", 391 | "16384/16384 [==============================] - 0s 4us/step - loss: 1.7014e-05 - val_loss: 1.6808e-05\n", 392 | "Epoch 38/50\n", 393 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.6702e-05 - val_loss: 1.6570e-05\n", 394 | "Epoch 39/50\n", 395 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.6408e-05 - val_loss: 1.6212e-05\n", 396 | "Epoch 40/50\n", 397 | "16384/16384 [==============================] - 0s 2us/step - loss: 1.6108e-05 - val_loss: 1.5974e-05\n", 398 | "Epoch 41/50\n", 399 | "16384/16384 [==============================] - 0s 2us/step - loss: 1.5828e-05 - val_loss: 1.5735e-05\n", 400 | "Epoch 42/50\n", 401 | "16384/16384 [==============================] - 0s 2us/step - loss: 1.5531e-05 - val_loss: 1.5378e-05\n", 402 | "Epoch 43/50\n", 403 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.5258e-05 - val_loss: 1.5139e-05\n", 404 | "Epoch 44/50\n", 405 | "16384/16384 [==============================] - 0s 2us/step - loss: 1.4989e-05 - val_loss: 1.4901e-05\n", 406 | "Epoch 45/50\n", 407 | "16384/16384 [==============================] - 0s 2us/step - loss: 1.4713e-05 - val_loss: 1.4543e-05\n", 408 | "Epoch 46/50\n", 409 | "16384/16384 [==============================] - 0s 4us/step - loss: 1.4447e-05 - val_loss: 1.4305e-05\n", 410 | "Epoch 47/50\n", 411 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.4190e-05 - val_loss: 1.4067e-05\n", 412 | "Epoch 48/50\n", 413 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.3935e-05 - val_loss: 1.3828e-05\n", 414 | "Epoch 49/50\n", 415 | "16384/16384 [==============================] - 0s 4us/step - loss: 1.3684e-05 - val_loss: 1.3590e-05\n", 416 | "Epoch 50/50\n", 417 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.3438e-05 - val_loss: 1.3351e-05\n" 418 | ] 419 | }, 420 | { 421 | "data": { 422 | "text/plain": [ 423 | "" 424 | ] 425 | }, 426 | "execution_count": 44, 427 | "metadata": {}, 428 | "output_type": "execute_result" 429 | } 430 | ], 431 | "source": [ 432 | "#Training of discriminator\n", 433 | "discriminator.fit(Routput, Ir1,\n", 434 | " epochs=50,\n", 435 | " batch_size=500,\n", 436 | " validation_data=(Voutput, Ir2))" 437 | ] 438 | }, 439 | { 440 | "cell_type": "code", 441 | "execution_count": 45, 442 | "metadata": {}, 443 | "outputs": [], 444 | "source": [ 445 | "Foutput = generator.predict(Rinput) \n", 446 | "FVoutput=generator.predict(Vinput)" 447 | ] 448 | }, 449 | { 450 | "cell_type": "code", 451 | "execution_count": 46, 452 | "metadata": {}, 453 | "outputs": [ 454 | { 455 | "name": "stdout", 456 | "output_type": "stream", 457 | "text": [ 458 | "Train on 16384 samples, validate on 1024 samples\n", 459 | "Epoch 1/50\n", 460 | "16384/16384 [==============================] - 0s 4us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 461 | "Epoch 2/50\n", 462 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 463 | "Epoch 3/50\n", 464 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 465 | "Epoch 4/50\n", 466 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 467 | "Epoch 5/50\n", 468 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 469 | "Epoch 6/50\n", 470 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 471 | "Epoch 7/50\n", 472 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 473 | "Epoch 8/50\n", 474 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 475 | "Epoch 9/50\n", 476 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 477 | "Epoch 10/50\n", 478 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 479 | "Epoch 11/50\n", 480 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 481 | "Epoch 12/50\n", 482 | "16384/16384 [==============================] - 0s 4us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 483 | "Epoch 13/50\n", 484 | "16384/16384 [==============================] - 0s 4us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 485 | "Epoch 14/50\n", 486 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 487 | "Epoch 15/50\n", 488 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 489 | "Epoch 16/50\n", 490 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 491 | "Epoch 17/50\n", 492 | "16384/16384 [==============================] - 0s 4us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 493 | "Epoch 18/50\n", 494 | "16384/16384 [==============================] - 0s 4us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 495 | "Epoch 19/50\n", 496 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 497 | "Epoch 20/50\n", 498 | "16384/16384 [==============================] - 0s 4us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 499 | "Epoch 21/50\n", 500 | "16384/16384 [==============================] - 0s 4us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 501 | "Epoch 22/50\n", 502 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 503 | "Epoch 23/50\n", 504 | "16384/16384 [==============================] - 0s 4us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 505 | "Epoch 24/50\n", 506 | "16384/16384 [==============================] - 0s 5us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 507 | "Epoch 25/50\n", 508 | "16384/16384 [==============================] - 0s 5us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 509 | "Epoch 26/50\n", 510 | "16384/16384 [==============================] - 0s 4us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 511 | "Epoch 27/50\n", 512 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 513 | "Epoch 28/50\n", 514 | "16384/16384 [==============================] - 0s 4us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 515 | "Epoch 29/50\n", 516 | "16384/16384 [==============================] - 0s 5us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 517 | "Epoch 30/50\n", 518 | "16384/16384 [==============================] - 0s 4us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 519 | "Epoch 31/50\n", 520 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.3196e-09 - val_loss: 7.3342e-09\n", 521 | "Epoch 32/50\n", 522 | "16384/16384 [==============================] - 0s 3us/step - loss: 4.4456e-09 - val_loss: 0.0000e+00\n", 523 | "Epoch 33/50\n", 524 | "16384/16384 [==============================] - 0s 3us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 525 | "Epoch 34/50\n", 526 | "16384/16384 [==============================] - 0s 3us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 527 | "Epoch 35/50\n", 528 | "16384/16384 [==============================] - 0s 3us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 529 | "Epoch 36/50\n", 530 | "16384/16384 [==============================] - 0s 3us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 531 | "Epoch 37/50\n", 532 | "16384/16384 [==============================] - 0s 3us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 533 | "Epoch 38/50\n", 534 | "16384/16384 [==============================] - 0s 3us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 535 | "Epoch 39/50\n", 536 | "16384/16384 [==============================] - 0s 3us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 537 | "Epoch 40/50\n", 538 | "16384/16384 [==============================] - 0s 4us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 539 | "Epoch 41/50\n", 540 | "16384/16384 [==============================] - 0s 3us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 541 | "Epoch 42/50\n", 542 | "16384/16384 [==============================] - 0s 3us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 543 | "Epoch 43/50\n", 544 | "16384/16384 [==============================] - 0s 4us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 545 | "Epoch 44/50\n", 546 | "16384/16384 [==============================] - 0s 6us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 547 | "Epoch 45/50\n", 548 | "16384/16384 [==============================] - 0s 4us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 549 | "Epoch 46/50\n", 550 | "16384/16384 [==============================] - 0s 3us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 551 | "Epoch 47/50\n", 552 | "16384/16384 [==============================] - 0s 3us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 553 | "Epoch 48/50\n", 554 | "16384/16384 [==============================] - 0s 3us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 555 | "Epoch 49/50\n", 556 | "16384/16384 [==============================] - 0s 3us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n", 557 | "Epoch 50/50\n", 558 | "16384/16384 [==============================] - 0s 4us/step - loss: 0.0000e+00 - val_loss: 0.0000e+00\n" 559 | ] 560 | }, 561 | { 562 | "data": { 563 | "text/plain": [ 564 | "" 565 | ] 566 | }, 567 | "execution_count": 46, 568 | "metadata": {}, 569 | "output_type": "execute_result" 570 | } 571 | ], 572 | "source": [ 573 | "#Training of channel step 1\n", 574 | "channel.layers[-1].trainable = False\n", 575 | "channel.layers[-2].trainable = False\n", 576 | "channel.layers[-3].trainable = False\n", 577 | "channel.layers[-4].trainable = False\n", 578 | "channel.fit(Foutput, If1,\n", 579 | " epochs=50,\n", 580 | " batch_size=500,\n", 581 | " validation_data=(FVoutput, If2))" 582 | ] 583 | }, 584 | { 585 | "cell_type": "code", 586 | "execution_count": 47, 587 | "metadata": {}, 588 | "outputs": [ 589 | { 590 | "name": "stdout", 591 | "output_type": "stream", 592 | "text": [ 593 | "Train on 16384 samples, validate on 1024 samples\n", 594 | "Epoch 1/50\n", 595 | "16384/16384 [==============================] - 0s 4us/step - loss: 2.5640 - val_loss: 0.0133\n", 596 | "Epoch 2/50\n", 597 | "16384/16384 [==============================] - 0s 3us/step - loss: 0.0023 - val_loss: 3.5658e-04\n", 598 | "Epoch 3/50\n", 599 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.5289e-04 - val_loss: 2.0542e-04\n", 600 | "Epoch 4/50\n", 601 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.7170e-04 - val_loss: 1.5304e-04\n", 602 | "Epoch 5/50\n", 603 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.3154e-04 - val_loss: 1.2018e-04\n", 604 | "Epoch 6/50\n", 605 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.0564e-04 - val_loss: 9.8228e-05\n", 606 | "Epoch 7/50\n", 607 | "16384/16384 [==============================] - 0s 3us/step - loss: 8.7154e-05 - val_loss: 8.0970e-05\n", 608 | "Epoch 8/50\n", 609 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.0650e-05 - val_loss: 6.2595e-05\n", 610 | "Epoch 9/50\n", 611 | "16384/16384 [==============================] - 0s 3us/step - loss: 5.3169e-05 - val_loss: 4.7665e-05\n", 612 | "Epoch 10/50\n", 613 | "16384/16384 [==============================] - 0s 4us/step - loss: 3.9880e-05 - val_loss: 3.4232e-05\n", 614 | "Epoch 11/50\n", 615 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.6001e-05 - val_loss: 1.9738e-05\n", 616 | "Epoch 12/50\n", 617 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.5803e-05 - val_loss: 1.3022e-05\n", 618 | "Epoch 13/50\n", 619 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.1051e-05 - val_loss: 1.0383e-05\n", 620 | "Epoch 14/50\n", 621 | "16384/16384 [==============================] - 0s 3us/step - loss: 9.2305e-06 - val_loss: 8.8263e-06\n", 622 | "Epoch 15/50\n", 623 | "16384/16384 [==============================] - 0s 3us/step - loss: 7.7410e-06 - val_loss: 7.3882e-06\n", 624 | "Epoch 16/50\n", 625 | "16384/16384 [==============================] - 0s 3us/step - loss: 6.5206e-06 - val_loss: 6.3559e-06\n", 626 | "Epoch 17/50\n", 627 | "16384/16384 [==============================] - 0s 3us/step - loss: 5.6899e-06 - val_loss: 5.6050e-06\n", 628 | "Epoch 18/50\n", 629 | "16384/16384 [==============================] - 0s 3us/step - loss: 5.0314e-06 - val_loss: 4.9029e-06\n", 630 | "Epoch 19/50\n", 631 | "16384/16384 [==============================] - 0s 3us/step - loss: 4.3824e-06 - val_loss: 4.3067e-06\n", 632 | "Epoch 20/50\n", 633 | "16384/16384 [==============================] - 0s 4us/step - loss: 3.8820e-06 - val_loss: 3.8420e-06\n", 634 | "Epoch 21/50\n", 635 | "16384/16384 [==============================] - 0s 4us/step - loss: 3.4787e-06 - val_loss: 3.4483e-06\n", 636 | "Epoch 22/50\n", 637 | "16384/16384 [==============================] - 0s 4us/step - loss: 3.1169e-06 - val_loss: 3.0869e-06\n", 638 | "Epoch 23/50\n", 639 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.7982e-06 - val_loss: 2.7402e-06\n", 640 | "Epoch 24/50\n", 641 | "16384/16384 [==============================] - 0s 3us/step - loss: 2.4765e-06 - val_loss: 2.4237e-06\n", 642 | "Epoch 25/50\n", 643 | "16384/16384 [==============================] - 0s 4us/step - loss: 2.2035e-06 - val_loss: 2.1751e-06\n", 644 | "Epoch 26/50\n", 645 | "16384/16384 [==============================] - 0s 4us/step - loss: 1.9803e-06 - val_loss: 1.9520e-06\n", 646 | "Epoch 27/50\n", 647 | "16384/16384 [==============================] - 0s 4us/step - loss: 1.7895e-06 - val_loss: 1.7757e-06\n", 648 | "Epoch 28/50\n", 649 | "16384/16384 [==============================] - 0s 4us/step - loss: 1.6381e-06 - val_loss: 1.6361e-06\n", 650 | "Epoch 29/50\n", 651 | "16384/16384 [==============================] - 0s 4us/step - loss: 1.4978e-06 - val_loss: 1.4744e-06\n", 652 | "Epoch 30/50\n", 653 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.3468e-06 - val_loss: 1.3269e-06\n", 654 | "Epoch 31/50\n", 655 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.2121e-06 - val_loss: 1.1813e-06\n", 656 | "Epoch 32/50\n", 657 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.0965e-06 - val_loss: 1.0807e-06\n", 658 | "Epoch 33/50\n", 659 | "16384/16384 [==============================] - 0s 3us/step - loss: 1.0099e-06 - val_loss: 9.9698e-07\n", 660 | "Epoch 34/50\n", 661 | "16384/16384 [==============================] - 0s 3us/step - loss: 9.3133e-07 - val_loss: 9.2748e-07\n", 662 | "Epoch 35/50\n", 663 | "16384/16384 [==============================] - 0s 4us/step - loss: 8.6866e-07 - val_loss: 8.6589e-07\n", 664 | "Epoch 36/50\n", 665 | "16384/16384 [==============================] - 0s 5us/step - loss: 8.1427e-07 - val_loss: 8.0431e-07\n", 666 | "Epoch 37/50\n", 667 | "16384/16384 [==============================] - 0s 6us/step - loss: 7.6095e-07 - val_loss: 7.5169e-07\n", 668 | "Epoch 38/50\n", 669 | "16384/16384 [==============================] - 0s 4us/step - loss: 7.1567e-07 - val_loss: 7.1327e-07\n", 670 | "Epoch 39/50\n", 671 | "16384/16384 [==============================] - 0s 3us/step - loss: 6.7753e-07 - val_loss: 6.7486e-07\n", 672 | "Epoch 40/50\n", 673 | "16384/16384 [==============================] - 0s 3us/step - loss: 6.4273e-07 - val_loss: 6.3644e-07\n", 674 | "Epoch 41/50\n", 675 | "16384/16384 [==============================] - 0s 3us/step - loss: 5.9754e-07 - val_loss: 5.9162e-07\n", 676 | "Epoch 42/50\n", 677 | "16384/16384 [==============================] - 0s 3us/step - loss: 5.5430e-07 - val_loss: 5.5483e-07\n", 678 | "Epoch 43/50\n", 679 | "16384/16384 [==============================] - 0s 3us/step - loss: 5.2103e-07 - val_loss: 5.1700e-07\n", 680 | "Epoch 44/50\n", 681 | "16384/16384 [==============================] - 0s 3us/step - loss: 4.8551e-07 - val_loss: 4.7125e-07\n", 682 | "Epoch 45/50\n", 683 | "16384/16384 [==============================] - 0s 3us/step - loss: 4.4751e-07 - val_loss: 4.3504e-07\n", 684 | "Epoch 46/50\n", 685 | "16384/16384 [==============================] - 0s 3us/step - loss: 4.0831e-07 - val_loss: 4.0454e-07\n", 686 | "Epoch 47/50\n", 687 | "16384/16384 [==============================] - 0s 3us/step - loss: 3.8089e-07 - val_loss: 3.7462e-07\n", 688 | "Epoch 48/50\n", 689 | "16384/16384 [==============================] - 0s 3us/step - loss: 3.5560e-07 - val_loss: 3.5146e-07\n", 690 | "Epoch 49/50\n", 691 | "16384/16384 [==============================] - 0s 3us/step - loss: 3.3309e-07 - val_loss: 3.2887e-07\n", 692 | "Epoch 50/50\n", 693 | "16384/16384 [==============================] - 0s 3us/step - loss: 3.1020e-07 - val_loss: 3.0000e-07\n" 694 | ] 695 | }, 696 | { 697 | "data": { 698 | "text/plain": [ 699 | "" 700 | ] 701 | }, 702 | "execution_count": 47, 703 | "metadata": {}, 704 | "output_type": "execute_result" 705 | } 706 | ], 707 | "source": [ 708 | "#Training of the channel\n", 709 | "channel.layers[-1].trainable = False\n", 710 | "channel.layers[-2].trainable = False\n", 711 | "channel.layers[-3].trainable = False\n", 712 | "channel.layers[-4].trainable = False\n", 713 | "channel.fit(Rinput, Ir1,\n", 714 | " epochs=50,\n", 715 | " batch_size=500,\n", 716 | " validation_data=(Vinput, Ir2))" 717 | ] 718 | }, 719 | { 720 | "cell_type": "code", 721 | "execution_count": 48, 722 | "metadata": {}, 723 | "outputs": [ 724 | { 725 | "name": "stdout", 726 | "output_type": "stream", 727 | "text": [ 728 | "Model: \"model_12\"\n", 729 | "_________________________________________________________________\n", 730 | "Layer (type) Output Shape Param # \n", 731 | "=================================================================\n", 732 | "input_17 (InputLayer) (None, 8) 0 \n", 733 | "_________________________________________________________________\n", 734 | "dense_89 (Dense) (None, 30) 270 \n", 735 | "_________________________________________________________________\n", 736 | "dense_90 (Dense) (None, 20) 620 \n", 737 | "_________________________________________________________________\n", 738 | "dense_91 (Dense) (None, 13) 273 \n", 739 | "_________________________________________________________________\n", 740 | "dense_92 (Dense) (None, 8) 112 \n", 741 | "_________________________________________________________________\n", 742 | "dense_93 (Dense) (None, 5) 45 \n", 743 | "_________________________________________________________________\n", 744 | "dense_94 (Dense) (None, 8) 48 \n", 745 | "=================================================================\n", 746 | "Total params: 1,368\n", 747 | "Trainable params: 1,368\n", 748 | "Non-trainable params: 0\n", 749 | "_________________________________________________________________\n", 750 | "None\n" 751 | ] 752 | } 753 | ], 754 | "source": [ 755 | "Inp=Input(shape=(Inputsize,))\n", 756 | "gener=channel.layers[-10](Inp)\n", 757 | "gener=channel.layers[-9](gener)\n", 758 | "gener=channel.layers[-8](gener)\n", 759 | "gener=channel.layers[-7](gener)\n", 760 | "gener=channel.layers[-6](gener)\n", 761 | "gener=channel.layers[-5](gener)\n", 762 | "\n", 763 | "Generator=Model(Inp, gener)\n", 764 | "Generator.compile(optimizer='adam', loss='categorical_crossentropy')\n", 765 | "print(Generator.summary())" 766 | ] 767 | }, 768 | { 769 | "cell_type": "code", 770 | "execution_count": 49, 771 | "metadata": {}, 772 | "outputs": [], 773 | "source": [ 774 | "from keras.models import load_model\n", 775 | "Generator.save('channel_generator.model')" 776 | ] 777 | }, 778 | { 779 | "cell_type": "code", 780 | "execution_count": null, 781 | "metadata": {}, 782 | "outputs": [], 783 | "source": [] 784 | } 785 | ], 786 | "metadata": { 787 | "kernelspec": { 788 | "display_name": "Python 3", 789 | "language": "python", 790 | "name": "python3" 791 | }, 792 | "language_info": { 793 | "codemirror_mode": { 794 | "name": "ipython", 795 | "version": 3 796 | }, 797 | "file_extension": ".py", 798 | "mimetype": "text/x-python", 799 | "name": "python", 800 | "nbconvert_exporter": "python", 801 | "pygments_lexer": "ipython3", 802 | "version": "3.7.4" 803 | } 804 | }, 805 | "nbformat": 4, 806 | "nbformat_minor": 2 807 | } 808 | --------------------------------------------------------------------------------