mirror of
https://github.com/This-weiyuqing/ECG_by_Diffenert_CNN_Test.git
synced 2026-10-18 03:13:39 +08:00
load two layer of cnn
This commit is contained in:
1 parent
815bd40d40
commit
5f757ad939
11 files changed
+158
-126
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import numpy as np
|
||||
import pywt
|
||||
import wfdb
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
# file error
|
||||
|
||||
# use db5 ,level9 do deviose
|
||||
ECGDATAPATH = './MIT-BIT/'
|
||||
|
||||
# from ECG_read_weiyuqing_without_wfdb import PATH
|
||||
# record = wfdb.rdrecord(ECGDATAPATH + number, channel_names=['MLII'])
|
||||
record = wfdb.rdrecord(ECGDATAPATH + '100', channel_names=['MLII'])
|
||||
data = record.p_signal.flatten()
|
||||
|
||||
coeffs = pywt.wavedec(data=data, wavelet='db5', level=9)
|
||||
cA9, cD9, cD8, cD7, cD6, cD5, cD4, cD3, cD2, cD1 = coeffs
|
||||
|
||||
threshold = (np.median(np.abs(cD1)) / 0.6745) * (np.sqrt(2 * np.log(len(cD1))))
|
||||
cD1.fill(0)
|
||||
cD2.fill(0)
|
||||
for i in range(1, len(coeffs) - 2):
|
||||
coeffs[i] = pywt.threshold(coeffs[i], threshold)
|
||||
|
||||
rdata = pywt.waverec(coeffs=coeffs, wavelet='db5')
|
||||
|
||||
plt.figure(figsize=(20, 4))
|
||||
plt.plot(data)
|
||||
plt.show()
|
||||
plt.plot(rdata)
|
||||
plt.show()
|
||||
@@ -0,0 +1,10 @@
|
||||
import torch
|
||||
torch.cuda.is_available()
|
||||
print(torch.cuda.is_available())
|
||||
print(torch.__version__)
|
||||
|
||||
|
||||
print(torch.cuda.is_available() )# cuda是否可用
|
||||
print(torch.cuda.device_count() )# gpu数量
|
||||
print(torch.cuda.current_device())# 当前设备索引, 从0开始
|
||||
print(torch.cuda.get_device_name(0))# 返回gpu名字
|
||||
@@ -0,0 +1,19 @@
|
||||
## read_img.py
|
||||
|
||||
import cv2
|
||||
import os
|
||||
import matplotlib.pyplot as plt
|
||||
from PIL import Image
|
||||
|
||||
source_path='E:/CToE/Pictures'
|
||||
|
||||
def show_pic():
|
||||
# img=cv2.imread(os.path.join(source_path,'t1.png'))
|
||||
img=Image.open(os.path.join(source_path,'1.png'))
|
||||
# plt.imshow(img)
|
||||
info = plt.imshow(img)
|
||||
print(info)
|
||||
plt.show()
|
||||
|
||||
if __name__ == '__main__':
|
||||
show_pic()
|
||||
@@ -0,0 +1,52 @@
|
||||
import tensorflow as tf
|
||||
|
||||
tf.test.is_gpu_available()
|
||||
|
||||
# Tensorflow 2.10是最后一个在本地windows上支持GPU的版本。从2.11版本开始,需要在windows WLS2(适用于 Linux 的 Windows 子系统)上安装才能使用GPU。所以要在native-windows上使用GPU,就只能安装2.10.0版本及以下的版本,或者安装老版的tensorflow-gpu.
|
||||
# 指定在cpu上运行
|
||||
with tf.device('/cpu:0'):
|
||||
cpu_a = tf.random.normal([10000, 1000])
|
||||
cpu_b = tf.random.normal([1000, 2000])
|
||||
cpu_c = tf.matmul(cpu_a, cpu_b)
|
||||
print("cpu_a:", cpu_a.device)
|
||||
print("cpu_b:", cpu_b.device)
|
||||
print("cpu_c:", cpu_c.device)
|
||||
# 查看gpu是否可用
|
||||
print(tf.config.list_physical_devices('GPU'))
|
||||
# 指定在gpu上运行
|
||||
with tf.device('/gpu:0'):
|
||||
gpu_a = tf.random.normal([10000, 1000])
|
||||
gpu_b = tf.random.normal([1000, 2000])
|
||||
gpu_c = tf.matmul(gpu_a, gpu_b)
|
||||
print("gpu_a:", gpu_a.device)
|
||||
print("gpu_b:", gpu_b.device)
|
||||
print("gpu_c:", gpu_c.device)
|
||||
|
||||
import tensorflow as tf
|
||||
import timeit
|
||||
|
||||
|
||||
def cpu_run():
|
||||
with tf.device('/cpu:0'):
|
||||
cpu_a = tf.random.normal([10000, 1000])
|
||||
cpu_b = tf.random.normal([1000, 2000])
|
||||
c = tf.matmul(cpu_a, cpu_b)
|
||||
return c
|
||||
|
||||
|
||||
def gpu_run():
|
||||
with tf.device('/gpu:0'):
|
||||
gpu_a = tf.random.normal([10000, 1000])
|
||||
gpu_b = tf.random.normal([1000, 2000])
|
||||
c = tf.matmul(gpu_a, gpu_b)
|
||||
return c
|
||||
|
||||
|
||||
cpu_time = timeit.timeit(cpu_run, number=10)
|
||||
gpu_time = timeit.timeit(gpu_run, number=10)
|
||||
print("cpu:", cpu_time, " gpu:", gpu_time)
|
||||
# 检测 tensorflow 能使用的设备情况
|
||||
from tensorflow.python.client import device_lib
|
||||
|
||||
# os.environ["CUDA_VISIBLE_DEVICES"] = "1" # 这个可以指定使用哪个设备
|
||||
print(device_lib.list_local_devices())
|
||||
@@ -0,0 +1,51 @@
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
import wfdb
|
||||
import matplotlib.pyplot
|
||||
|
||||
PATH = '../MIT-BIT/'
|
||||
|
||||
|
||||
# file error with read_ecg_data(data) parameter data false
|
||||
|
||||
def read_ecg_data(data):
|
||||
# get the data from the ecg data file and set begin and end points
|
||||
record = wfdb.rdrecord(PATH + 'data', sampfrom=0, sampto=1500)
|
||||
# return type record
|
||||
print(type(record))
|
||||
print(dir(record))
|
||||
# get the Lead signal (len、filename、number、signalname、Sample rate
|
||||
print(record.p_signal)
|
||||
print(np.shape(record.p_signal))
|
||||
|
||||
print(record.sig_len)
|
||||
|
||||
print(record.record_name)
|
||||
|
||||
print(record.n_sig)
|
||||
|
||||
print(record.sig_name)
|
||||
|
||||
print(record.fs)
|
||||
|
||||
# get type
|
||||
annotations = wfdb.rdann(PATH + data, 'atr')
|
||||
print(type(annotations))
|
||||
print(dir(annotations))
|
||||
|
||||
# get R
|
||||
print(annotations.sample)
|
||||
# get label of Heart beat
|
||||
print(annotations.sample)
|
||||
# num
|
||||
print(annotations.ann_len)
|
||||
# show label of beat
|
||||
print(wfdb.show_ann_labels())
|
||||
|
||||
matplotlib.pyplot.draw_ecg(record.p_signal)
|
||||
return record.p_signal
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
read_ecg_data(100)
|
||||
Reference in new issue
Block a user