Diff of /data_preproc.py [000000] .. [eaa663]

Switch to unified view

a b/data_preproc.py
1
# -*- coding: utf-8 -*-
2
"""
3
Created on Sun Apr 21 13:32:56 2019
4
5
@author: Winham
6
7
data_preproc.py:用于人工标记后的文件整理
8
注意:由于下列代码中包含了对文件的删除,因此在原始人工标记后的文件中
9
仅能运行一次。建议运行前先将原始文件备份!!!若遇到错误可重新恢复并
10
重新执行。运行前先在同目录下新建一个文件夹119_SEG
11
12
"""
13
14
import os
15
import numpy as np
16
import scipy.io as sio
17
18
path = 'G:/ECG_UNet/119_MASK/'               # 原始文件目录
19
seg_path = 'G:/ECG_UNet/119_SEG/'            # 存储信号.npy文件
20
21
files = os.listdir(path)
22
23
for i in range(len(files)):
24
    file_name = files[i]
25
    print(file_name + ' ' + str(i+1))
26
    if file_name.endswith('.json'):          # 只取已经人工标记好的信号段,即有.json文件配套
27
        name = file_name[:-5]
28
        mat_name = name + '.mat'
29
        sig = sio.loadmat(path+mat_name)['seg_t'].squeeze()
30
        np.save(seg_path+name+'.npy', sig)
31
    elif file_name.startswith('ann') or file_name.endswith('.png'):
32
        os.remove(path+file_name)
33
34
rest_files = os.listdir(path)
35
for i in range(len(rest_files)):
36
    if rest_files[i].endswith('.mat'):
37
        os.remove(path+rest_files[i])