赞
踩
目前在做帕金森震颤分类,数据类型是三轴加速度和陀螺仪。一次尝试想将这些信号转换为时频图输入至神经网络结构中。转换过程在每个batch中进行。比如,输入数据格式为【batch_size, window_size, channels, 输出格式为【batch_size, length, channels】。由于本人常用的时间窗口长度为200,因此使用specgram函数默认参数的情况下,每一轴的数据被转换为大小为【length, 1】大小的数组。该函数数据输入为tensor,输出也为tensor。想实现的效果如下图所示。
- def compute_tf(self, data):
- tf = []
- data = data.numpy() #Tensor转换为numpy
- for i in range(data.shape[0]):
- tf_batch = []
- for j in range(data.shape[1]):
- spectrum, freqs, ts, fig = plt.specgram(data[i, j, :], Fs=100)
- tf_batch.append(spectrum.reshape(-1))
- tf.append(tf_batch)
- return torch.from_numpy(np.array(tf)).float()
-
- #float()是因为pytorch中常用float32类型进行运算,
- #而torch.from_numpy()默认输出为float64格式。
结果:加入实验后,程序运行速度变得极慢。
参考资料:1.torch.from_numpy() 记录-CSDN博客
2. 论文Wrist sensor-based tremor severity quantification in Parkinson's disease
using convolutional neural network
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。