Example #1
0
def ToInputShape(data,net_name,norm=True,test_flag = False):
    data = data.astype(np.float32)
    batchsize=data.shape[0]
    if net_name=='LSTM':
        result =[]
        for i in range(0,batchsize):
            randomdata=random_transform_1d(data[i],finesize = 2700,test_flag=test_flag)
            result.append(dsp.getfeature(randomdata))
        result = np.array(result).reshape(batchsize,2700*5)
    elif net_name=='CNN' or net_name=='resnet18_1d':
        result =[]
        for i in range(0,batchsize):
            randomdata=random_transform_1d(data[i],finesize = 2700,test_flag=test_flag)
            # result.append(dsp.getfeature(randomdata,ch_num = 6))
            result.append(randomdata)
        result = np.array(result)
        if norm:
            result = Normalize(result,maxmin = 1000,avg=0,sigma=1000)
        result = result.reshape(batchsize,1,2700)

    elif net_name in ['dfcnn','resnet18','densenet121','densenet201','resnet101','resnet50']:
        result =[]
        for i in range(0,batchsize):
            spectrum = dsp.signal2spectrum(data[i])
            spectrum = random_transform_2d(spectrum,(224,122),test_flag=test_flag)
            result.append(spectrum)
        result = np.array(result)
        if norm:
            #sleep_def : std,mean,median = 0.4157 0.3688 0.2473
            #challge 2018 : std,mean,median,max= 0.2972 0.3008 0.2006 2.0830
            result=Normalize(result,2,0.3,1)
        result = result.reshape(batchsize,1,224,122)
        # print(result.shape)

    return result
Example #2
0
def ToInputShape(data, opt, test_flag=False):
    data = data.astype(np.float32)
    batchsize = data.shape[0]
    if data.ndim == 2:
        loadsize = data.shape[1]
    elif data.ndim == 3:
        loadsize = data.shape[2]

    _finesize = int(loadsize * 0.9)

    if opt.model_name == 'lstm':
        result = []
        for i in range(0, batchsize):
            randomdata = random_transform_1d(data[i],
                                             finesize=_finesize,
                                             test_flag=test_flag)
            result.append(dsp.getfeature(randomdata))
        result = np.array(result).reshape(batchsize, _finesize * 5)

    elif opt.model_name in [
            'cnn_1d', 'resnet18_1d', 'resnet34_1d', 'multi_scale_resnet_1d',
            'micro_multi_scale_resnet_1d'
    ]:
        result = []
        for i in range(0, batchsize):
            randomdata = random_transform_1d(data[i],
                                             finesize=_finesize,
                                             test_flag=test_flag)
            result.append(randomdata)
        result = np.array(result)
        result = result.reshape(batchsize, opt.input_nc, _finesize)

    elif opt.model_name in [
            'squeezenet', 'multi_scale_resnet', 'dfcnn', 'resnet18',
            'densenet121', 'densenet201', 'resnet101', 'resnet50'
    ]:
        result = []
        data = (data - 0.5) * 2
        for i in range(0, batchsize):
            spectrum = dsp.signal2spectrum(data[i])
            spectrum = random_transform_2d(spectrum, (224, 122),
                                           test_flag=test_flag)
            result.append(spectrum)
        result = np.array(result)
        #datasets    th_95    avg       mid
        # sleep_edfx 0.0458   0.0128    0.0053
        # CC2018     0.0507   0.0161    0.00828
        result = Normalize(result, maxmin=0.5, avg=0.0150, sigma=0.0500)
        result = result.reshape(batchsize, 1, 224, 122)

    return result