Closed JJYjackson closed 1 year ago
您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档、常见问题、历史Issue、AI社区来寻求解答。祝您生活愉快~
Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the API,FAQ,Github Issue and AI community to get the answer.Have a nice day!
请问这是自己的代码还是官方提供的
请问这是自己的代码还是官方提供的
您好这是我自己的代码,希望大佬能帮我看看是什么问题?
RADIOML 2016.04C https://aistudio.baidu.com/aistudio/datasetdetail/80514
!/usr/bin/env python
coding: utf-8
In[1]:
import paddle import paddle.vision.transforms as T from net import senet154, se_resnet50, se_resnet101, se_resnet152, se_resnext50_32x4d, se_resnext101_32x4d, senet103 from net_resnet import resnet18, resnet34, resnet50, resnet101, resnet152, resnext50_32x4d, resnext101_32x8d, wide_resnet50_2, wide_resnet101_2 from cnn1_cnn2 import cnn1, cnn2
In[4]:
import pickle import matplotlib.pyplot as plt import numpy as np
加载数据集
with open(r'/home/titan-306/workspace/JJY/R2016C-MR_compare/data/data80514/2016.04C.multisnr.pkl','rb') as xd1: Xd = pickle.load(xd1, encoding='latin1') snrs, mods = map(lambda j: sorted(list(set(map(lambda x: x[j], Xd.keys())))), [1, 0]) #set() 函数创建一个无序不重复元素集,可进行关系测试, 删除重复数据, 还可以计算交际、差集、并集等。
X = [] lbl = [] print('信噪比为:',snrs) print('调制模式为:',mods) for mod in mods: for snr in snrs: X.append(Xd[(mod, snr)]) #循环取出数值 for i in range(Xd[(mod, snr)].shape[0]): lbl.append((mod, snr)) X = np.vstack(X) #垂直(按照行顺序)的把数组给堆叠起来 print(X.shape) print(lbl[0:5])
对数据进行分区 数据集划分 60%/20%/20%
n_examples = X.shape[0] n_train = int(n_examples * 0.7) #训练集的数量 train_idx = np.random.choice(range(0, n_examples), size=n_train, replace=False)
测试集=验证集
test_idx = list(set(range(0,n_examples))-set(train_idx)) EsNoArray = [] for idx in test_idx: EsNoArray.append(lbl[idx][1]) EsNoArray = np.reshape(EsNoArray, len(EsNoArray)) print(EsNoArray)
X_train = X[train_idx] X_test = X[test_idx] row = 2 col = 128 X_train = np.asarray(list(map(lambda x: np.reshape(x, (row, col, 1)), X_train))) #将列表转换为数组 ??? 对列表可以进行reshape X_test = np.asarray(list(map(lambda x: np.reshape(x, (row, col, 1)), X_test)))
print('训练集的shape为:{}'.format(X_train.shape)) print('测试集的shape为:{}'.format(X_test.shape))
Y_train = list(map(lambda x: mods.index(lbl[x][0]), train_idx)) Y_train_snrs = list(map(lambda x: snrs.index(lbl[x][1]), train_idx))
Y_test = list(map(lambda x: mods.index(lbl[x][0]), test_idx)) Y_test_snrs = list(map(lambda x: snrs.index(lbl[x][1]), test_idx))
in_shp = list(X_train.shape[1:])
print(Y_train[0:10], Y_train_snrs[0:10])
数据集自定义
In[5]:
数据集自定义
import paddle.vision.transforms as T
class MR_dataset(paddle.io.Dataset): """ 步骤一:继承paddle.io.Dataset类 """ def init(self, mode: str ='train'): """ 步骤二:实现构造函数,定义数据读取方式 """ super(MR_dataset, self).init()
实例化数据集
In[6]:
train_dataset = MR_dataset(mode='train') print(train_dataset[0][0].shape) print(train_dataset[0][1], train_dataset[0][1].shape, len(train_dataset)) print('**') test_dataset = MR_dataset(mode='test') print(test_dataset[0][0].shape) print(test_dataset[0][1], len(test_dataset))
In[7]:
model_CNN1 = cnn1()
In[8]:
model_senet154
model_CNN1 = paddle.Model(model_CNN1) model_CNN1.summary((None, 1, 2, 128))
mods = ['8PSK', 'AM-DSB', 'AM-SSB', 'BPSK', 'CPFSK', 'GFSK', 'PAM4', 'QAM16', 'QAM64', 'QPSK', 'WBFM']
snrs = [-20, -18, -16, -14, -12, -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18]