1 Star 0 Fork 1

xiaodangshan/PAPR-net

forked from zhoub86/PAPR-net 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
training.py 1.85 KB
一键复制 编辑 原始数据 按行查看 历史
XieYe9909 提交于 2020-03-22 23:31 . PAPR net
import numpy as np
from ofdm import OFDMTransmitter
from PAPRNet import papr_net, tf_papr
from initialize.params import bit_allocation, coef, channel
from keras.callbacks import ReduceLROnPlateau, CSVLogger, EarlyStopping
from keras.optimizers import adam
from keras.models import load_model
params = dict()
params['BitAllocation'] = bit_allocation
params['Coef'] = coef
train_num = 5000
test_num = 100
symbol_num = train_num + test_num
bits_per_symbol = sum(params['BitAllocation'])
bit_send = np.random.randint(0, 2, bits_per_symbol * symbol_num)
tx = OFDMTransmitter(**params)
ofdm_chunks = tx.get_qammod(bit_send)
ofdm_chunks = np.concatenate([np.expand_dims(ofdm_chunks.real, 1), np.expand_dims(ofdm_chunks.imag, 1)], axis=1)
ofdm_train = ofdm_chunks[0: train_num, :, 0: -1]
ofdm_train = np.repeat(ofdm_train, repeats=6, axis=0)
ofdm_test = ofdm_chunks[train_num:, :, 0: -1]
sig_train = np.zeros(6 * train_num)
sig_test = np.zeros(test_num)
encoder = load_model('pre_train/encoder.hdf5')
decoder = load_model('pre_train/decoder.hdf5')
rate = 30
net = papr_net(encoder, decoder, channel=channel[0: -1], snr=20)
callbacks = list()
callbacks.append(ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=10, verbose=1, mode='min', min_delta=0.01,
cooldown=0, min_lr=1e-10))
callbacks.append(CSVLogger('training/train_log_%d.csv' % rate, separator=',', append=False))
callbacks.append(EarlyStopping(monitor='val_loss', min_delta=0.001, patience=50, verbose=0, mode='min'))
optimizer = adam(learning_rate=0.001)
net.compile(loss=['mse', tf_papr], loss_weights=[1, rate / 100], optimizer=optimizer)
net.fit(ofdm_train, [ofdm_train, sig_train], validation_data=(ofdm_test, [ofdm_test, sig_test]), epochs=120,
batch_size=50, callbacks=callbacks)
encoder.save('training/encoder_%d.hdf5' % rate)
decoder.save('training/decoder_%d.hdf5' % rate)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chenxuanlut/PAPR-net.git
git@gitee.com:chenxuanlut/PAPR-net.git
chenxuanlut
PAPR-net
PAPR-net
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385