audrey06100 commited on
Commit
c8b0280
·
1 Parent(s): 94ae045

update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +11 -16
utils.py CHANGED
@@ -1,12 +1,10 @@
1
  import numpy as np
2
  import csv
3
- #from model import cumbersome_model2
4
- #from model import UNet_family
5
- #from model import UNet_attention
6
  from model import tf_model
7
  from model import tf_data
8
- #from opts import get_opts
9
- #from tools import pick_models
10
 
11
  import time
12
  import torch
@@ -15,8 +13,6 @@ import random
15
  import shutil
16
  from scipy.signal import decimate, resample_poly, firwin, lfilter
17
 
18
- from pathlib import Path
19
-
20
 
21
  os.environ["CUDA_VISIBLE_DEVICES"]="0"
22
 
@@ -118,8 +114,8 @@ def dataDelete(path):
118
  except OSError as e:
119
  print(e)
120
  else:
121
- #pass
122
- print("The directory is deleted successfully")
123
 
124
 
125
  def decode_data(data, std_num, mode=5):
@@ -183,18 +179,17 @@ def decode_data(data, std_num, mode=5):
183
  decode = np.array(decode.cpu()).astype(np.float64)
184
  return decode
185
 
186
- def preprocessing(filename, samplerate):
187
  # establish temp folder
188
- tmp_filepath = str(Path(str(filename)).parent)
189
  try:
190
- os.mkdir(tmp_filepath+"/temp2/")
191
  except OSError as e:
192
- dataDelete(tmp_filepath+"/temp2/")
193
- os.mkdir(tmp_filepath+"/temp2/")
194
  print(e)
195
 
196
  # read data
197
- signal = read_train_data(filename)
198
  #print(signal.shape)
199
  # resample
200
  signal = resample(signal, samplerate)
@@ -203,7 +198,7 @@ def preprocessing(filename, samplerate):
203
  signal = FIR_filter(signal, 1, 50)
204
  #print(signal.shape)
205
  # cutting data
206
- total_file_num = cut_data(tmp_filepath, signal)
207
 
208
  return total_file_num
209
 
 
1
  import numpy as np
2
  import csv
3
+ from model import cumbersome_model2
4
+ from model import UNet_family
5
+ from model import UNet_attention
6
  from model import tf_model
7
  from model import tf_data
 
 
8
 
9
  import time
10
  import torch
 
13
  import shutil
14
  from scipy.signal import decimate, resample_poly, firwin, lfilter
15
 
 
 
16
 
17
  os.environ["CUDA_VISIBLE_DEVICES"]="0"
18
 
 
114
  except OSError as e:
115
  print(e)
116
  else:
117
+ pass
118
+ #print("The directory is deleted successfully")
119
 
120
 
121
  def decode_data(data, std_num, mode=5):
 
179
  decode = np.array(decode.cpu()).astype(np.float64)
180
  return decode
181
 
182
+ def preprocessing(filepath, filename, samplerate):
183
  # establish temp folder
 
184
  try:
185
+ os.mkdir(filepath+"/temp2/")
186
  except OSError as e:
187
+ dataDelete(filepath+"/temp2/")
188
+ os.mkdir(filepath+"/temp2/")
189
  print(e)
190
 
191
  # read data
192
+ signal = read_train_data(filepath+'/'+filename)
193
  #print(signal.shape)
194
  # resample
195
  signal = resample(signal, samplerate)
 
198
  signal = FIR_filter(signal, 1, 50)
199
  #print(signal.shape)
200
  # cutting data
201
+ total_file_num = cut_data(filepath, signal)
202
 
203
  return total_file_num
204